0

New to Maven...

I have succeeded in creating a jar for my app. I'd like to run the app from this jar "java -jar foo.jar MyClass" but I have no idea where to get (and package) all the dependencies. Does maven have a goal to do this? If not, do I use something like proguard? And then how do I thread that into the maven goals?

Thanks in advance

  • Thanks all. Indeed, the answer is here http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven – user2884343 Oct 16 '13 at 14:27

3 Answers3

0

Maven puts ALL of your dependencies in your ~/.m2 folder. (if you're using maven 2)

Provided your pom.xml has everything it needs, doing a mvn clean install will handle all of the details.

Keep in mind you can do a mvn dependency:tree in your project to see all of it's dependencies :p

yamafontes
  • 5,552
  • 1
  • 18
  • 18
  • I think the OP wants to package the dependencies _with the artifact_ so that is can be executed. Having the dependencies in `~/.m2` ain't much help with that... – Boris the Spider Oct 15 '13 at 22:26
0

Maven will download all dependencies recursively and place them into your local repository.

Once of the tricky things about running java from the command line is getting the classpath right. However, you could get Maven to execute it for you:

How do I execute a program using Maven?

Community
  • 1
  • 1
NickJ
  • 9,380
  • 9
  • 51
  • 74
0

This is not exactly the answer to your queston, but to create a "fat" jar, with all dependencys packed into, try the maven complier plugin:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.stackoverflow.example.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
MemLeak
  • 4,456
  • 4
  • 45
  • 84