如何从终端运行Java程序?
我正在尝试从我的终端运行 Java 程序。我有 Mac OS X 10.7。
teamL javac -jar kxml2-2.3.0.jar XMLHandler.java ServiceEndpoint.java TeamL.java
这是我的 Eclipse 类文件结构:
我无法找到为什么会抛出 Unable to access jarfile kxml2-2.3.0.jar
?
I am trying to run a Java program from my Terminal. I have Mac OS X 10.7.
teamL javac -jar kxml2-2.3.0.jar XMLHandler.java ServiceEndpoint.java TeamL.java
This is my Eclipse class file structure:
I am not able to find why is this throwing Unable to access jarfile kxml2-2.3.0.jar
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您引用任何外部库,则必须将它们添加到
类路径
中。您可以通过这种方式在类编译期间添加它。转到 src 目录并:
执行:
如果您使用的是 eclipse,则转到
/bin/
在这里您可以找到已编译的类(因此您不必编译它们)并使用上面的java
命令直接运行它们注意:由于您的类打包在
teamL
包下,因此您必须通过指定完全限定名称来从包外部运行这些类,例如teamL.ServiceEndpoint
If you are referencing any external libraries, then you have to add them to the
classpath
. You can add it during compilation of the classes this way.Go to the src directory and :
TO execute :
if your are using eclipse, then go to
<project_directory>/bin/
here you can find the compiled classes (so you dont have to compile them) and directly run them using the abovejava
commandNote: Since your classes are packaged under
teamL
package, you have to run the classes from outside the package by specifying the fully qualified name liketeamL.ServiceEndpoint
当您在命令行上执行程序时,是否已将该 jar 添加到类路径中?例如
java -classpath location_of_jar ...
Have you added that jar to the classpath when you execute the program on the command line? e.g.
java -classpath location_of_jar ...
javac
是一个编译命令,而不是您应该使用命令 Java。从命令提示符运行 Java 程序 这可以给你一个更好的想法,但对于 Windows 来说是相似的。
javac
is a command to compile instead of that you should use the command Java.Running a Java Program from Command Prompt this could give you a better idea is for Windows but is similar.