嵌入式tomcat应用程序与maven一起使用mvn tomcat7:run,但是从mvn包生成的jar没有

时间:2014-10-06 00:44:31

标签: java maven tomcat7 maven-plugin embedded-tomcat-7

我正在尝试关注this将我的webapp变成jar文件。如果我mvn tomcat7:run该应用效果很好。但是,如果我使用mvn package生成jar文件并执行jar,则每个页面都会出现404错误,说明请求的资源不可用。我一直试图在没有运气的情况下解决这个问题。这是我的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.mycompany</groupId>
<artifactId>HVF</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>HVF</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<profiles>
        <profile>
                <id>test</id>
                <activation>
                        <property>
                                <name>test</name>
                                <value>dev</value>
                        </property>
                </activation>
                <properties>
                </properties>
        </profile>
</profiles>

<dependencies>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.swinglabs</groupId>
        <artifactId>pdf-renderer</artifactId>
        <version>1.0.5</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.18</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>
            <type>maven-plugin</type>
            <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                        <execution>
                                <id>tomcat-run</id>
                                <goals>
                                        <goal>exec-war-only</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                        <path>/HVF</path>
                                        <attachArtifactClassifier>exec-war</attachArtifactClassifier>
                                        <attachArtifactClassifierType>jar</attachArtifactClassifierType>
                                        <enableNaming>false</enableNaming>
                                        <finalName>HVF.jar</finalName>
                                        <charset>utf-8</charset>
                                </configuration>
                        </execution>
                </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.0</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
                <dependencies>
                    <dependency>
                      <groupId>org.apache.tomcat.embed</groupId>
                      <artifactId>tomcat-embed-core</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-util</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-coyote</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-api</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-jdbc</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-dbcp</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-servlet-api</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-jsp-api</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-jasper</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-jasper-el</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-el-api</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-catalina</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-tribes</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-catalina-ha</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                    <dependency>
                      <groupId>org.apache.tomcat</groupId>
                      <artifactId>tomcat-annotations-api</artifactId>
                      <version>7.0.53</version>
                    </dependency>
                </dependencies>
        </plugin>
    </plugins>
</build>

非常感谢任何帮助。在这一点上,我不知道接下来要尝试什么。

0 个答案:

没有答案