maven配置
分环境打包
<profiles>
<profile>
<id>dev</id>
<properties>
<project.env>dev</project.env>
</properties>
<!--默认激活测试环境-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<project.env>test</project.env>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<!-- 生产环境 -->
<id>prod</id>
<properties>
<project.env>prod</project.env>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
springboot
spring:
profiles:
active: @project.env@
spring
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources/common</directory>
</resource>
<resource>
<directory>src/main/resources/differ/${project.env}</directory>
</resource>
</resources>
</build>
或者把数据库账号密码等写在pom 文件profile-》properties中,在spring xml中使用${} 替换即可。
上传jar包到私服
maven settings.xml配置
<servers>
<server>
<!--该id与distributionManagement中repository元素的id相匹配-->
<id>releases</id>
<!--权限-->
<username>noah_yang</username>
<password>xxxx</password>
</server>
</servers>
pom.xml 配置
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<!--地址,但是需要在nexus给与对应库的权限-->
<url>http://172.xx.xx.xx:9988/repository/test-hosted/</url>
</repository>
</distributionManagement>
如果对nexus不太熟悉的,可以百度一下相关知识
配置私服下载jar
maven settings.xml配置
<profiles>
<profile>
<id>NexusRepo</id>
<repositories>
<repository>
<id>nexus-proxy</id>
<name>nexus-proxy</name>
<url>http://172.xx.xx.xx:9988/repository/test-proxy/</url>
<releases>
<enabled>true</enabled>
</releases>
<!-- snapshots默认是关闭的,需要手动开启 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>nexus-hosted</id>
<name>nexus-hosted</name>
<url>http://172.xx.xx.xx:9988/repository/test-hosted/</url>
<releases>
<enabled>true</enabled>
</releases>
<!-- snapshots默认是关闭的,需要手动开启 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>NexusRepo</activeProfile>
</activeProfiles>
这是全局的路径配置,对所以项目起作用