Add dependency packages and add local dependency packages when maven is packaged

When maven is packaged, the dependent jar package is not added by default, so if you want to create an independent runnable jar package, it is not possible to directly mvn clean install package. You need to change the pom file slightly and add the following plugin

<build>
		<sourceDirectory>src/main/java</sourceDirectory>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<defaultLibBundleDir>lib</defaultLibBundleDir>
					<source>1.5</source>
					<target>1.5</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix></classpathPrefix>
							<mainClass>com.xx.xx.xx</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>install</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>
								${project.build.directory}
                            </outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>

 

 

 

When maven is packaged, some jar packages are not in mavencenter. The relevant local jar package needs to be introduced in the pom, then the relevant depency should be changed as follows

<dependency>
        <groupId>org.wltea.ik-analyzer</groupId>
        <artifactId>ik-analyzer</artifactId>
        <version>3.2.8</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/ik-analyzer-3.2.8.jar</systemPath>
    </dependency>

 

For the war package system, sometimes it is necessary to type the jar package into the relevant war package. You can use the plugin to package all the jar files under lib into WEB-INF/lib by default. Of course, other files can also be packaged, such as xml, properties, etc. The relevant plugins are as follows:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warName>${project.artifactId}</warName>
                <webResources>
                    <resource>
                        <directory>lib/</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

 

Guess you like

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