Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create zip target instead of jar in maven?

Can someone please help me in creating a zip target instead of jar in maven. I tried several ways but couldn't progress. Given descriptor file in the assembly path is as follows:

<assembly>
<formats>
    <format>zip</format>
</formats>
<fileSets>
    <fileSet>
        <directory>src/main</directory>
    </fileSet>
</fileSets>
</assembly>

The assembly plugin section in my pom file is as follows:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/descriptor.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>
    </plugins>
</build>

Final Output:

[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ sql1 ---
[INFO] Building jar: C:\Divakar\mvn_project\sql1\target\sql1-0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
like image 948
divakar.scm Avatar asked Aug 01 '14 10:08

divakar.scm


People also ask

Is ZIP same as jar?

So jar files are actually a specific type of zip file. JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory.

Can I rename ZIP to jar?

Generally if your ZIP contains the class files (And not the sources): Just rename the file, a jar is a zip file. But if you're aiming for a class to be launched with command java -jar myProject. jar you should create a MANIFEST file containing the main-class and libraries to use in the classpath.

How do I create a jar folder in Target?

Summary. To create a JAR file from a Maven project in IntelliJ IDEA, go to the Maven Tool Window (View → Tool Windows → Maven), expand your project in the tree, expand Lifecycle, and then double-click on package. Maven will compile your package, and the compiled JAR file will be written to the target/ directory.


1 Answers

You need to bind the plugin to a particular build lifecycle phase via execution like this:

<executions> 
  <execution>
    <id>make-zip</id>
    <phase>package</phase>
    <goals>
      <goal>single</goal>
    </goals>
  </execution>
</executions>

Afterwards you can do it via mvn clean package.

like image 86
khmarbaise Avatar answered Oct 12 '22 08:10

khmarbaise