• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enviromential variable for servlet

 
Wong Martin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wong Martin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49363
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49363
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic