简体   繁体   English

javac -classpath没有做到这一点

[英]javac -classpath not doing the trick

I have a source file SerialTalk.java, in directory C:\\javasrc\\BattProj 我有一个源文件SerialTalk.java,在目录C:\\ javasrc \\ BattProj中

This file imports classes from RXTXcomm.jar, eg. 该文件从RXTXcomm.jar导入类,例如。

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

RXTXcomm.jar is in the same directory as SerialTalk.java. RXTXcomm.jar与SerialTalk.java位于同一目录中。 I compile specifying a classpath pointing to the current directory: 我编译指定一个指向当前目录的类路径:

javac -verbose -classpath . javac -verbose -classpath。 SerialTalk.java 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; SerialTalk.java:3:错误:包gnu.io不存在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. 当我打开RXTXcomm.jar(例如,使用7-Zip)时,我可以看到gnu.io结构,以及我正在尝试导入的特定.class文件。

So what am I doing wrong? 那么我做错了什么? The same .java (source) file has been compiled and run on another workstation within the Netbeans IDE. 已编译相同的.java(源)文件并在Netbeans IDE中的另一个工作站上运行。 The difference here is I'm trying to compile it using javac from the command line. 这里的区别是我正在尝试使用命令行中的javac编译它。 (Environment is Win7, 32 bit, jdk1.7.0_03) (环境是Win7,32位,jdk1.7.0_03)

So what am I doing wrong? 那么我做错了什么?

You're not putting the jar file on the class path. 你没有把jar文件放在类路径上。 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. 这只告诉javac在目录结构中找到.class文件的位置,而不是包含类文件的jar文件。 You want: 你要:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM