jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Enviromential variable for servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enviromential variable for servlet" Watch "Enviromential variable for servlet" New topic

Enviromential variable for servlet

Wong Martin

Joined: Jan 14, 2011
Posts: 25
Hi buddies,

I'm new to Servlet and Linux, using Tomcat on Fedora15. I need help...

How can I include servlet-api.jar to java classpath, in order to be more comfortable with compiling .java file? I've tried some like:

1. edit etc/profile
2. edit etc/java/java.conf
3. drag and drop the servlet-api.jar file into jdk_/jre/lib

Unfortunately, none of these methods have solved my problem... What is the right way? It's really cumbersome for typing javac -classpath path/some/what/abc.jar everytime...

Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3817

Add a CLASSPATH entry and export it in your ~/.bash_profile file.

Note: You need to re-login once you've done this.

Generally you won't use this as various other techniques are used for this, like using build scripts, IDE configs etc...

[How to ask questions] [Twitter]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964

Manual single-file compiles for J2EE get old real fast. Shell scripts are awkward. So the popular solution is to use a java-aware build system like Ant or Maven. These systems can not only manage the references for the JEE libraries, they also can assemble the J2EE WAR for you.

Customer surveys are for companies who didn't pay proper attention to begin with.
Wong Martin

Joined: Jan 14, 2011
Posts: 25
Hi Kumara, Holloway,

Sorry for my late reply.

Thank you for the solutions

I'd included the servlet-api.jar into my CLASSPATH environment indeed. I found it most convenient.

My way is typing this command on my shell: export CLASSPATH=$CLASSPATH:/path/to/my/servlet-api.jar

I didn't actually realize why, but somehow I could solve the problem by typing in command-line instead of editing etc/profile... anyway, thanks for the helps!~

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38107
Setting the classpath from the terminal is much better than adding it to .bashrc. Otherwise the classpath in .bashrc gradually gets larger and larger, with more and more locations for different applications. What happens if you have two classes with the same name in different classpaths? How do you tell which one will be used?
Wong Martin

Joined: Jan 14, 2011
Posts: 25
Hi Campbell,

Thanks for your reply!

I just met the problem as you've mentioned, my CLASSPATH is getting longer and longer by setting too many variables , and sometime even duplicated because of neglect. In my case, they just
work fine. Do you know the way of removing those paths I've duplicated in the CLASSPATH??

My solution to this issue (not that smart anyway ) is simply put these two lines into ~/.bashrc file:

export CLASSPATH=$CLASSPATH:a/new/path/for/it

The Shell can get rid of the old one, and always only point to the second line I set. Is there any straightforward way?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38107
You will lose access to "." in your CLASSPATH if you do that. Also you would have to edit .bashrc for each new application.

I still prefer setting a new CLASSPATH from the terminal. You can write export CLASSPATH=... as a shell instruction.
wood burning stoves
subject: Enviromential variable for servlet
Similar Threads
Compile From Console
compiling servlets and jsp and running in tomcat
problem with programming using MVC techniques
problem in HFSJ chapter 3 Beer example
Help me writing an ACTION class in eclipse