简体   繁体   English

从命令行OS X调用和打开jar文件

[英]Calling and opening jar file from command line OS X

I have an issue, which relates to starting a jar file. 我有一个问题,与启动jar文件有关。

I have my code in java, and i have to export it to get a jar file. 我的代码在Java中,我必须将其导出以获得jar文件。 I do that, and i get a jar file, however, now i want to call my jar file from the command line. 我这样做了,但是我得到了一个jar文件,但是,现在我想从命令行调用我的jar文件。 I set my main class in my jar file, so that i have an entry point. 我将主类设置在jar文件中,以便有一个入口点。 My java code depends on another jar file, and i am not sure, if it has anything to do with my problem. 我的Java代码依赖于另一个jar文件,我不确定是否与我的问题有关。

Then i call the file from command line, after i have positioned myself in the right folder. 然后,在将自己定位在正确的文件夹中之后,我从命令行调用该文件。 I use the command : java -jar Likvidator2.jar 我使用以下命令:java -jar Likvidator2.jar

And what i get is this : 我得到的是:

错误信息

I have tried checking my java version, and updating it, but at this point i really am not sure what to do and where to go anymore. 我已经尝试检查我的Java版本并对其进行更新,但是目前我真的不确定该怎么做以及去哪里。 Is it possible that i am building my project wrong, or something ? 我可能在构建我的项目时出错了吗?

您需要将类路径添加到命令中。

java -classpath <pathtodependency.jar;pathtootherdep.jar> your.MainClass

@Jan Doerrenhaus所述,您应该使用Maven Shade插件来创建可执行的JAR。

[SOLVED] [解决了]

I just had to build the jar file as runnable jar file, and everything worked fine. 我只需要将jar文件构建为可运行的jar文件,一切就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM