Idea maven插件方式打包dubbo_provide成可运行的包

时间:2024-03-18 13:36:08

1.在项目pom文件加入

<build>
    <!--打成jar的名称-->
    <finalName>project-service</finalName>
    <resources>
        <resource>
            <targetPath>${project.build.directory}/classes</targetPath>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>

        <!-- 结合com.alibaba.dubbo.container.Main,因为dubbo自带的Main需要读取classes/META-INF/spring下的spring配置信息 -->
        <resource>
            <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
            <directory>src/main/resources/spring</directory>
            <filtering>true</filtering>
            <includes>
                <!--将spring相关的配置文件拷贝到classes/META-INF/spring下 -->
                <include>application-context.xml</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <!-- 配置manifest文件,以及服务jar的启动类 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classesDirectory>target/classes/</classesDirectory>
                <archive>
                    <manifest>
                        <!--执行Jar文件的启动类,使用dubbo自带的启动类 -->
                        <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                        <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                        <useUniqueVersions>false</useUniqueVersions>
                        <addClasspath>true</addClasspath>
                        <!--将服务依赖的jar文件,放到lib文件夹下 -->
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <!-- 将运行服务的jar文件,依赖的其它jar文件放在lib文件夹下 -->
        <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>
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2.Help->findAction搜索MavenProjects

Idea maven插件方式打包dubbo_provide成可运行的包3.出现右侧工具栏

选择要打包的provide项目,同时右击run maven build,则在项目文件同目录的target生成可运行的jar包

Idea maven插件方式打包dubbo_provide成可运行的包Idea maven插件方式打包dubbo_provide成可运行的包

4.dos命令行进入对应的目录,java -jar project-service.jar(替换成自己的包名),运行则可,需要的注意的是lib和jar包要在同目录保证,所运行的类的,能找到对应的包  ,同时,还要把项目的中依赖的其他项目,install到自己的本地的库