[英]Run maven web application from command line
I'm trying to run my maven web application through: 我正在尝试通过以下方式运行我的Maven Web应用程序:
java -jar CliniKeyMaven-1.0-SNAPSHOT.war
First, I faced the error no main manifest attribute in CliniKeyMaven-1.0-SNAPSHOT.war and after searching for a quite long time I reached this in my pom.xml: 首先,我在CliniKeyMaven-1.0-SNAPSHOT.war中遇到错误no main manifest属性,并且搜索了很长时间之后,我在pom.xml中达到了这一点:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<attachClasses>true</attachClasses>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.clinikeymaven.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
and this is the App.java that contains a main: 这是包含主要内容的App.java:
package com.mycompany.clinikeymaven;
public class App {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
But I'm now facing the error: 但是我现在面临错误:
Could not find or load main class com.mycompany.clinikeymaven.App
找不到或加载主类com.mycompany.clinikeymaven.App
When I run the application from the NetBeans it is working but I need to run it from the command line.. what should I do? 当我从NetBeans运行应用程序时,它正在运行,但是我需要从命令行运行它。我该怎么办?
this is a working pom .Pls try this one. 这是一个工作的pom。请尝试一下。
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.clinikeymaven.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
You need to user the Maven jar plugin and not the Maven war plugin 您需要使用Maven jar插件而不是Maven war插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mycompany.clinikeymaven.App</mainClass>
</manifest>
<compress>true</compress>
<index>true</index>
</archive>
</configuration>
</plugin>
Also as people said in the comments, with the maven-war-plugin you are creating a .war file that needs an application server to be deployed on in order to run. 就像人们在评论中所说的那样,使用maven-war-plugin您正在创建一个.war文件,该文件需要在其上部署应用服务器才能运行。
For example the generating .war could be deployed on in tomcat server. 例如,生成的.war可以部署在tomcat服务器中。
Try 尝试
java -cp CliniKeyMaven-1.0-SNAPSHOT.war com.mycompany.clinikeymaven.App
Alternately, you can update the content of your manifest file to following: 或者,您可以将清单文件的内容更新为以下内容:
Main-Class: com.mycompany.clinikeymaven.App
Then you can try running it the following way: 然后,您可以尝试通过以下方式运行它:
java -jar CliniKeyMaven-1.0-SNAPSHOT.war
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.