1

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. JAR view in jd-gui

Hector Ruiz
  • 123
  • 3
  • 12
  • Into... what jar? Why is there a pom in the jar? Without knowing anything about your build environment etc. it's impossible to provide meaningful advice. – Dave Newton Feb 04 '16 at 17:23
  • What do you mean with `it still uses an older version of the pom.xml`? Maven uses the `pom.xml` on your current directory, except if you configure it otherwise (with `-f`) – Joao Morais Feb 04 '16 at 17:41
  • @Dave Newton Please see EDIT 1 – Hector Ruiz Feb 04 '16 at 20:35
  • @Joao Morais I know what you mean. That's *exactly* what I thought. However, if I run `maven package` in the original directory it includes an older version of the pom.xml (the one with errors). This is also reflected in the manifest which lacks the 2 values that the correct (latest) pom.xml adds. – Hector Ruiz Feb 04 '16 at 20:37
  • As @Margo Vargas points out in his answer, what is your folder structure of project before running mvn package? Maybe if zou put it on some public repo, we could take a better look – Hurda Feb 04 '16 at 20:57
  • try to run mvn clean pakcage (make sure clean does not fail because you have opened some files in target folder) – Hurda Feb 04 '16 at 20:59

2 Answers2

1

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.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Also of note is that there's no SNAPSHOT in OP's version number, and it sounds like they'll be happier if it's there (see http://stackoverflow.com/questions/5901378/what-exactly-is-a-maven-snapshot-and-why-do-we-need-it) – Gus Feb 04 '16 at 20:59
0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Marco Vargas
  • 1,232
  • 13
  • 31
  • This is my folder structure. I'm actually using IntelliJ but I can't get it to pack the JAR. That's why I decided to run the command in the console. God bless you too! – Hector Ruiz Feb 04 '16 at 20:41