Results 1 to 6 of 6
- 06-01-2011, 11:38 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
In Linux export PATH doesn't work but the giving classpath to javac works. Why?
In Linux,
Why doesn't export PATH=path_to_lib doesn't work and -classpath works?
lib has all the jar files.
I exported the path to the lib folder.
export PATH=$PATH:/opt/lib
I also did export CLASSPATH=$CLASSPATH:$PATH
Then did a javac,
javac clazz.java
It is giving compilation problems.
Whereas, when we did javac --classpath /opt/lib/something.jar clazz works fine. Why is that?
- 06-02-2011, 12:47 AM #2
What do the linux experts think about this problem?
- 06-02-2011, 01:08 AM #3
Setting your CLASSPATH to the directory containing your jars isn't enough. java/javac won't automatically look inside all the jars in that directory.
Before I started using Eclipse, I had something like this in my .bashrc (or .bash_profile, I can't remember):
Java Code:CLASSPATH="." for fname in /home/kevin/lib/java/*.jar; do "CLASSPATH=$CLASSPATH:$fname"; done export CLASSPATH
Last edited by kjkrum; 06-02-2011 at 01:13 AM. Reason: added double quotes
Get in the habit of using standard Java naming conventions!
- 06-02-2011, 01:18 AM #4
Also, out of curiosity, I found this: unix - Setting multiple jars in java classpath - Stack Overflow
Apparently Sun added wildcards to classpaths in Java 1.6. (Who knew?)Get in the habit of using standard Java naming conventions!
- 06-02-2011, 06:28 AM #5
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
javac -classpath /home/lib/*.jar clazz.java seems to be working. But, I can't believe that PATH doesn't work.
What is PATH then? I remember adding PATH to Windows environmental variables before running javac which worked before.
- 06-02-2011, 06:59 AM #6
PATH is a list of locations your shell searches for a command or program. It's unrelated to Java's classpath.
Edit: Like if javac is located at /usr/bin/javac, and /usr/bin is in your PATH, then you can just type "javac" and the shell will find it. Classpaths are conceptually similar, but otherwise unrelated. They tell the JVM where to look for classes in the same way PATH tells the shell where to look for programs.Last edited by kjkrum; 06-02-2011 at 07:05 AM. Reason: clarification
Get in the habit of using standard Java naming conventions!
Similar Threads
-
How JVM works in linux box ?
By vinothjava in forum Advanced JavaReplies: 14Last Post: 05-06-2011, 12:02 PM -
JMF works fine with javac BUT same code has problems with NetBeans 6.9.1
By WACman in forum NetBeansReplies: 1Last Post: 11-03-2010, 08:49 AM -
classpath in linux...
By miko5054 in forum EclipseReplies: 3Last Post: 09-23-2010, 08:50 AM -
Source works in NetBeans but not with java/javac (commandline)
By Jacsoft3 in forum NetBeansReplies: 0Last Post: 10-05-2009, 11:25 PM -
Error : Invalid path, \bin\javac.exe -classpath
By Ed in forum JCreatorReplies: 3Last Post: 08-14-2009, 12:57 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks