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 can download the source code from: http://horstmann.com/corejsf/. When I type the following on the command-line
javac UserBean.java
I get errors:
package javax.inject does not exist
package javax.enterprise.context doe not exist
I have downloaded Java EE, Ant and GlassFish.
Here is a snap of my command-line:
C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>javac UserBean.java
UserBean.java:4: error: package javax.inject does not exist
import javax.inject.Named;
^
UserBean.java:6: error: package javax.enterprise.context does not exist
import javax.enterprise.context.SessionScoped;
^
UserBean.java:9: error: cannot find symbol
@Named("user") // or @ManagedBean(name="user")
^
symbol: class Named
UserBean.java:10: error: cannot find symbol
@SessionScoped
^
symbol: class SessionScoped
4 errors
C:\JSF-Tutorial\corejsf3-examples\javaee\ch01\login\src\java\com\corejsf>
Been googling how to compile a Java EE application for the last week but without anything useful.
Would someone help me with this please, I need to solve this so I can move forward in my task to learn JSF.
S.P: I want to learn to compile Java EE applications bare hands before moving to compiling my Java EE projects with NetBeans. I prefer to learn to work with GlassFish first then maybe latter I'll consider Tomcat.
One more question; what's the difference between using Java EE and the GlassFish server to deploy my applications?
In NetBeans IDE 8.0 it's slightly different than described above for version 7.3
Libraries
in Java EE your projectImport...
Java EE 6 API Library
or Java EE 7 API Library
depending on the version you're using.Import Library
buttonAdd Library
button.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With