JAR Maven项目依赖于远程机器而不依赖于相关性 [英] JAR Maven project with dependencies on remote machine without dependencies

查看:118
本文介绍了JAR Maven项目依赖于远程机器而不依赖于相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Maven Java 的新手。我正试图在远程机器上运行hdfs MapReduce作业。我没有写入/编辑依赖关系文件的权限。我想知道是否可以将 JAR 我的Maven项目传递给我的MapReduce作业。这样我就不需要通过SSH连接到远程机器并改变Maven项目的依赖关系。我将使用包含远程计算机上未包含的所有所需依赖项的JAR来运行我的MapReduce作业。 您可以使用来做到这一点。



将它添加到你的POM并进行相应的配置(看看下面的示例)。
$ b 这会创建一个额外的jar,包含从命令行运行jar所需的所有依赖项,并且将使用要执行的 main()方法标记该类(再次考虑,这可能是可选的,因为您可以在运行 java -jar 时指定主类。)



这里是(部分)我的MainJooqClass :

 包sunshine.web.shaker.main; 

//进口

public class MainJooqClass {

public static void main(String [] args){

// code

}

}

以下是配置插件的POM部分:

 < project xmlns =http://maven.apache。 org / POM / 4.0.0xmlns: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>
<配置>
< descriptorRefs>
< descriptorRef> jar -with-dependencies< / descriptorRef>
< / descriptorRefs>
<档案>
< manifest>
< mainClass> sunshine.web.shaker.main.MainJooqClass< / mainClass>
< / manifest>
< / archive>
< / configuration>
<执行次数>
<执行>
< id> make-assembly< / id>
<阶段>包< /阶段>
<目标>
< goal>单< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>

< / plugins>
< / build>

< dependencies />

< / project>


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.

解决方案

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>

这篇关于JAR Maven项目依赖于远程机器而不依赖于相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆