Maven2 eclipse plugin and custom or pom packages.

Update: This approach will also work with “ear” projects and only requires adding plugin definition without changes to eclipse maven plugin.

Recently I had to create maven project which was producing war file and then packaging it into tar before deploying to maven repository without deploying the war itself. This forced me to declare my pom package as “pom”. Everything was fine until I tried to run “mvn eclipse:eclipse” which gave me error that it does not support “pom” packages.
After googling I stumble upon this ticket

http://jira.codehaus.org/browse/MECLIPSE-310

which suggested to specify “war” (or “jar”) packaging in eclipse plugin configuration like so

<build>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <packaging>war</packaging>
                </configuration>
            </plugin>

    ….

This got me passed the “pom” package error and created the .project file but I still could not get .classpath file.

After some more googling I found this blog:

http://lazydev.ildella.net/maven-eclipse-plugin-and-the-pom-packaging-pr

which unfortunately did not provide the modification details.

But this post

http://stackoverflow.com/questions/2454700/maven-generate-eclipse-project-for-custom-packaging

gave me necessary clue that eclipse plugin was not generating .classpath because of my pom not being a Java project (war and jar are java projects for eclipse).

Unfortunately I could not find a way to override the project type in pom.xml and had to fix it in eclipse plugin code.

Just checkout latest eclipse plugin releases, for me it was 2.8:

svn checkout http://svn.apache.org/repos/asf/maven/plugins/tags/maven-eclipse-plugin-2.8

and modify org.apache.maven.plugin.eclipse.EclipsePlugin class by replacing the last line:

public final boolean setup()
        throws MojoExecutionException
    {
       
        boolean ready = true;

        checkDeprecations();
        setProjectNameTemplate( IdeUtils.calculateProjectNameTemplate( getProjectNameTemplate(),
                                                                       isAddVersionToProjectName(),
                                                                       isAddGroupIdToProjectName(), getLog() ) );
        ajdt = enableAjdt( executedProject ) && !ajdtVersion.equals( "none" );
        ready = validate();

        // TODO: Why are we using project in some places, and executedProject in others??
        ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();

        // ear projects don’t contain java sources
        // pde projects are always java projects
        isJavaProject =
                    pde
                        || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) );

with

isJavaProject=true;

Finally, to use your modified plugin make sure you delete everything under

/your path to/repository/org/apache/maven/plugins/maven-eclipse-plugin/

directory and then build your updated plugin by running “mvn install” on it.
This though can accidentally be overwritten by newer eclipse plugin but can be fixed by changing version of your custom plugin pom.xml from lets say 2.8 to 2.8-custom and then specifying it in plugin definition of your project like so

<build>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.8-custom</version>
                <configuration>
                    <packaging>war</packaging>
                </configuration>
            </plugin>

    ….

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>