运行java jar - 没有主清单属性错误 [英] Run java jar - no main manifest attribute error
问题描述
我创建了简单的java程序(maven with pom),当我用CMD运行一些命令时,它应该在给定路径下创建一个文件...我做 mvn clean install
成功完成,
现在我想从命令行使用这个创建的jar,如下所示:
I’ve created simple java program (maven with pom ) which when I run some command with CMD it should created a file under given path... I do mvn clean install
which finish successfully,
Now I want to use this created jar from the command line like follwoing:
java -jar "/Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar" path2genfile2create
哪个应该运行我的程序(这是我第一次尝试这样的......)
Which should run my program (this the first time that I try something like this…)
但我得到的错误是:
no main manifest attribute, in /Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar
这里可能缺少什么?哪个清单属性?
What could be missing here ? which manifest attribute ?
错误不是来自我创建的课程 ......
我创建了一些META-INF / MANIFEST.MF没有帮助,但可能是错误的
i've created some META-INF/MANIFEST.MF not helping but maybe Its wrong
推荐答案
如果您正在使用Maven汇编插件,或者你的IDE工具是,你需要一个 mainClass
元素。这就是我使用的:
If you're using the Maven assembly plug-in, or your IDE tooling is, you need a mainClass
element. This is what I use:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.foo.MyMainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于运行java jar - 没有主清单属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!