Monday, July 10, 2017

Apache Tomcat Maven plugin war not found

Leave a Comment

I'm following the documentation here but I end up with a jar that doesn't find the war to execute. Here's the error:

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) 

For some reason the war file is not added to the jar so it fails when it's extracting it.

ROOT.war exists and is present in the target folder.

Here's the relevant POM contents:

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 Answers

Answers 1

You are missing the decency on your war. Therefore it is not included:

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

Answers 2

How about adding this to your pom.xml file..

                    <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> 

Answers 3

As a alternative for tomcat, You can use jetty as server. Therefore POM should be added flowing plugins.

<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> 

You can run it as following.

mvn clean install mvn jetty:run 

You app will be start on default port 8080 under given context (In this "myapp").

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment