Roman Kazanovskyi
Roman Kazanovskyi

Reputation: 3599

Maven ignored maven archiver

I'm 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>

I can see in logs that maven execute it:

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

but it don't put main class to MANIFEST.MF:

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

i don't understand why. I work with Idea.

Upvotes: 3

Views: 1078

Answers (3)

bodyjares
bodyjares

Reputation: 440

@khmarbaise is wrong in his definition of PluginManagement. According to the definition in Maven documentation, PluginManagement is intended to configure project builds that inherit from this one. In your pom.xml you have no needs to keep the PluginManagement node.

You only have to change the location of your configuration node from execution level to plugin level. You can see that @khmarbaise did that 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>

Furthermore you don't have to keep the executions node anymore because maven-jar-plugin is already bound to the build life-cycle as @khmarbaise mentioned it.

Upvotes: 0

khmarbaise
khmarbaise

Reputation: 97487

You have to define the configuration in a pluginManagement area cause the maven-jar-plugin is already bound to the build life-cycle

  <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 you have is that the execution you have defined means to have a supplemental execution as the log output shows and not change the configuration of the existing execution within the life cycle. Furthermore you seemed to be running on Maven 2 instead of Maven 3 and you should update as soon as possible because Maven 2 has been defined EoL

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

Upvotes: 2

Trink
Trink

Reputation: 584

Try to compile manually by prompt: mvn compile
or try: mvn clean install -Dmaven.test.skip=true
What IDE are you using?

Upvotes: 0

Related Questions