zoukankan      html  css  js  c++  java
  • maven设置打jar包并引入依赖包

    --------------------------------------------------------方法一:将jar包和项目打在一起---------------------------------

    1.修改pom根节点下packaging属性为jar

    2.修改pom根节点下build为:

        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.hbase2Redis.Hbase2Redis</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    3.使用maven install 打包,将在target下生成项目jar包xxx-with-dependencies.jar复制出来,执行java -jar xxx-with-dependencies.jar即可运行。

    --------------------------------------------------------方法二:将jar包和项目分离---------------------------------------

    1.修改pom根节点下packaging属性为jar

    2.修改pom根节点下build为:

        <build>
            <finalName>Hbase2Redis</finalName>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.m2e</groupId>
                        <artifactId>lifecycle-mapping</artifactId>
                        <version>1.0.0</version>
                        <configuration>
                            <lifecycleMappingMetadata>
                                <pluginExecutions>
                                    <pluginExecution>
                                        <pluginExecutionFilter>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-dependency-plugin</artifactId>
                                            <versionRange>[2.0,)</versionRange>
                                            <goals>
                                                <goal>copy-dependencies</goal>
                                            </goals>
                                        </pluginExecutionFilter>
                                        <action>
                                            <ignore />
                                        </action>
                                    </pluginExecution>
                                </pluginExecutions>
                            </lifecycleMappingMetadata>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <!-- 主方法所在类名 -->
                                <mainClass>com.hbase2Redis.Hbase2Redis</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <!-- 将依赖包放到lib文件夹中 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    3.使用maven install 打包,将在target下生成项目jar包xxx.jar及lib文件夹,将这两者放在同一目录下,执行java -jar xxx.jar即可运行。

  • 相关阅读:
    ava的动态代理机制详解
    Windows10系统切换JDK版本(前提是装了多个版本的JDK)
    关于springMVC传参问题
    js的replace函数把"$"替换成成"$"
    vue框架之组件通信及插槽简介等相关内容-113
    vue框架之前后端交互等相关内容-112
    django框架之cookie和session的使用等相关内容-74
    vue框架之基础语法等相关内容-111
    vue框架之初始、模板语法、指令等相关内容-110
    django框架之forms渲染错误信息、全局钩子及cookie引入等相关内容-73
  • 原文地址:https://www.cnblogs.com/sheeva/p/5032706.html
Copyright © 2011-2022 走看看