Skip to content

Instantly share code, notes, and snippets.

@jesperfj
Created April 30, 2012 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperfj/2560204 to your computer and use it in GitHub Desktop.
Save jesperfj/2560204 to your computer and use it in GitHub Desktop.
M2Eclipse and copy-dependencies problem

Take a simple Maven app like this JAX-RS app:/

$ git clone http://github.com/heroku/template-java-jaxrs.git
Cloning into template-java-jaxrs...
remote: Counting objects: 348, done.
remote: Compressing objects: 100% (156/156), done.
remote: Total 348 (delta 97), reused 348 (delta 97)
Receiving objects: 100% (348/348), 39.70 KiB | 45 KiB/s, done.
Resolving deltas: 100% (97/97), done.

The POM looks like this:

$ cd template-java-jaxrs/
$ cat pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>jax-rs-heroku</artifactId>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <!-- Jetty -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-servlet</artifactId>
            <version>7.6.0.v20120127</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-webapp</artifactId>
            <version>7.6.0.v20120127</version>
        </dependency>

        <!-- Jersey -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.8</version>
        </dependency>

        <!-- jUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

This project uses the maven-dependency-plugin to copy all dependencies into a single directory in target. That allows us to start the app with a single command line like this:

$ java -cp target/classes:"target/dependency/*" com.example.Main

This approach is simpler than using a start script to build an explicit classpath and it's faster than building a "super jar" that contains all dependencies in a single jar.

Unfortunately, M2Eclipse doesn't like it. If we import this project into Eclipse using M2Eclipse:

You get this:

M2Eclipse complains that the goal copy-dependencies is not supported by M2Eclipse.

There is clearly nothing wrong with the POM file. I'd like to continue to use the copy-dependencies approach while using M2Eclipse in my IDE. I don't see why the two cannot coexist. But perhaps I am missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment