问题描述
我不能让javac识别外部.jar文件,我想要扩展的类。我有两个文件在同一个目录:TestConsole.java和acm.jar。我使用以下命令从同一目录进行编译:
I can't make javac recognize an external .jar file, whose classes I'm trying to extend. I have two files in the same directory: TestConsole.java and acm.jar. I'm compiling from the same directory using the following command:
javac -classpath。:acm.jar TestConsole.java
但看起来javac只是忽略acm.jar。它给我错误:
But it seems like javac is just ignoring acm.jar. It gives me the error:
TestConsole.java:1: package acm does not exist
import acm.program;
^
当然,acm.program是acm.jar中的一个包。 acm.jar中的所有类都已编译;我只是想在我的课程中使用它们,而不是编译它们。
Of course, acm.program is a package in acm.jar. All of the classes in acm.jar are already compiled; I just want to use them in my classes, not compile them.
我做错了什么?
我在Mac上运行这个,并且acm.jar的目录结构似乎是有效的:它包含一个 acm / program
目录,它有 ConsoleProgram.class
是 TestConsole
扩展的唯一类。
I am running this on a Mac, and the directory structure of acm.jar appears to be valid: It contains an acm/program
directory, which has ConsoleProgram.class
, the only class that TestConsole
extends.
javac -classpath:acm.jarTestConsole.java
不起作用。
推荐答案
检查清单:
-
您在acm.jar中的课程显示为:
acm / program /CLASSX.class
acm / program / CLASSY.class
your classes in acm.jar appear as:
acm/program/CLASSX.class
acm/program/CLASSY.class
当使用jar tf acm.jar进行倾销时
when decanted with jar tf acm.jar
您正在导入它们:
import acm.program .CLASSX;
或
import acm.program。*;
import acm.program.CLASSX ;
or
import acm.program.* ;
这篇关于如何用.jar库编译Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!