maven 构建可执行的jar 配置
博客专区 > 汪林 的博客 > 博客详情
maven 构建可执行的jar 配置
汪林 发表于2年前
maven 构建可执行的jar 配置
  • 发表于 2年前
  • 阅读 62
  • 收藏 8
  • 点赞 2
  • 评论 0

移动开发云端新模式探索实践 >>>   

摘要: maven项目,打成可执行的jar。 例如,java -jar demo.jar
<build>
    <plugins>

        <!-- 将所依赖的所有jar打包在一起 -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.**.StartUp</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>assembly</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- 打成jar包的插件  -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.**.Startup</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <!-- 编译插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>

        <!-- junit 测试插件 打jar包的时候跳过测试 设置skip=true -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>

        <!-- 要将源码放上去,需要加入这个插件 -->
        <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>


  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 7
博文 11
码字总数 8847
×
汪林
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: