Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using an external JAR library

807588Jul 7 2009 — edited Jul 8 2009
Hi, I'm trying to use the JFreeChart library, but I'm having some trouble with getting the classpath set up correctly.
I managed to set the classpath variable to "$HOME/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar", but the Java compiler doesn't appear to be reading the variable.
$ echo $CLASSPATH
$HOME/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar
$ echo $CLASSPATH
$HOME/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar
[chenyuz@raritan ~]$ javac VWAnalyzer.java
VWAnalyzer.java:8: package org.jfree.chart does not exist
import org.jfree.chart.*;
^
VWAnalyzer.java:9: package org.jfree.chart.axis does not exist
import org.jfree.chart.axis.*;
^
VWAnalyzer.java:10: package org.jfree.chart.plot does not exist
import org.jfree.chart.plot.*;
^
VWAnalyzer.java:11: package org.jfree.ui does not exist
import org.jfree.ui.*;
^
VWAnalyzer.java:13: cannot find symbol
symbol: class ApplicationFrame
public class VWAnalyzer extends ApplicationFrame {
                                ^
-snip-

17 errors
Now, when I try to compile it using the -cp option, it works (ish).
$ javac -classpath "$HOME/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar" VWAnalyzer.java
VWAnalyzer.java:11: package org.jfree.ui does not exist
import org.jfree.ui.*;
^
VWAnalyzer.java:13: cannot find symbol
symbol: class ApplicationFrame
public class VWAnalyzer extends ApplicationFrame {
                                ^
VWAnalyzer.java:48: cannot access org.jfree.ui.Drawable
file org/jfree/ui/Drawable.class not found
                ChartPanel panel = new ChartPanel( chart, true );
                                   ^
VWAnalyzer.java:51: cannot find symbol
symbol  : method setContentPane(org.jfree.chart.ChartPanel)
location: class VWAnalyzer
                setContentPane( panel );
                ^
VWAnalyzer.java:52: cannot find symbol
symbol  : method pack()
location: class VWAnalyzer
                pack();
                ^
VWAnalyzer.java:53: cannot find symbol
symbol  : method setVisible(boolean)
location: class VWAnalyzer
                setVisible( true );
                ^
6 errors
Now there's another dependency that I need to include, which is why the second compile (the one using -classpath) wasn't completely successful. However, when I try adding in that second JAR file to the classpath, the whole operation fails like the first compile:
$ javac -classpath "$HOME/jfreechart-1.0.13/lib/jcommon-1.0.16.jar;$HOME/jfreechart-1.0.13/lib/jfreechart-1.0.13.jar" VWAnalyzer.java
VWAnalyzer.java:8: package org.jfree.chart does not exist
import org.jfree.chart.*;
^
VWAnalyzer.java:9: package org.jfree.chart.axis does not exist
import org.jfree.chart.axis.*;
^
VWAnalyzer.java:10: package org.jfree.chart.plot does not exist
import org.jfree.chart.plot.*;
^
VWAnalyzer.java:11: package org.jfree.ui does not exist
import org.jfree.ui.*;
^
VWAnalyzer.java:13: cannot find symbol
symbol: class ApplicationFrame
public class VWAnalyzer extends ApplicationFrame {
                                ^

-snip-

VWAnalyzer.java:53: cannot find symbol
symbol  : method setVisible(boolean)
location: class VWAnalyzer
                setVisible( true );
                ^
17 errors
So essentially I have two questions:
1. Why is my computer not recognizing the global CLASSPATH variable?
2. Why can I not add two dependencies to the classpath when using the -classpath option?

I'm on a Linux computer and here's my Java version:
$ java -version
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Server VM (build 1.5.0_04-b05, mixed mode)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2009
Added on Jul 7 2009
8 comments
346 views