Maven ignores maven archiver

I am using maven-jar-plugin in pom.xml.

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <!-- DO NOT include log4j.properties file in your Jar -->
                            <archive>
                                <manifest>
                                    <!-- Jar file entry point -->
                                    <addClasspath>true</addClasspath>
                                    <mainClass>com.example.Manager</mainClass>
                                    <classpathPrefix>dependency-jar/</classpathPrefix>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

      

In the logs, I can see that maven is executing it:

[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: example.jar
[INFO] [jar:jar {execution: jar}]

      

but it doesn't put the main class in MANIFEST.MF:

Manifest-Version: 1.0
Built-By: romkazanova
Build-Jdk: 1.7.0_65
Created-By: Apache Maven
Archiver-Version: Plexus Archiver

      

I do not understand why. I am working with Idea.

+3


source to share


3 answers


You have to define the config in the pluginManagement scope because the maven-jar-plugin is already tied to the build lifecycle

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>com.example.Manager</mainClass>
                <classpathPrefix>dependency-jar/</classpathPrefix>
              </manifest>
            </archive>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

      



The problem is that the execution you specified means there is additional execution as log output and does not change the configuration of the existing execution in the lifecycle . Also, you seem to have been working on Maven 2 instead of Maven 3 and you should update as soon as possible since Maven 2 was defined by EoL

You can of course add the maven-jar-plugin version.

+2


source


Try running the command manually at the prompt: mvn compile
or try: mvn clean install -Dmaven.test.skip = true
Which IDE are you using?



0


source


@khmarbaise is wrong in his definition of PluginManagement . As defined in the Maven documentation, PluginManagement is for customizing the build of projects that inherit from this. In your pom.xml, you don't need to support PluginManagement node.

You need to change the location of your node config from runlevel to plugin level. You can see @khmarbaise did this too.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <!-- DO NOT include log4j.properties file in your Jar -->
        <archive>
            <manifest>
                <!-- Jar file entry point -->
                <addClasspath>true</addClasspath>
                <mainClass>com.example.Manager</mainClass>
                <classpathPrefix>dependency-jar/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>jar</id>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

      

Also, you don't need to continue running node anymore because the maven-jar-plugin is already tied to the build lifecycle as @khmarbaise mentioned.

0


source







All Articles