views:

407

answers:

2

I would like to have the maven eclipse plugin regenerate my .classpath whenever a build is run, and I did so by using the following configuration:

    <!--
        Generate a new .classpath each time the build is run, but don't try
        to download sources or javadocs
    -->
    <profile>
        <id>elipse-update</id>
        <activation>
            <file>
                <exists>.classpath</exists>
            </file>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>eclipse</goal>
                            </goals>
                            <configuration>
                                <downloadSources>false</downloadSources>
                                <downloadJavadocs>false</downloadJavadocs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

For some reason, this causes the maven jetty plugin to fail with ClassNotFoundException errors (it complains about all sorts of Spring classes not being there). Of course, it worked without a hit when I didn't have the maven eclipse plugin installed. Here's an example of what I'm talking about:

$ mvn jetty:run
[INFO] Scanning for projects...
...
[INFO] Starting jetty 6.1.22 ...
2010-02-11 20:53:08.984:INFO::jetty-6.1.22
2010-02-11 20:53:09.109:WARN::Could not instantiate listener org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
        at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
        at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

Of course, if I delete that eclipse plugin section, I can run jetty as expected:

$ mvn jetty:run
[INFO] Scanning for projects...
...
Feb 11, 2010 8:55:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1672 ms
2010-02-11 20:55:28.687:INFO::Started [email protected]:8080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 5 seconds.

Some things I know:

  • Yes, I only activate this profile if the .classpath is present. This seems counter-intuitive, but I have a reason: I have another profile that activates when the .classpath is absent which runs the eclipse plugin with the options for downloading source code and javadocs set to true. I don't want this to happen each build, so I created a separate plugin config for when the classpath is already there.
  • Yes, I could simply create properties that held the values of the options I wish to change instead of specifying the entire plugin config again. In that case, I would just set a eclipse.downloadSources property to true or false depending on the presence of the classpath and have a single plugin definition in the regular build section.

Any advice? This is a strange problem.

Thanks, LES

+1  A: 

You really don't want to run the maven-eclipse-plugin on every build when there's a .classpath present. I can't tell you exactly what it does to the classpaths, but this is not how it's intended to be used. The assumption is that when you run it you only run eclipse:eclipse (or some other goal).

Why do you want to keep re-running it?

bmargulies
(+1) Absolutely right.
Pascal Thivent
i just wanted to make it easy for other devs when i change the pom file; currently, i have to tell them to run mvn eclipse:eclipse when i change something; otherwise, they get all sorts of red errors in eclipse and they wont' bother figuring them out since the maven build works; this causes them to ignore all of the really good warnings - e.g., null pointer access, etc. if i can make eclipse always up to date i'm hoping that people will pay more attention to the elcipse warnings; automation helps this. :)
LES2
A Jira, as per @Pascal Thivent, might be your best bet. Or, see if you can rig profile activations to make sure it's off when the jetty plugin is on?
bmargulies
it also breaks cobertura instrumentation if i'm not mistaking ... so i'd have to keep excluding plugins as more problems are found ... i guess i could log a JIRA so at least the devs are aware of it (in case they aren't already)
LES2
+2  A: 

I suspect the Maven Eclipse Plugin to mess do some classpath woodo that affects the jetty plugin later.

But to be honest, this is not a very common way to use the Eclipse plugin, at least not to my knowledge. Most people don't include it in their build, they just run it when the POM has changed and this generally doesn't happen every build. Moreover, touching the .classpath confuses Eclipse if I remember well and forces a clean rebuild of the project which is pretty annoying.

So at the end, and I'm sorry for that, this seems to introduce more annoyances than benefits. You can try to open a Jira issue though.

Pascal Thivent
i have included a plugin config that will run eclipse:eclipse only if .classpath is missing. that way i can tell people to check out the source, run mvn install and their classpath will be there for them. i have disabled the always on config for now since it doesn't work. it is kind of a pain to have to remember to run eclipse:eclipse whenever i change the pom file - i would like for this to happen automatically with maven (i don't have the .classpath under version control since it's derrived from maven)
LES2
@LES2 I understand but, sadly, it doesn't work (and you'll remember to run it on pom changes, especially after a few mistakes of this kind). Another option would be to use the m2eclipse plugin, this would solve this problem (having to run anything before to import the project). I've been a user of the maven-eclipse-plugin for a long time but swapped some months ago and I'm happy with it so far.
Pascal Thivent
i've tried the eclipse plugin and wasn't impressed with it: slowed eclipse down and flaky. maybe i didn't have it configured properly. :/ i think i'll just log a JIRA just in case someone wants to fix it :(
LES2
@LES2 No doubts about this, m2eclipse can't be as lightweight as the maven-eclipse-plugin. And while I agree that it was not very reactive (which is why I wasn't using it as I don't need fancy pom editor or wizards), I find that things are better now. But I can't say it speeds up Eclipse indeed. I guess it's the price to pay to get better integration (I needed filtering support). I still frequently get StackOverflowError though, very annoying.
Pascal Thivent