Question

I want to make a jar file of my project but it shows error when I try to make jar.

Till now, I build a jar that is executed by using a command ,

java -cp <JAR FILE> <MAIN CLASS NAME>.

I have done this by adding plugin in the POM,

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
<descriptorRefs> 
<descriptorRef>jar-with-dependencies</descriptorRef> 
</descriptorRefs> 
</configuration> 
</plugin>

and by running command , mvn clean and mvn install assembly:assembly.

But I want a jar, that will run by using command java -jar <JAR FILE>

For that I read this link and implemented also. But it shows below error,

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project ThreadPool: Unable to parse configuration of mojo org.apache.maven.plugins:maven-jar-plugin:2.4:jar for parameter manifest: Cannot find setter, adder nor field in org.apache.maven.archiver.ManifestConfiguration for 'addClassPath' -> [Help 1] 

Please help me making jar file, that executes by using java -jar command. Thanks in advance . Looking for your kind response.

EDIT NO 1

I added below plugins, dependency in POM,

<!-- Example dependency -->
<dependencies>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>  
        </plugin>
    </plugins>
</build>
Was it helpful?

Solution

try this

<plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>your.fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
</plugin>

this will add

Main-Class: your.fully.qualified.MainClass 

header to jars's META-INF/MANIFEST.MF and make it runnable

You can run maven build as one line

mvn clean package assembly:single

OTHER TIPS

The error means that somewhere in your pom.xml file you have an element ClassPath that is not understood by the element you are configuring. Search for that and see if it makes sense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top