找不到Apache Tomcat Maven插件战争

时间:2017-06-29 21:33:53

标签: java maven tomcat

我按照文档here进行了操作,但最终得到的jar找不到要执行的war。这是错误:

java.io.FileNotFoundException: C:\Users\ortizj\Documents\NetBeansProjects\valida
tion-manager\Validation-Manager-Web\target\.extract\webapps\ROOT.war (The system
 cannot find the file specified)

由于某些原因,war文件未添加到jar,因此在提取时会失败。

ROOT.war存在且存在于目标文件夹中。

以下是相关的POM内容:

POM Project

 <profile>
        <id>installer</id>
        <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>
                                <warRunDependency>
                                    <dependency>
                                        <groupId>${project.groupId}</groupId>
                                        <artifactId>Validation-Manager-Web</artifactId>
                                        <version>${project.version}</version>
                                        <type>war</type>
                                    </dependency>
                                    <charset>utf-8</charset>
                                    <httpPort>9078</httpPort>
                                    <contextPath>/</contextPath>
                                </warRunDependency>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

3 个答案:

答案 0 :(得分:1)

你错过了战争的正派。因此不包括在内:

<warRunDependencies>
  <warRunDependency>
    <dependency>
      <groupId>a groupId</groupId>
      <artifactId>and artifactId</artifactId>
      <version>version</version>
      <type>war</type>
    </dependency>
    <contextPath>/</contextPath>
  </warRunDependency>
</warRunDependencies>

答案 1 :(得分:1)

如何将其添加到pom.xml文件中..

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>${maven-war-plugin.version}</version>
                        <configuration>
                            <warSourceDirectory>src/main/webapp</warSourceDirectory>
                            <warName>your-war-name</warName>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                            <outputDirectory>${deploy-path}</outputDirectory>
                        </configuration>
                    </plugin>

答案 2 :(得分:-1)

作为tomcat的替代方案,您可以使用jetty作为服务器。 因此POM应该添加流畅的插件。

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceDirectory>src/main/webapp</warSourceDirectory>
                <warName>myapp</warName>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.5.v20170502</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webApp>
                    <contextPath>/myapp</contextPath>
                </webApp>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

您可以按照以下方式运行它。

mvn clean install
mvn jetty:run

您的app将在给定上下文的默认端口8080上启动(在此&#34; myapp&#34;)。

相关问题