aspose file tools*
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
Author

Enviromential variable for servlet

Wong Martin
Greenhorn

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

Please,
Martin
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

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


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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
Greenhorn

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!~

MartinSing.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Greenhorn

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:

unset CLASSPATH
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?

Martin
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enviromential variable for servlet