Maven tomcat7 exec-war-only错误

时间:2014-06-09 17:17:06

标签: java maven tomcat

我想创建一个可执行的war / jar,如tomcat7-maven-plugin文档中所述: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:\***\GMM\target\gmm-0.1.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\***\GMM\src\main\webapp]
[INFO] Webapp assembled in [963 msecs]
[INFO] Building war: C:\***\GMM\target\gmm-0.1.1-SNAPSHOT.war
[INFO] WEB-INF\web.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启动本地嵌入式服务器:运行按预期工作。

与上面链接的文档不同,我只有一个.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 ,但没有任何效果。

我现在搜索并尝试了不同的事情,所以任何帮助都非常感谢! :]

5 个答案:

答案 0 :(得分:2)

我对插件的2.2版有类似的问题,但我根据this tutorial使用2.1运行。

答案 1 :(得分:2)

现在有一个版本2.3,其中2.2的问题已得到解决!

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

可悲的是,它只是一个快照版本,需要从Apache Snapshots Repository中获取。为了得到它你需要将它放入你的pom:

from erl_terms import decode
from os import getuid
from re import sub
from subprocess import check_output


check_command = ['/usr/sbin/rabbitmqctl', '-q', 'status']

if getuid() != 0:
    check_command.insert(0, '/usr/bin/sudo')

status = check_output(check_command)

## Join into a single line string then add a period at the end to make it a valid erlang term
status = ''.join(status.splitlines()) + '.'
# Remove any literal \n's since the erlang_version item has one in it
status = sub('(?:\\\\n)+', '',  status)

# Decode this into a python object
status = decode(status)

# And now let's find just mem_stat for mgmt_db
for item in status[0]:
    if 'memory' in item:
        for mem_stat in item[1]:
            if 'mgmt_db' in mem_stat:
                print mem_stat[1]

然后您可以使用新的version <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>

答案 2 :(得分:2)

NPE是因为插件找不到打包的war文件,我通过明确地将package阶段添加到构建中来修复该错误,例如:

mvn clean package tomcat7:exec-war

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

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

答案 3 :(得分:0)

我在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。有关更多信息... Create a deployable war file

答案 4 :(得分:0)

我已经在项目中修复了类似的问题,并在链接下方提供了参考

tomcat7-maven-plugin custom server.xml

找到此问题的pom.xml更改