Through maven's GAV, you can avoid using the same component in the project ===", that is, the component that is packaged out and eventually the same GA must have only one
But in addition to this GA component only, we often encounter the same scene in the java project. For example, the typical is mail.
referenceThe maven project that the mail could not be sent introduces a new dependency problem
There are also a few problems with class names that cause class duplication.
How to solve this problem? ? ?
In fact, it is difficult to say that it is not easy ~ what we need to do is to check the corresponding class to check whether there is a duplicate!
Abstract, that is to say, in a bunch of folders we have to find the file with the exact same file path.
All jars are traversed inside the class file for output and sorted.
For example, we can have some third-party scriptsshow-duplicate-java-classes
After the corresponding directory is executed, the output is as follows
11 (1@3): ./woden-impl-dom-1.0M8.jar ./stax-api-1.0.1.jar ./xml-apis-1.3.04.jar
1 javax/xml/namespace/QName.class
12 (223@2): ./quartz-all-1.6.1.jar ./quartz-1.6.1.jar
1 org/quartz/impl/jdbcjobstore/JobStoreSupport$VoidTransactionCallback.class
2 org/quartz/impl/jdbcjobstore/JobStoreSupport$25.class
3 org/quartz/impl/StdJobRunShellFactory.class
4 org/quartz/impl/QuartzServer.class
In this case, it can be corrected according to the corresponding problem.
Use the maven plugin to find problems during compile time [of course I will ignore some jars provided by the container] but most of them are OK, as follows
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-ban-duplicate-classes</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<banDuplicateClasses>
<ignoreClasses>
<ignoreClass>javax.*</ignoreClass>
<ignoreClass>org.junit.*</ignoreClass>
<ingoreClass>org.aspectj.*</ingoreClass>
<ingoreClass>org.jboss.netty.*</ingoreClass>
<ingoreClass>org.apache.juli.*</ingoreClass>
<ingoreClass>org.apache.commons.logging.*</ingoreClass>
<ingoreClass>org.apache.log4j.*</ingoreClass>
<ingoreClass>org.objectweb.asm.*</ingoreClass>
<ingoreClass>org.parboiled.*</ingoreClass>
<ingoreClass>org.apache.xmlbeans.xml.stream.*</ingoreClass>
<ingoreClass>org.json.JSONString</ingoreClass>
</ignoreClasses>
<findAllDuplicates>true</findAllDuplicates>
</banDuplicateClasses>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.0-beta-6</version>
</dependency>
</dependencies>
</plugin>
For example, if a classmate introduces a new dependency, some new classes appear in the system and the original is repeated. Then, in the process of maven compilation, an error will be reported.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-ban-duplicate-classes) on project web: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :web
Can view detailed error information
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-ban-duplicate-classes) @ web ---
[INFO] Adding ignore: javax.*
[INFO] Adding ignore: org.junit.*
[INFO] Adding ignore: org.aspectj.*
[INFO] Adding ignore: org.jboss.netty.*
[INFO] Adding ignore: org.apache.juli.*
[INFO] Adding ignore: org.apache.commons.logging.*
[INFO] Adding ignore: org.apache.log4j.*
[INFO] Adding ignore: org.objectweb.asm.*
[INFO] Adding ignore: org.parboiled.*
[INFO] Adding ignore: org.apache.xmlbeans.xml.stream.*
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:
Duplicate classes found:
Found in:
org.skyscreamer:jsonassert:jar:1.4.0:compile
org.json:json:jar:20140107:compile
Duplicate classes:
org/json/JSONString.class
We can know that the org.json.JSONString class has appeared in both jars~ need to pay attention!
First talk about the role of Maven-Enforcer-Plugin this plugin ENFORCER plugin:Constraint and inspections on the environment Source code root directory, Find the POM.xml file, open it, find the locati...
【background】 Spring-boot project executionmvn clean packageEncountered a problem when packaging, the error is as follows: The BehaviorDataApplication and ReportRankDataDomain classes have their own ma...
Problem: Execution jar can't find dependent class After compiling with Maven, it was produced.ui-compressor-1.0.0.jar, execute at this time Prompt below can not find the dependent package: Unzip the j...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) on project ly-common: Execution default of goal org.springframework.boot:spring-boot-...
1 The following error occurred during install 2 solution 2.1 Add main method The main method can be arbitrary, for example: Structure directory: butDon'tAdd @SpringBootApplication annotation to the ma...
1 The following error occurred during install 2.1 Add main method The main method can be arbitrary, for example: Structure directory: butDon'tAdd @SpringBootApplication annotation to the main method! ...
1 INSTALL happened as follows 2 solution modification pom.xml file Will be original: Replace with: OK...
This is your configuration file is your company's private server. You don't have these jar packages on your private server. It has nothing to do with your local area. I am like this. There is nothing ...
solution The parent projectinstallGo to the local warehouse and repackage the sub-projects Error Scenario The parent project needs to use the sub-project, and the sub-project will be added to the POM ...
Error: At first, I thought this error was something wrong with the settings.xml file, and then I changed it several times, and changed many other people’s configuration files. In the end, I stil...