DEVFYI - Developer Resource - FYI

When do I need "struts.jar" on my classpath?

Struts Questions and Answers


(Continued from previous question...)

28. When do I need "struts.jar" on my classpath?

When you are compiling an application that uses the Struts classes, you must have the "struts.jar" on the classpath your compiler sees -- it does not have to be on your CLASSPATH environment variable.
Why is that an important distinction? Because if you are using a servlet container on your development machine to test your application, the "struts.jar" must not be on your CLASSPATH environment variable when running the container. (This is because each Web application must also have their own copy of the Struts classes, and the container will become confused if it is on the environment path as well.)
There are several general approaches to this issue:
* Use ANT for building your projects -- it can easily assemble classpaths for the compiler. (This is how Struts itself is built, along with Tomcat and most other Java-based projects).
* Use an IDE where you can configure the "class path" used for compilation independent of the CLASSPATH environment variable.
* Use a shell script that temporarily adds struts.jar to the classpath just for compilation, for example javac -classpath /path/to/struts.jar:$CLASSPATH $@

(Continued on next question...)

Other Interview Questions