9
I want to use the Maven to generate the JAR with its dependencies in format .jar
, the solutions I found are not valid.
The Eclipse has three forms of generate a executable JAR.
- Extract required Libraries into gerenated JAR
- Package required Libraries into generated JAR < I use that in Eclipse.
- Copy required Libraries into a sub-Folder next to the generated JAR
And Maven has a form equivalent to Eclipse?
Using maven-jar-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>qualquer.que.seja.seu.pacote.ClasseMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Problem: This mode generates a JAR without format dependencies .jar
.
Using maven-assemply-plugin
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>qualquer.que.seja.seu.pacote.ClasseMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
Problem: Generates a JAR with "extracted" dependencies out of format .jars
.
I used that method and I get
[ERROR] Could not find goal 'attached' in plugin org.apache.maven.plugins:maven-shade-plugin:2.2 among available goals shade, help -> [Help 1]
and others. are looking for solutions.– noNihongo
Bug fixed. Was using
<goal>attached</goal>
I traded for<goal>shade</goal>
.– noNihongo
@Eduardobentorochajunior Okay, I was just going to say I was more like the other answer.
– utluiz
@Liuutz, I like that
shade
, for each compilation it generates a JAR and keeps an old one, is that right? Has some way of having the.jar
guycommons-net-3.3.jar
. In all the tests I’ve done with Maven I have the Folder of my dependenciesorg/apache/commons/..
I believe it will work the same way, but my JAR earns a few kB and more. D– noNihongo
@Eduardobentorochajunior That’s right. Usually the new super jar serves for distribution and is fatter even, since it includes the dependencies within it. That way, you don’t need to have the jars in the folder. But, if you want to have the dependencies in separate jars, then you can use the other plugin (Assembly) to create a zip with the jars, for example.
– utluiz
+1 Hade is the scheme to package Big Yard easy to run.
– elias