Dubbo之服务项目打成jar

pom.xml增加配置

<!-- 构建项目配置 -->
<build>
    <finalName>zns-article-service</finalName>
    <!-- 加载资源 -->
    <resources>
        <resource>
            <targetPath>${project.build.directory}/classes</targetPath> <!-- 设置根路径,classes文件是源文件 -->
            <directory>src/main/resources</directory>  <!-- 制定文件夹src/main/resources下面的文件移到根路径, src/main/resources 这个路径存放所有配置文件 -->
            <filtering>true</filtering>
            <includes>
                <!-- **/* 代表读取src/main/resources所有,不管啥文件,全部移到根路径 -->
                <include>**/*</include>
            </includes>
        </resource>

        <!-- 结合com.alibaba.dubbo.container.Main -->
        <resource>
            <!-- dubbo Main方法 默认读取/classes/META-INF/spring文件下的spring-context.xml文件,所以要将spring-context.xml文件移到该目录 -->
            <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
            <directory>src/main/resources/spring</directory> <!-- 这是我的项目存放spring-context.xml的目录 -->
            <filtering>true</filtering>
            <includes>
                <include>spring-context.xml</include> <!-- 将 spring-context.xml 移到启动文件目录下 -->
            </includes>
        </resource>
    </resources>

    <pluginManagement>
        <plugins>
            <!-- 解决Maven插件在Eclipse内执行了一系列的生命周期引起冲突 -->
            <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>
        <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classesDirectory>target/classes/</classesDirectory>
                <archive>
                    <manifest>
                        <mainClass>com.alibaba.dubbo.container.Main</mainClass> <!-- 主方法,dubbo官方提供的 -->
                        <!-- 打包时 MANIFEST.MF文件不记录时间戳版本 -->
                        <useUniqueVersions>false</useUniqueVersions>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <type>jar</type>
                        <includeTypes>jar</includeTypes>
                        <!--<useUniqueVersions>false</useUniqueVersions>-->
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

 

转载于:https://www.cnblogs.com/zengnansheng/p/10404661.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值