“package javax.inject does not exist” error while compiling with javac in commandline

前端 未结 3 1881
攒了一身酷
攒了一身酷 2021-02-13 19:02

I\'m making my first steps toward learning JSF. I found this interesting book called \"Core JavaServer Faces Third Edition\".

Trying to compile the first example, you ca

3条回答
  •  梦谈多话
    2021-02-13 19:32

    You need to include the JAR file containing those classes in the compile time classpath.

    In your particular case with the GlassFish server, that's the /glassfish/lib/javaee.jar. You can specify the classpath as -cp (or -classpath) argument of javac command. It is a semicolonseparated string of disk file system paths pointing to JAR files and/or class folders which should be included in the compile time classpath.

    javac -cp /path/to/glassfish/lib/javaee.jar UserBean.java
    

    javac will then look in there once it encounters an unknown class which is referenced by import, so that it can among others verify if you used it the right way.

    This has technically nothing to do with Java EE. This is just basic Java. I'd suggest to learn that first before diving into Java EE.

    In case you're using an IDE, then it's just a matter of attaching the target server as "Targeted Runtime" to the project. The IDE will then automatically do all magic as to the build path (the compile time classpath).

提交回复
热议问题