Automatically download and run standalone Java app from Maven
I would like to have an application/script that I could use to execute a stand alone Java application (i.e. a basic class with a main method) from a given Maven artifact. Based on my research nothing like this currently exists, but I thought I'd ask the question to the community and see if anyone knows of a project that could support my needs.
The idea would be that I would pass in, either via a config file or the command line, a Maven artifact spec (group ID, artifact ID, and version) along with a fully qualified class name and a list of arguments. The given artif开发者_运维知识库act and all of its dependencies would then be downloaded (or not if they're already in the local repo) and the application would be launched with the appropriate classpath.
At this point I don't think it will be too difficult to implement a system that does this using the Aether library and Java's ProcessBuilder, but I was wondering if anyone else knew of an existing project that already handles this before I start reinventing the wheel.
Perhaps this is obvious, but why wont the exec plugin work? http://mojo.codehaus.org/exec-maven-plugin/
mvn exec:java -Dexec.mainClass=com.project.App
If com.project.App were part of another jar, you would include it as a dependency like you normally would.
Running an application using Maven is pretty simple. I wonder if this something that you are looking at or did I get the question wrong?
mvn exec:java -Dexec.mainClass="com.test.foo.Main" -Dexec.args="arg1 arg2..."
I have just pushed to Maven Central the Installation plugin. It allows installing and executing artifacts from repositories and it doesn't require a project.
It's very similar to package managers like yum, apt or gem:
mvn installation:install -Dartifact=groupId:artifactId
This will create a shortcut to your class available on the path.
精彩评论