Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off jar compression in Maven

Tags:

maven-2

jar

build

Is there an option in Maven (2.0.9) to turn off jar compression for the entire operation? I'm using Maven both in the build server and in my work station and I'd like to disable jar compression on the work station builds (development only). However, I don't want to touch all the poms and create two versions for each.

Is there an option for turning off jar compression by environment variable, file or by touching a single pom.xml?

like image 510
Ran Biron Avatar asked Jun 23 '09 13:06

Ran Biron


People also ask

What is Maven jar plugin?

The maven jar plugin provides the capability to build jars files, if you define that your project is packaged as a jar file, maven will call implicitely to this plugin. We don´t need to define it inside pom. xml it will be downloaded and executed when maven needs it.

What is shaded jar in Maven?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

What is jar original in Maven?

jar file contains Spring boot framework class files having this contents while the . jar. original file contains actual class files of my application. Snapshot of target folder.


3 Answers

Apparently it's possible by defining this:

 <profile><id>...</id>
   <build>
     <pluginManagement>
         <plugins>
             <plugin>
                 <configuration>
                     <archive>
                         <compress>false</compress>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</profile>

in the top-level pom.xml. As a side note - this didn't really solved my initial problem of the build taking too much time.

like image 69
Ran Biron Avatar answered Oct 10 '22 15:10

Ran Biron


Add the following to the build.plugins section in your project's pom.xml file.

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <archive>
            <compress>false</compress>
        </archive>
    </configuration>
</plugin>

This turns off jar file compression for your maven project.

like image 30
walter Avatar answered Oct 10 '22 15:10

walter


finally I found the answer of this topic (turn off the jar compression), configuring directly into the pom, also I found other two interesting details: putting a different jar's name and includ a "manifest" definition. Here is my pom fragment.

<build>
    <finalName>***FileName***</finalName>

    <plugins>

        <!-- Set a JDK compiler level -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>

        <!-- Make this jar executable -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
              <archive>
                <manifest>
                    <!-- Jar file entry point -->
                    <mainClass>***package.test.ClassTest***</mainClass>
                </manifest>
                <compress>***false***</compress>
              </archive>
            </configuration>
        </plugin>

    </plugins>
</build>
like image 1
Lisandro López Villatoro Avatar answered Oct 10 '22 15:10

Lisandro López Villatoro