标签:
按住shift 点击鼠标右键,点击“在此处打开命令窗口”,在窗口中输入“mvn package”,如下图
我的没有配环境,要在maven安装目录下找到bin目录,并记录该路径,然后复制到命令窗口中,如下图
回车,等待结果,结果如下(不要关闭命令窗口)
在项目target目录下可以看到生成的jar
在命令窗口中输入:clean -P test source:jar install -Dmaven.test.skip
执行配置分离,想完成这一步需要在代码中进行配置,否则无法成功。
目录结构如下:
pom.xml中添加:
<!-- 开发环境dubbo打包配置,不分离部署文件 -->
<build>
<!-- 该属性根据项目自定义,一般取值项目的artifactId -->
<finalName>ticketapply-schedule</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>assemble/*.xml</exclude>
<exclude>conf/**/*.*</exclude>
</excludes>
</resource>
</resources>
<!--开发环境自定义打包插件,不需修改 -->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/assemble/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- 正式环境打包配置,配置文件和代码分离 -->
<profiles>
<profile>
<!-- 该属性不可修改,以免影响配置打包 -->
<id>test</id>
<build>
<!--自定义打包插件,不需修改 -->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<!--正式环境自定义打包描述文件 -->
<descriptor>src/main/resources/assemble/dubboPackage.xml</descriptor>
<descriptor>src/main/resources/assemble/dubboConfigPackage.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
dubboConfigPackage.xml
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>dubboConfig</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources/conf</directory>
<outputDirectory>dubboConfig</outputDirectory>
<includes>
<include>**/*.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
dubboPackage.xml
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources/conf</directory>
<outputDirectory>conf</outputDirectory>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<!-- 将scope为runtime的依赖包打包到lib目录下。 -->
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
package.xml
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources/conf</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
命令窗口中输入命令并执行
target目录下会多出几个文件
dubboConfig是所有配置文件,package是spring文件+配置文件+lib,sources是源码
标签:
原文地址:http://blog.csdn.net/kp783491236/article/details/51261797