views:

339

answers:

1

When attempting to execute mvn tomcat:run right after a clean, and with a configured tomcatWebXml specified in the pom, I get a FileNotFoundException.

Here's the snippet from my POM:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <version>1.0-beta-1</version>
    <configuration>     
     <path>/licensing</path>
     <tomcatWebXml>${basedir}/src/main/mock/web.xml</tomcatWebXml>
    </configuration>
</plugin>

And here's the error I experience, but only on the first invocation after a clean, subsequent invocations find the file and work fine.

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Could not create Tomcat configuration

Embedded error: C:\..snip..\src\main\mock\web.xml
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Could not create Tomcat
configuration
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:703)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:553)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:523)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:371)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:332)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:181)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:4
1)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not create Tomc
at configuration
        at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java
:153)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:483)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:678)
        ... 17 more
**Caused by: java.io.FileNotFoundException: C:\...snip..\src\main\mock\web.xml**
        at org.codehaus.mojo.tomcat.AbstractRunMojo.copyFile(AbstractRunMojo.jav
a:326)
        at org.codehaus.mojo.tomcat.AbstractRunMojo.initConfiguration(AbstractRu
nMojo.java:273)
        at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java
:143)
        ... 19 more

Any ideas on how I could resolve this? If it's an unconditional bug, it would seem to be the sort of thing that would affect anyone & everyone.

+1  A: 

I could reproduce this bug. Not sure why but in the following method of AbstractRunMojo.java:

private void copyFile( String fromPath, File toFile )
    throws IOException
{

    URL fromURL = getClass().getResource( fromPath );

    if ( fromURL == null )
    {
        throw new FileNotFoundException( fromPath );
    }

    FileUtils.copyURLToFile( fromURL, toFile );
}

The call to getClass().getResource( fromPath ) indeed returns a null URL right after a clean and works during subsequent invocations. I didn't really dig the issue but this seems to be a classloading issue (maybe related to MTOMCAT-25).

It's pretty annoying but the workaround is obviously to run the goal a second time after the first failure.

EDIT: I've reported this problem, see MTOMCAT-42, which has been fixed and a new snapshot of the Maven Tomcat Plugin has been published! To use it, add the following snippet to your pom.xml:

  <pluginRepositories>
    <pluginRepository>
      <id>Codehaus Snapshots</id>
      <url>http://snapshots.repository.codehaus.org/&lt;/url&gt;
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>  <!-- Workaround for MNG-2974, see note below -->
      </releases>
    </pluginRepository>
  </pluginRepositories>

Then change the version of the plugin to 1.0-SNAPSHOT and try again.

Pascal Thivent
Thanks for reproducing this, Pascal.
Justin Searls
Thanks Pascal, that's awesome!
Justin Searls
Actually, after following your directions, I'm still failing to pull down the snapshot. Opened this question: http://stackoverflow.com/questions/2013576/maven-is-failing-to-download-the-tomcat-maven-plugin-snapshot
Justin Searls
That's odd, I did a verification before to post the update and guarantee the issue was fixed (but maybe I built the plugin myself locally). I'll go check the new question.
Pascal Thivent