Maven uses profile to set multiple links with different configurations

Set the profiles node in the pom file
	<profiles>
		<profile>
			<!-- local development environment -->
			<id>dev</id>
			<activation>
			<!-- <activeByDefault>true</activeByDefault>  -->
				<property>
					<name>env</name>
					<value>dev</value>
				</property>
			</activation>
			<properties>
				<profiles.active>dev</profiles.active>
			</properties>
		</profile>
		<profile>
			<id>sit</id>
			<activation>
				
				<property>
					<name>env</name>
					<value>sit</value>
				</property>
			</activation>
			<properties>
				<profiles.active>sit</profiles.active>
			</properties>
		</profile>

		<profile>
			<id>uat</id>
			<activation>
				<property>
					<name>env</name>
					<value>uat</value>
				</property>
			</activation>
			<properties>
				<profiles.active>uat</profiles.active>
			</properties>
		</profile>

		<profile>
			<!-- Production Environment-->
			<id>prd</id>
			<properties>
				<profiles.active>prd</profiles.active>
			</properties>
		</profile>

	</profiles>
Maven packaging supports profile environment to replace configuration files of different environments (xml configuration file and properties configuration file)
	<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-active-profile-resources</id>
						<phase>process-resources</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${basedir}/target/classes</outputDirectory>
							<resources>
								<resource>
									<directory>${project.basedir}/profiles/${profiles.active}</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
							<overwrite>true</overwrite>
						</configuration>
					</execution>	
				</executions>
			</plugin>

 

1: Configure the profile folder in the project, and then configure the dev, sit, uat folders under this folder, and put the corresponding configuration files respectively

2: Use the maven command for different configuration files, configure clean install -Dmaven.test.skip=true -P dev in eclipse, and use mvn clean install -Dmaven.test.skip=true -P dev in maven 

If you need to upload to the private server nexus, you encounter a 401 error, and you need to configure the username and password with the id of Releases and Snapshots in the server node of the setting configuration file under the maven installation path.

	<distributionManagement>
		<repository>
			<id>Releases</id>
			<name>Team Nexus Release Repository</name>
			<url>http://xxxx:7001/nexus/content/repositories/releases/</url>
		</repository>
		<snapshotRepository>
			<id>Snapshots</id>
			<name>Team Nexus Snapshot Repository</name>
			<url>http://xxxx:7001/nexus/content/repositories/snapshots/</url>
			<uniqueVersion>true</uniqueVersion>
		</snapshotRepository>
	</distributionManagement>

    <server>
           <id>Releases</id>
              <username>xxx</username>
            <password>xxx</password>
          </server>
<server>
			<id>Snapshots</id>
			<username>xxx</username>
            <password>xxxx</password>
</server>

 

3: Use the maven plugin maven-compiler-plugin to set the encoded jdk version and encoding format

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>${jdk.version}</source>
					<target>${jdk.version}</target>
					<encoding>${project.build.sourceEncoding}</encoding>
				</configuration>
			</plugin>

 4: You can also set the version of JDK in setting.conf under the maven installation directory

 

<profile>
			<id>jdk8</id>
			 <activation>
				  <activeByDefault>true</activeByDefault>
				  <jdk>1.8</jdk>
			 </activation>
			 <properties>
				  <maven.compiler.source>1.8</maven.compiler.source>
				  <maven.compiler.target>1.8</maven.compiler.target>
				  <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
			 </properties>
		</profile>

5: Use the maven plugin maven-war-plugin to hit the war package

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<!--Local db configuration and migration do not need to be deployed in containers in test, sit, uat, prd environments-->
					<packagingExcludes>WEB-INF/classes/config/**</packagingExcludes>
				</configuration>
				<version>2.4</version>
			</plugin>

 6: Get the maven configuration file that takes effect from the local command line:

mvn help:effective-settings

7: maven command line for remote deployment of private servers

mvn deploy:deploy-file -Dfile=.\target\xxxx.jar Dpackaging=jar -Durl=http://xxxx:7001/nexus/content/repositories/snapshots  -DgroupId=com.xxx -DartifactId=xxx -Dversion=0.0.1-SNAPSHOT

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326572743&siteId=291194637