从cmd运行Jar相关的.Java

发布于 2024-12-05 04:31:47 字数 195 浏览 1 评论 0原文

我正在尝试从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红衣飘飘貌似仙 2024-12-12 04:31:47

您需要设置类路径

您可以通过两种方式做到这一点。使用 -classpath-cp 选项:

javac -cp jar1.jar;path/to/jar2.jar Classname.java

或者,如果需要保留它,请使用 CLASSPATH 环境变量:

set CLASSPATH=path1;path2
javac Classname.java

You need to set the classpath.

You can do this in 2 ways. Either use the -classpath or -cp option:

javac -cp jar1.jar;path/to/jar2.jar Classname.java

Or, if you need it to persist, use the CLASSPATH environmental variable:

set CLASSPATH=path1;path2
javac Classname.java
故事未完 2024-12-12 04:31:47

如果您已经设法在 Eclipse 中运行代码,那么 Eclipse 可以帮助您。

在“调试”视图中,运行代码后应该会保留如下内容:

Screenshot of Debug view

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:

Screenshot of Debug view

If you right-click the bottom "terminated" text and select "Properties", you will get something like this:

enter image description here

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.

青柠芒果 2024-12-12 04:31:47

您只需将目录路径和/或 .jar 库添加到“-classpath”命令行参数中。

根据您拥有的库数量,您可能会得到一个 .sh 脚本 (Linux) 或 .cmd 文件 (Windows),如下所示:

http://ubuntuforums.org/showthread.php?t=230258

java -cp jts.jar:jcommon-1.0.0.jar:jfreechart-1.0.0.jar:jhall.jar:other.jar:rss.jar -Xmx256M jclient.LoginFrame .

如果您使用的是 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

java -cp jts.jar:jcommon-1.0.0.jar:jfreechart-1.0.0.jar:jhall.jar:other.jar:rss.jar -Xmx256M jclient.LoginFrame .

If you're on Windows, you'd use ";" as a separator (instead of *nix ":").

'Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文