Dubbo微服务打成可执行jar包
1.配置pom.xml,遇到了很多问题,总结如下dubbo-service${project.build.directory}/classessrc/main/resourcestrue**/*.xml**/*.properties
·
1.配置pom.xml,遇到了很多问题,总结如下
<!-- 构建项目配置 -->
<build>
<finalName>dubbo-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>**/*.xml</include> <!-- 把src/main/resources下所有文件夹的所有后缀名为.xml的文件 移到根路径 -->
<include>**/*.properties</include> <!-- 把src/main/resources下所有文件夹的所有后缀名为.properties的文件 移到根路径 -->
</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/WEB-INF/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>
2.cmd命令打包,cd到项目文件目录(前提要配置好maven环境变量,没配的朋友,跳转:http://blog.csdn.net/icoudsoft_saas/article/details/50390873)
执行:mvn clean install
2.eclipse上打包
3.进入到target目录
4.运行dubbo服务,用jre运行,(前提:必须配置jdk和jre环境变量,没配的朋友跳转:http://blog.csdn.net/icoudsoft_saas/article/details/50390849)
cmd 到jar包的路径,然后执行:java -jar dubbo-service.jar &
打包启动完成,这是windows的部署,linux也一样(手动的),如果想要shell脚本打包,可以留言
更多推荐
已为社区贡献1条内容
所有评论(0)