javac -classpath不能解决问题 [英] javac -classpath not doing the trick

查看:150
本文介绍了javac -classpath不能解决问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源文件SerialTalk.java,位于目录C:havejavasrc\BattProj

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

该文件从RXTXcomm.jar导入类。

This file imports classes from RXTXcomm.jar, eg.

导入gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
...

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

RXTXcomm.jar与SerialTalk.java位于同一目录中。我编译时指定了指向当前目录的类路径:

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

javac -verbose -classpath . SerialTalk.java

总是会出现以下错误。 (实际上,此错误的许多实例和变体):

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

SerialTalk.java:3:错误:包gnu.io不存在
导入gnu。 io.CommPortIdentifier;

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

当我打开RXTXcomm.jar(例如7-Zip)时,我可以看到gnu.io结构以及特定的.class文件我正在尝试导入。

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.

那我做错了什么?相同的.java(源)文件已被编译并在Netbeans IDE中的另一个工作站上运行。此处的区别在于,我试图通过命令行使用javac对其进行编译。 (环境是Win7,32位,jdk1.7.0_03)

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)

推荐答案


那我在做什么

So what am I doing wrong?

您没有将jar文件放在类路径中。将目录放在类路径上不会执行此操作。这只会告诉javac在目录结构中的哪里找到 .class 文件,而不是包含 类文件的jar文件。您想要:

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

这篇关于javac -classpath不能解决问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆