7

I have problem using Maven Tomcat7 plugin to produce JAR archives with embedded Tomcat7 instance. Here is my pom.xml snippet:

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/${project.artifactId}</path>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>exec-war</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

My project uses war packaging. The JAR file containing Tomcat with WAR archive of the project is produced, however when I try to run it I get error:

java.io.FileNotFoundException: /home/rafal.wrzeszcz/workspace/Mailer/.extract/webapps/mailer.war
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:214)
    at java.util.zip.ZipFile.<init>(ZipFile.java:144)
    at java.util.jar.JarFile.<init>(JarFile.java:153)
    at java.util.jar.JarFile.<init>(JarFile.java:90)
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:88)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:89)
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:113)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:722)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:843)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:387)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

I tried plugin version 2.1 - same result.

This is the directory tree that is extracted by executing the JAR:

$ ls -AR .extract
.extract:
conf  logs  temp  webapps  work

.extract/conf:

.extract/logs:
access_log.2014-03-07

.extract/temp:

.extract/webapps:

.extract/work:
Tomcat

.extract/work/Tomcat:
localhost

.extract/work/Tomcat/localhost:
mailer

.extract/work/Tomcat/localhost/mailer:

(as you can see no files were copied)

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Rafał Wrzeszcz
  • 1,996
  • 4
  • 23
  • 45
  • have you tried exec-war-only with packaging=war? http://tomcat.apache.org/maven-plugin-2.0-beta-1/executable-war-jar.html – matt b Mar 06 '14 at 22:24
  • shouldn't the block come inside block? – sasankad Mar 06 '14 at 22:33
  • @mattb: My projects **does** use packaging `war`. And using `exec-war-only` gives similar result: `Exception in thread "main" java.lang.Exception: FATAL: impossible to create directories:.extract/webapps`. @sasankad: no it doesn't, configuration can either be per-execution or for plugin and it doesn't matter where you put it, it's just attached to the MOJO properties. But just to check that I did it and the result was just the same. – Rafał Wrzeszcz Mar 06 '14 at 22:45
  • are you running command line or within an ide? – Olivier Lamy Mar 07 '14 at 03:14
  • Command line, whats the difference? – Rafał Wrzeszcz Mar 07 '14 at 05:03

3 Answers3

7

This is indeed a bug in the tomcat7 maven plugin version 2.2: https://issues.apache.org/jira/browse/MTOMCAT-263

Use version 2.1 or wait for 2.3 to be released.

hennr
  • 2,632
  • 2
  • 23
  • 26
6

Remove the path from the configuration. And use 2.1 version of the tomcat plugin. Making those two changes in my pom file fixed a similar issue for me. Also I had cleaned the $M2_REPO/org/apache folder prior to rerunning.

Vikdor
  • 23,934
  • 10
  • 61
  • 84
Amar
  • 76
  • 2
-1

When I rm the old dir .extract/ created by last java -jar xx-war.jar , it OK. And I use version 2.0, I think other version also work.

Nisus Liu
  • 19
  • 2