others - Java - Maven tomcat7 exec-war-only 错误

我想创建一个可执行的war jar,如tomcat7 maven插件文档中所述: http://tomcat.apache.org/maven-plugin-2.2/executable-war-jar.html

但是我构建失败(NullPointerException ):


[INFO] Error stacktraces are turned on.


[INFO] Scanning for projects...


[INFO] 


[INFO] ------------------------------------------------------------------------


[INFO] Building Gothic Mod Manager 0.1.1-SNAPSHOT


[INFO] ------------------------------------------------------------------------


[INFO] 


[INFO] >>> tomcat7-maven-plugin:2.2:exec-war (default-cli) @ gmm >>>


[INFO] 


[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gmm ---


[INFO] Using 'ISO-8859-1' encoding to copy filtered resources.


[INFO] Copying 3 resources


[INFO] 


[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gmm ---


[INFO] Nothing to compile - all classes are up to date


[INFO] 


[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ gmm ---


[INFO] Not copying test resources


[INFO] 


[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ gmm ---


[INFO] Not compiling test sources


[INFO] 


[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ gmm ---


[INFO] Tests are skipped.


[INFO] 


[INFO] --- maven-war-plugin:2.2:war (default-war) @ gmm ---


[INFO] Packaging webapp


[INFO] Assembling webapp [gmm] in [C:***GMMtargetgmm-0.1.1-SNAPSHOT]


[INFO] Processing war project


[INFO] Copying webapp resources [C:***GMMsrcmainwebapp]


[INFO] Webapp assembled in [963 msecs]


[INFO] Building war: C:***GMMtargetgmm-0.1.1-SNAPSHOT.war


[INFO] WEB-INFweb.xml already added, skipping


[INFO] 


[INFO] --- tomcat7-maven-plugin:2.2:exec-war-only (executable) @ gmm ---


[INFO] 


[INFO] <<< tomcat7-maven-plugin:2.2:exec-war (default-cli) @ gmm <<<


[INFO] 


[INFO] --- tomcat7-maven-plugin:2.2:exec-war (default-cli) @ gmm ---


[INFO] ------------------------------------------------------------------------


[INFO] BUILD FAILURE


[INFO] ------------------------------------------------------------------------


[INFO] Total time: 4.854s


[INFO] Finished at: Mon Jun 09 18:55:09 CEST 2014


[INFO] Final Memory: 30M/223M


[INFO] ------------------------------------------------------------------------


[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:exec-war (default-cli) on project gmm: Execution default-cli of goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:exec-war failed. NullPointerException -> [Help 1]


org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:exec-war (default-cli) on project gmm: Execution default-cli of goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:exec-war failed.


 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)


 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)


 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)


 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)


 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)


 at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)


 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)


 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)


 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)


 at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)


 at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)


 at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)


 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)


 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


 at java.lang.reflect.Method.invoke(Method.java:606)


 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)


 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)


 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)


 at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)


 at org.codehaus.classworlds.Launcher.main(Launcher.java:46)


Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:exec-war failed.


 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)


 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)


 ... 20 more


Caused by: java.lang.NullPointerException


 at java.io.FileInputStream.<init>(FileInputStream.java:134)


 at org.apache.tomcat.maven.plugin.tomcat7.run.AbstractExecWarMojo.execute(AbstractExecWarMojo.java:301)


 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)


 ... 21 more


[ERROR] 


[ERROR] Re-run Maven using the -X switch to enable full debug logging.


[ERROR] 


[ERROR] For more information about the errors and possible solutions, please read the following articles:


[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException



目标tomcat7:deploy :重新部署:以预期的方式使用tomcat7:run工作的本地嵌入式服务器和启动本地嵌入式服务器。

上面链接的文档不同,我只有一个.pom文件,因此我将文档中的部分合并到一起,我的pom现在看起来像这样:


<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/maven-v4_0_0.xsd">


 <modelVersion>4.0.0</modelVersion>


 <groupId>de.gothic-reloaded-mod</groupId>


 <artifactId>gmm</artifactId>


 <packaging>war</packaging>


 <version>0.1.1-SNAPSHOT</version>


 <name>Gothic Mod Manager</name>


 <url>https://github.com/Katharsas/GMM</url>



 <properties>


 <org.springframework.version>4.0.4.RELEASE</org.springframework.version>


 <org.springframework.security.version>3.2.0.RELEASE</org.springframework.security.version>


 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>


 </properties>



 <dependencies>


 <dependency>


 <groupId>org.imgscalr</groupId>


 <artifactId>imgscalr-lib</artifactId>


 <version>4.2</version>


 <type>jar</type>


 <scope>compile</scope>


 </dependency>


 <dependency>


 <groupId>org.codehaus.jackson</groupId>


 <artifactId>jackson-mapper-asl</artifactId>


 <version>1.9.13</version>


 </dependency>


 <dependency>


 <groupId>junit</groupId>


 <artifactId>junit</artifactId>


 <version>4.11</version>


 <scope>test</scope>


 </dependency>


 <dependency>


 <groupId>org.apache.commons</groupId>


 <artifactId>commons-lang3</artifactId>


 <version>3.2.1</version>


 </dependency>


 <dependency>


 <groupId>javax.servlet</groupId>


 <artifactId>jstl</artifactId>


 <version>1.2</version>


 </dependency>


 <dependency>


 <groupId>com.thoughtworks.xstream</groupId>


 <artifactId>xstream</artifactId>


 <version>1.4.7</version>


 </dependency>


 <dependency>


 <groupId>javax.servlet</groupId>


 <artifactId>javax.servlet-api</artifactId>


 <version>3.1.0</version>


 <scope>provided</scope>


 </dependency>


 <dependency>


 <groupId>org.apache.tomcat</groupId>


 <artifactId>tomcat-juli</artifactId>


 <version>7.0.52</version>


 </dependency>


 <dependency>


 <groupId>org.springframework</groupId>


 <artifactId>spring-context</artifactId>


 <version>${org.springframework.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework</groupId>


 <artifactId>spring-webmvc</artifactId>


 <version>${org.springframework.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework</groupId>


 <artifactId>spring-test</artifactId>


 <version>${org.springframework.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework</groupId>


 <artifactId>spring-beans</artifactId>


 <version>${org.springframework.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework.security</groupId>


 <artifactId>spring-security-core</artifactId>


 <version>${org.springframework.security.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework.security</groupId>


 <artifactId>spring-security-config</artifactId>


 <version>${org.springframework.security.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework.security</groupId>


 <artifactId>spring-security-web</artifactId>


 <version>${org.springframework.security.version}</version>


 </dependency>


 <dependency>


 <groupId>org.springframework.security</groupId>


 <artifactId>spring-security-taglibs</artifactId>


 <version>${org.springframework.security.version}</version>


 </dependency>


 <!-- Apache Commons Upload --> 


 <dependency>


 <groupId>commons-io</groupId>


 <artifactId>commons-io</artifactId>


 <version>2.4</version>


 </dependency>


 <!-- Apache Commons Upload --> 


 <dependency>


 <groupId>commons-fileupload</groupId>


 <artifactId>commons-fileupload</artifactId>


 <version>1.3</version>


 </dependency>


 </dependencies>



 <build>


 <pluginManagement>


 <plugins>


 <plugin>


 <groupId>org.apache.tomcat.maven</groupId>


 <artifactId>tomcat7-maven-plugin</artifactId>


 <version>2.2</version>


 </plugin>


 <plugin>


 <groupId>org.apache.maven.plugins</groupId>


 <artifactId>maven-compiler-plugin</artifactId>


 <version>3.1</version>


 </plugin>


 <plugin>


 <groupId>org.apache.maven.plugins</groupId>


 <artifactId>maven-resources-plugin</artifactId>


 <version>2.6</version>


 </plugin>


 </plugins>


 </pluginManagement>



 <resources>


 <resource>


 <directory>src/main/resources</directory>


 <filtering>true</filtering>


 </resource>


 </resources>



 <plugins>


 <plugin>


 <groupId>org.apache.tomcat.maven</groupId>


 <artifactId>tomcat7-maven-plugin</artifactId>


 <configuration>


 <path>/GMM</path>


 <encoding>UTF-8</encoding>


 <username>admin</username>


 <password>**********</password>


 </configuration>



 <executions>


 <execution>


 <id>executable</id>


 <goals>


 <goal>exec-war-only</goal>


 <goal>exec-war</goal>


 </goals>


 <phase>package</phase>


 <configuration>



 <enableNaming>true</enableNaming>



 <warRunDependencies>


 <warRunDependency>


 <dependency>


 <groupId>de.gothic-reloaded-mod</groupId>


 <artifactId>gmm</artifactId>


 <version>0.1.1-SNAPSHOT</version>


 <type>war</type>


 </dependency>


 <contextPath>/</contextPath>


 </warRunDependency>


 </warRunDependencies>



 <extraDependencies>


 <extraDependency>


 <groupId>org.apache.derby</groupId>


 <artifactId>derby</artifactId>


 <version>10.1.3.1</version>


 </extraDependency>


 <extraDependency>


 <groupId>javax.mail</groupId>


 <artifactId>mail</artifactId>


 <version>1.4</version>


 </extraDependency>


 </extraDependencies>



 </configuration>


 </execution>


 </executions>


 </plugin>



 <plugin>


 <groupId>org.apache.maven.plugins</groupId>


 <artifactId>maven-compiler-plugin</artifactId>


 <configuration>


 <source>1.7</source>


 <target>1.7</target>


 <encoding>UTF-8</encoding>


 </configuration>


 </plugin>



 <plugin>


 <groupId>org.apache.maven.plugins</groupId>


 <artifactId>maven-resources-plugin</artifactId>


 <configuration>


 <encoding>ISO-8859-1</encoding>


 </configuration>


 </plugin>


 </plugins>


 </build>


</project>



附加信息:我使用Eclipse Kepler,我的运行配置如下所示:
tomcat7:exec-war -e
我也试过命令行,试过:exec-war-only,但是,没有任何效果。

:]

时间:

我在2.2版的插件中也有类似的问题,但是根据这个教程解决了,此Tutorial 。

现在2.3来了,其中2.2的问题已得到解决!

(2.1有一些问题,因为它太旧了)

遗憾的是,它只是一个快照版本,需要从Apache Snapshots存储库中获取,要获得它,你需要将它放入你的pom中:


<pluginRepositories>


 <pluginRepository>


 <id>apache.snapshots</id>


 <name>Apache Snapshots</name>


 <url>http://repository.apache.org/snapshots</url>


 <releases>


 <enabled>false</enabled>


 </releases>


 <snapshots>


 <enabled>true</enabled>


 </snapshots>


 </pluginRepository>


</pluginRepositories>



然后你可以使用版本<version>2.3-SNAPSHOT</version>

由于该插件没有找到打包的war文件,我修复了将package阶段显式添加到构建中的错误例如:


mvn clean package tomcat7:exec-war



产生war包的任何阶段都适合避免NPE:软件包,安装,部署等。

因此在你的情况下在Eclipse中使用运行配置只需在tomcat7:exec-war -e之前添加package

我在Spring Boot应用程序中收到这个错误。 我花费了相当长的时间才解决,把它放在这里需要包含下面的插件就可以了,


 <plugin>


 <groupId>org.springframework.boot</groupId>


 <artifactId>spring-boot-maven-plugin</artifactId>


 </plugin>



包装类型应该是jar


<packaging>jar</packaging>



开始类应该定义为你的主要类


<start-class>com.edu.schoolT.SchoolWeb</start-class>



用@SpringBootApplication注释的主类或类应该扩展SpringBootServletInitializer ,更多信息,创建可部署的war文件

...