JAR Maven project with dependencies on remote machine without dependencies

*爱你&永不变心* 提交于 2019-12-25 02:55:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!