目标:
- 使用maven构建项目,不依赖具体IDE
- 使用spring profile做环境选择,无需手动调整
项目构建
目标:使用maven构建项目,不依赖具体IDE
步骤
- 把zpy-common, zpy-jxgl, 等子项目放入 zpy父项目路径下。
- 调整zpy 父 pom,添加以下maven插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.source}</source>
<target>${java.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
- 调整zpy下面 zpy-jxgl, zpy-sbgl, zpy-wx, zpy-xxgl 的webapp子工程,添加
<packaging>war</packaging>
- 调整zpy-wx 依赖,把对zpy-jxgl的依赖改为
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-jxgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
多添加了<classifier>classes</classifier>
属性
- 调整zpy-web依赖,依赖改为:
<dependencies>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-jxgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-jxgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-xxgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-xxgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-wx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-wx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-sbgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-sbgl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>alipay</groupId>
<artifactId>alipay-sdk</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/alipay-sdk-java20170615110434.jar</systemPath>
</dependency>
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.70.0</version>
</dependency>
</dependencies>
修改了对其他war包依赖,不仅依赖war中class,还需把WEB-INF/jsp 下面的jsp文件打入当前war包。所以不仅依赖于war,还依赖于jar。
war 插件无需修改,为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
<overlays>
<overlay>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-jxgl</artifactId>
</overlay>
<overlay>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-xxgl</artifactId>
</overlay>
<overlay>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-wx</artifactId>
</overlay>
<overlay>
<groupId>com.zrsf.vat</groupId>
<artifactId>zpy-sbgl</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
经过以上步骤调整,就可以使用maven做项目构建。构建步骤如下:
- 切换到spy-web项目跟路径下。
- 执行maven指令
mvn clean package -Dmaven.test.skip=true
- 执行完成后会在该项目target下生成war
项目环境
目标:使用spring profile做环境选择,无需手动调整
由于该项目已经使用spring profile做环境的构建,无需做配置,只需在不同环境,激活不同的环境。
例如:在test环境,只需在tomcat/bin下面添加2个文件,用来设置环境变量。文件内容如下:
- setenv.bat (windows环境使用)
set SPRING_PROFILES_ACTIVE=test
- setenv.sh (liunx环境使用)
export SPRING_PROFILES_ACTIVE=test
网友评论