javac -classpath not doing the trick

流过昼夜 提交于 2019-12-11 02:47:05

问题


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)


回答1:


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


来源:https://stackoverflow.com/questions/9876924/javac-classpath-not-doing-the-trick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!