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

青春壹個敷衍的年華 提交于 2019-12-03 11:33:34

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).

In netbeans 7.3 you can right click on libraries folder in project viewer, choose option 'add library' and then select 'Java EE 6 API Library' from list.

In NetBeans IDE 8.0 it's slightly different than described above for version 7.3

  1. Right click on Libraries in Java EE your project
  2. Select Import...
  3. Choose either Java EE 6 API Library or Java EE 7 API Library depending on the version you're using.
  4. Click the Import Library button
  5. Select the library you just imported and press the Add Library button.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!