web applications - Tomcat - Maven plugin: run webapps but not current project -


the tomcat7-maven-plugin allows running current project web application , additional <webapps> can specified simultaneously loaded tomcat.

my project not web application, accesses services provided webapps. how possible deploy number of webapps without running project webapp? following maven snippet results in filenotfoundexceptions because context.xml cannot found.

<plugin>   <groupid>org.apache.tomcat.maven</groupid>   <artifactid>tomcat7-maven-plugin</artifactid>   <version>2.0</version>   <executions>     <execution>       <id>run-tomcat</id>       <phase>${tomcat.run.phase}</phase>       <goals><goal>run-war-only</goal></goals>       <configuration>         <webapps>           <webapp>             <contextpath>/my/app1</contextpath>             <groupid>...</groupid>              <artifactid>...</artifactid>             <version>...</version>             <type>war</type>                 <aswebapp>true</aswebapp>           </webapp>           ... possibly more webapps ...         </webapps>        </configuration>     </execution>     <execution>       <id>tomcat-shutdown</id>       <phase>${tomcat.shutdown.phase}</phase>       <goals><goal>shutdown</goal></goals>     </execution>   </executions> </plugin> 

workaround:

even though application not webapp, need configure path , contextfile it:

<configuration>     <path>/my/non/existing/webapp</path>     <contextfile>src/test/resources/context.xml</contextfile>     <webapps>     ... 

the specified context.xml file must exist. following worked me, though web.xml file not exist:

<?xml version="1.0" encoding="utf-8"?> <context path="/my/non/existing/webapp">     <watchedresource>web-inf/web.xml</watchedresource> </context> 

this abusing tomcat maven plugin here solution found. btw fake context file solution didn't work me because needed run different webapp , app webapp.

there jira out there provide better solution our problem. see https://issues.apache.org/jira/browse/mtomcat-228. on solution...

first, need copy war directory. suggest target directory can cleaned. depending on whether want support run or run-war goals depends on whether copy war or copy war , unpack it.

<plugin>   <groupid>org.apache.maven.plugins</groupid>   <artifactid>maven-dependency-plugin</artifactid>   <version>${maven-dependency-plugin.version}</version>   <executions>     <execution>       <id>copy-war</id>       <goals>         <goal>copy</goal>       </goals>       <configuration>         <artifactitems>           <artifactitem>             <groupid>org.foo</groupid>             <artifactid>bar</artifactid>             <version>${bar.version}</version>             <type>war</type>             <overwrite>true</overwrite>             <outputdirectory>${project.build.directory}/bar/</outputdirectory>           </artifactitem>         </artifactitems>         <stripversion>true</stripversion>       </configuration>     </execution>     <execution>       <id>copy-war-unpack</id>       <goals>         <goal>unpack</goal>       </goals>       <configuration>         <artifactitems>           <artifactitem>             <groupid>org.foo</groupid>             <artifactid>bar</artifactid>             <version>${bar.version}</version>             <type>war</type>             <overwrite>true</overwrite>             <outputdirectory>${project.build.directory}/bar/bar</outputdirectory>           </artifactitem>         </artifactitems>       </configuration>     </execution>   </executions> </plugin> 

next, need configure tomcat plugins @ directory or war copied in above step. following shows configuration tomcat 6 & 7 identical other artifact id.

<plugin>   <groupid>org.apache.tomcat.maven</groupid>   <artifactid>tomcat6-maven-plugin</artifactid>   <version>${tomcat6-maven-plugin.version}</version>   <configuration>     <port>8090</port>     <path>${default.rice.context.path}</path>     <wardirectory>${project.build.directory}/bar/bar.war</wardirectory>     <warsourcedirectory>${project.build.directory}/bar/bar</warsourcedirectory>   </configuration> </plugin> <plugin>   <groupid>org.apache.tomcat.maven</groupid>   <artifactid>tomcat7-maven-plugin</artifactid>   <version>${tomcat7-maven-plugin.version}</version>   <configuration>     <port>8090</port>     <path>${default.rice.context.path}</path>     <wardirectory>${project.build.directory}/bar/bar.war</wardirectory>     <warsourcedirectory>${project.build.directory}/bar/bar</warsourcedirectory>   </configuration> </plugin> 

to clear don't need configure wardirectory or need copy-war execution if want support tomcat:run. conversely, don't need configure warsourcedirectory or need copy-war-unpack execution if want support tomcat:run-war.

one final note, dependency copy workaround works jetty maven plugin if wanted support both tomcat & jetty might way it.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -