user1293588
user1293588

Reputation: 21

javac -classpath not doing the trick

I have a source file SerialTalk.java, in directory C:\javasrc\BattProj

This file imports classes from RXTXcomm.jar, eg.

import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; ...

RXTXcomm.jar is in the same directory as SerialTalk.java. I compile specifying a classpath pointing to the current directory:

javac -verbose -classpath . SerialTalk.java

Invariably, I get the following error. (Actually, many instances & variants of this error):

SerialTalk.java:3: error: package gnu.io does not exist import gnu.io.CommPortIdentifier;

When I open the RXTXcomm.jar (eg. with 7-Zip) I can see the gnu.io structure, and the specific .class files that I'm trying to import.

So what am I doing wrong? The same .java (source) file has been compiled and run on another workstation within the Netbeans IDE. The difference here is I'm trying to compile it using javac from the command line. (Environment is Win7, 32 bit, jdk1.7.0_03)

Upvotes: 2

Views: 5290

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500075

So what am I doing wrong?

You're not putting the jar file on the class path. Putting the directory on the class path doesn't do it. That only tells javac where to find .class files in the directory structure, not jar files containing class files. You want:

javac -verbose -classpath .;RXTXcomm.jar SerialTalk.java

Upvotes: 11

Related Questions