I'm working through the Head First EJB's book. I downloaded the J2EE 1.3.1 release from sun (http://java.sun.com/j2ee/sdk_1.3/), as instructed. I'm on Win XP. It created a folder on my root drive. I updated the PATH environment variable to find the J2EE sdk files. However when I go to compile my first EJB program, it can't find my javax.ejb.* imported classes.
My question: Where exactly are these classes located (ie, what folder in the J2EE installed sdk -- the bin? lib? I searched all and nothing with the name 'javax.ejb' came up). The complie error I get is something like "cannot find javax.ejb". Not sure if the download didn't give me everything or if this is a PATH issue... Thanks!
Typically the classes are found in the lib directory within JAR files. I don't know what IDE you are using, but from the command line you would need to specify the individual jars in the CLASSPATH system variable (not the PATH variable) and the compile the class with the -classpath flag.
Example, on Windows:
javac -classpath "%CLASSPATH%" MyClass.java
Please note that you would need to specify all of the jars you need in the CLASSPATH variable prior to compilation. Multiple jars can be specified in the variable my separating them with a semicolon (Windows platform).
CLASSPATH, not PATH. javac finds classes using the CLASSPATH environment variable or, preferably, the -classpath command-line switch. Your OS finds things using the PATH. Javac, and Java itself, use PATH for precisely nothing.
The *.jar files in your J2EE distribution are where the classes are. Each distro is a little different, but you'll likely find one called j2ee.jar or something similar.
I'm only using this dated version because that's what the Head First EJB's book instructed. Also because I want to take the certification exam for business component development and I believe that exam is based on J2EE 1.3.
I realize the Head First EJB book's a little old (2003 I believe?), but since it seemed to match the current certification exam, thought I better start there.
Joined: Sep 01, 2006
Just to close this out and bring it full circle, the compile worked when I set the CLASSPATH environment variable to: c:\j2sdkee1.3.1\lib\j2ee.jar. Also worked from the command line with: c:\javac -classpath c:\j2sdkee1.3.1\lib\j2ee.jar Advice.java