8

I'm working with Eclipse and Maven and run my application using the Maven jetty plugin.

I find it mildly irritating that Maven insists on recompiling my files every time I execute jetty:run. It is sub-optimal, as the files have already been compiled by Eclipse (and I'm writing Scala which has a (relatively) slow compiler).

I'm using profiles, and run mvn jetty:run under my 'development' profile.

What I want to do is:

Configure the jetty plugin so that it skips the compilation phase whilst running under the development profile.

I've looked into maven lifecycle documentation but haven't found any information about a 'skip.compile' flag or configuration parameter.

I've also tried configuring Maven like so in the vain assumption that it would stop the recompile upon maven-jetty-plugin startup.

I was wrong, it did not work. But what I have thought is, perhaps the Scala compiler is the problem. Perhaps it ignores the compile stuff.

development maven-compiler-plugin default-testCompile test-compile default-compile compile 1.6 1.6 false org.mortbay.jetty jetty-maven-plugin 7.2.2.v20101205 true development

Update:

I'm going to try specifically disabling scala compilation

Bryan Hunt
  • 3,265
  • 2
  • 22
  • 34
  • As far as i know you can configure jetty plugin to scan periodically and so you don't need to stop jetty...and make changes within Eclipse...Take a deeper look into the maven-jetty plugin.. – khmarbaise May 05 '11 at 11:41
  • khmarbaise, I've already disabled scanning as I'm compiling using jrebel. I've also taken a pretty deep look into the plugin or otherwise I wouldn't be here. What it needs is to disable the fork compile phase of jetty:run goal – Bryan Hunt May 05 '11 at 11:56

4 Answers4

9

Finally solved it.. @RobertMunteanu

Wow! Well I've finally figured out what I was doing wrong, the solution is to create a development and production profile, and, for the development profile configure the Scala plugin executions to do nothing.

Like so :

<profile>
  <id>development</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <executions>
          <execution>
            <id>compile</id>
            <goals></goals>
            <phase>compile</phase>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals></goals>
            <phase>test-compile</phase>
          </execution>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals></goals>
          </execution>
          <execution>
            <id>default-compile</id>
            <phase>compile</phase>
            <goals></goals>
          </execution>
          <execution>
            <phase>process-resources</phase>
            <goals>
            </goals>
          </execution>
        </executions>
      </plugin>
Bryan Hunt
  • 3,265
  • 2
  • 22
  • 34
2

The solution is to set an environmental variable of:

MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE"

The above worked for me.

Elsewhere on the Internet it is described as:

MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y"
Bryan Hunt
  • 3,265
  • 2
  • 22
  • 34
0

After some research, the problem is not with the jetty plugin, but with maven-compiler-plugin. There's a bug in the incrementalCompilation. See this stackoverflow question and answer: Maven compiler plugin always detecting a set of sources as "stale"

The following configuration works well for me; it allows for a very quick restart of jetty when code has changed with minimal recompilation, and it does not recompile if you have already compiled:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>UTF-8</encoding>
        <debug>${compile.debug}</debug>
        <useIncrementalCompilation>false</useIncrementalCompilation>
            </configuration>
</plugin>
  <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.26</version>       
              <configuration>
                <contextPath>/</contextPath>                     
                <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
                <scanIntervalSeconds>2</scanIntervalSeconds>
                <scanTargets>
                    <scanTarget>src/main/java</scanTarget>
                </scanTargets>                       
            </configuration>             
</plugin>
Community
  • 1
  • 1
James O'Brien
  • 1,686
  • 1
  • 13
  • 10
-1

If you say that the classes have already been compiled by Eclipse, there are two possible causes for recompiling:

  • you are invoking clean or deleting the compiled classes somehow;
  • the output folder for Eclipse is not the same as the output folder for Maven.

So you need to either prevent deletion of your compiled classes or configure Eclipse and Maven to use the same output folder.

Robert Munteanu
  • 63,405
  • 31
  • 191
  • 270
  • 1
    Nope, that's not the cause. The cause is that the jetty:run goal forks a compile every time it is started. I've solved this problem, will post the solution now. – Bryan Hunt May 05 '11 at 16:07