从cmd运行Jar相关的.Java
我正在尝试从cmd提示符执行“javac Classname.java”,并且此Classname.java需要Jfreechart库/jar,并且如果从Eclipse编译则运行良好(因为项目包已导入jar)。
但我想从 cmd 提示符运行该文件,但它无法向我显示输出。它带有类似错误:(“包不存在”),如何修复它?我需要类文件并运行 JNI 命令来创建头文件。
I am trying to do "javac Classname.java" from cmd prompt, and this Classname.java requires Jfreechart libraries/jars, and runs fine if compiled from Eclipse (because project package has jars imported).
But I want to run the file from cmd prompt and its not able to show me the output. It comes with errors like: ("package doesn't exist"), how to fix it? I need the class file and also run JNI commands to create header file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要设置类路径。
您可以通过两种方式做到这一点。使用
-classpath
或-cp
选项:或者,如果需要保留它,请使用
CLASSPATH
环境变量:You need to set the classpath.
You can do this in 2 ways. Either use the
-classpath
or-cp
option:Or, if you need it to persist, use the
CLASSPATH
environmental variable:如果您已经设法在 Eclipse 中运行代码,那么 Eclipse 可以帮助您。
在“调试”视图中,运行代码后应该会保留如下内容:
If右键单击底部的“终止”文本并选择“属性”,您将得到如下内容:
您可以复制命令行内容并使用它从命令行运行您的应用程序,或者使用它来设置类路径,如其他答案所建议的那样。
If you have already managed to run your code in Eclipse, then Eclipse can help you.
In the "Debug" view, you should have something like this remaining after you have run your code:
If you right-click the bottom "terminated" text and select "Properties", you will get something like this:
You can copy the command line content and use that to run your app from the command line, or use it to set the classpath as the other answers have advised.
您只需将目录路径和/或 .jar 库添加到“-classpath”命令行参数中。
根据您拥有的库数量,您可能会得到一个 .sh 脚本 (Linux) 或 .cmd 文件 (Windows),如下所示:
http://ubuntuforums.org/showthread.php?t=230258
如果您使用的是 Windows,则可以使用“;”作为分隔符(而不是 *nix“:”)。
'希望有帮助!
You just need to add the directory paths and/or .jar libraries to your "-classpath" command-line argument.
Depending on how many libraries you've got, you might well wind up with a .sh script (Linux) or .cmd file (windows) that looks something like this:
http://ubuntuforums.org/showthread.php?t=230258
If you're on Windows, you'd use ";" as a separator (instead of *nix ":").
'Hope that helps!