[英]Run a jar file from unix command line
I have created a jar file from mvn command but when i am trying to run it i am getting below error:我从 mvn 命令创建了一个 jar 文件,但是当我尝试运行它时,出现以下错误:
java -cp target/new-repl.jar package.repl
Error: Could not find or load main class package.repl
Caused by: java.lang.ClassNotFoundException: package.repl
I got many links on stack overflow but none of them helped me.我有很多关于堆栈溢出的链接,但没有一个对我有帮助。 Could you please help me to run this from command line.你能帮我从命令行运行它吗? Below is the my.java file:下面是 my.java 文件:
package repl;
public class Test {
public static void main(String[] args) throws IOException {
....
}
}
POM.xml: POM.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>repl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>repl</name>
<description>build tar for repl</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<finalName>new-repl</finalName>
<directory>target</directory>
</build>
</project>
You can do like this.你可以这样做。 Type fully qualified class name instead of typing package name键入完全限定的 class 名称,而不是键入 package 名称
java -cp target/new-repl.jar repl.Test
The error says it all错误说明了一切
Error: Could not find or load main class package.repl
your class name is not package.repl, it is repl.Test
您的 class 名称不是 package.repl,它是repl.Test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.