I've just started using Maven for one of my Java projects. It took me a few edits to get Maven to accept the pom.xml
but I finally got it working. However, to my surprise it still uses an older version of the pom.xml
!
The thing is that I can't even find it in the project's directory. I used Notepad++ for all my edits. When I open pom.xml
it's the correct (latest) version. When I look into the JAR with jd-gui
, it's the previous version that Maven was complaining about. This makes no sense. I tried deleting everything in the target directory and running 'maven clean' to no avail.
Here's the current pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>solint</artifactId>
<version>1.0</version>
<name>SolInt</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<!-- Prepares Agent JAR before test execution -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestEntries>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
<Premain-Class>my.project.Agent</Premain-Class>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
</dependencies>
</project>
The only way I've been able to force Maven to use the latest version of pom.xml
is to copy the whole project to a different directory. I want to understand this mystery. Any ideas?
EDIT 1:
Here's how the JAR looks after mvn package
. Note that this one has the correct pom.xml because I changed the root directory.
If you deleted everything, then the next copy of the jar file built should contain the at-that-time current pom.xml file.
However, if you are actually loading the JAR file out of the ~/.m2/repo cache, then you need to do a maven install to update the cache, and then the projects that use that JAR will get the last installed version.
I suggest you to take a look here to find out where your pom.xml should be located inside your folder structure.
Another important thing is to understand how your folders structure should be; for this, please take a look here .
Basically, you should have something like this:
+ Project Folder
|
+ src
|
+ main
|
+ java
|
+ {here goes your package, classes, etc.}
|
i.e.
|
+ com
|
+ sample
|
+ HelloWorld.java
|
+ pom.xml
Also it's important, that you can have poms inheriting from other Poms and you also could have aggregation to group several poms on a project, check this to get more info.
Also, I will suggest you to use a IDE instead just Notepad++, such IntelliJ or Eclipse ; both have Maven Integration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.