问题
I am new to Maven
and Java
. I am trying to run a hdfs MapReduce job on a remote machine. I do not have permissions to write/edit the dependencies file. I was wondering if it was possible to JAR
my Maven project and pass it to my MapReduce job. That way I dont need to SSH in to the remote machine and change the maven projects dependencies. I would use the JAR that contained all the needed dependencies that are not included on the remote machine to run my MapReduce job.
回答1:
You can do that with the maven assembly plugin.
Add it to your POM and configure accordingly (have a look at my example below).
This will create an additional jar, that contains all the dependencies needed to run the jar from the command line, and will mark the class with the main()
method to be executed (on second thought, this may be optional, as you can specify the main class when running java -jar
).
Here's (part of) my MainJooqClass:
package sunshine.web.shaker.main;
// imports
public class MainJooqClass {
public static void main(String[] args) {
// code
}
}
And here's the part of my POM that configures the plugin:
<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/xsd/maven-4.0.0.xsd">
<!-- ... -->
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>sunshine.web.shaker.main.MainJooqClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies />
</project>
来源:https://stackoverflow.com/questions/29308719/jar-maven-project-with-dependencies-on-remote-machine-without-dependencies