简体   繁体   English

Jar可以双击但不能在命令行中使用

[英]Jar works on double-click, but not in command line

Following up on one of my questions in another post 另一篇文章中跟进我的一个问题

I added the maven-assembly-plugin to my POM , and now the jar works, but only if I double-click on the jar in the file system. 我将maven-assembly-plugin到了我的POM ,现在该jar可以工作了,但是仅当我双击文件系统中的jar时才可以。 If I try to run the jar from the command line, I still receive this error: 如果我尝试从命令行运行jar,我仍然会收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError:

This concerns me, because it seems like this jar is not platform-independent. 这让我感到担心,因为此jar似乎与平台无关。 Any ideas how to fix this? 任何想法如何解决这一问题?

Thanks! 谢谢!

How do you launch it? 您如何启动它?

You need to use the -jar switch: 您需要使用-jar开关:

java -jar your_jarfile.jar

syntax to launch application from jar on cmd line 从cmd行上的jar启动应用程序的语法

  java -jar jarname

Given that you have Manifest.txt file with jar having Main-Class:*package.class_name_containing_main_method* 假设您有Manifest.txt文件,其中jar具有Main-Class:* package.class_name_ contains_main_method *

That should not happen as launching it through command line is the exact same as launching by double click. 这不应该发生,因为通过命令行启动与通过双击启动完全相同。 Maybe you are trying to get it to use a different version of java through command line and that is what isn't working? 也许您正在尝试通过命令行使其使用不同版本的Java,这是行不通的吗? to clarify, the command to launch a jar is java -jar name.jar 澄清一下,启动jar的命令是java -jar name.jar

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

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