Create a tar with maven generated jar with dependenceis and few other files

srikanth

I'm new to maven and its interesting subject to learn. Succeed to create a jar with dependencies, using:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>

    <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <executions>
            <execution>
            <phase>package</phase>
            <goals>
            <goal>single</goal>
            </goals>
            </execution>
        </executions>
        </configuration>
    </plugin>

Now, i have to include few shell scripts and generated jar to a tar. To achieve this, i ve tried the following way: Added

 <descriptors>
    <descriptor>hadoop-job.xml</descriptor>
 </descriptors>

to the above script.

In hadoop-job.xml i'm including required files into tar.

The problem is tar is generated first and says no *.jar found in target. Is there a way to schedule jar creation first and tar next, since both the configurations reside in assembly plugin. OR Is there a command to execute and generate a jar first and then a command to generate a tar ?

By the way i'm executing mvn clean assembly:assembly -Dbinary=true. Help me to resolve. Thanks.

Fabien

Here is an example of assembly building the jar-with-dependencies and after that a tar that includes this jar-with-dependencies (built by the maven-assembly-plugin just before). In the tar I also includes the shell script files in .sh from the folder src/main/bin.

First, the plugin configuration :

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.3</version>
    <executions>
        <execution>
            <id>jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptorRefs>
                    <descriptorId>jar-with-dependencies</descriptorId>
                </descriptorRefs>
            </configuration>
        </execution>
        <execution>
            <id>all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/all.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <outputDirectory>${project.build.directory}/assembly/</outputDirectory>
    </configuration>
</plugin>

The order of the executions is important because if I want to include the jar-with-dependencies into my tar I need to have it built before.
I put all the assemblies in the same folder, that's why I have a global configuration tag additionally to the configuration tag of the executions

And then the content of my assembly file all.xml :

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>all</id>
    <formats>
        <format>tar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>**/*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/bin</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>755</fileMode>
        </fileSet>
    </fileSets>
</assembly>

The includeBaseDirectory is here to avoid my tar containing the root folder with the name of the project with the version.
If you don't specify the outputDirectory tags, the folder structure into your archive will begin from the root of the project, for example it will include your jar with the path target/your-project-1.0-SNAPSHOT.jar.



EDIT : The plugin configuration that I did before could be simplified with just the following :

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.3</version>
    <executions>
        <execution>
            <id>jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptorId>jar-with-dependencies</descriptorId>
                <descriptors>
                    <descriptor>src/assembly/all.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <outputDirectory>${project.build.directory}/assembly/</outputDirectory>
    </configuration>
</plugin>

The reason is because in the maven-assembly-plugin the descriptorId is read before the descriptors so that's good for our case but if not, we would need two executions as done higher with care about the order. The same attention have to be done for the order of the descriptors, they are performed in the reading order (it can seems logic but I think it might be useful to indicate it).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Maven Create Jar and exclude Files

From Dev

With bazel how to create a tar files with individual jar files

From Dev

With bazel how to create a tar files with individual jar files

From Dev

maven: how to include annotation-generated .java files in the .jar

From Dev

maven: how to include annotation-generated .java files in the .jar

From Dev

maven: create a jar from generated sources and add it as a dependency before compiling

From Dev

karaf-assembly 4.0.5 - zip ard tar.gz files are not generated at the end of a successful maven build

From Dev

Can tar extract jar files

From Dev

Why does Maven + Spring Boot create huge jar-files?

From Dev

How to create .bat files using Maven Appassembler that runs a JAR?

From Dev

Why does Maven + Spring Boot create huge jar-files?

From Dev

How to create .bat files using Maven Appassembler that runs a JAR?

From Dev

How to create tar file with only certain extensions but omitting server generated files with similar extension?

From Dev

Maven assembly -- how to create the project JAR with version included, but the artifact tar.gz file without?

From Dev

Tar Create and Split files into subdir

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Packaging a single jar including few netty jar files?

From Dev

Maven creates empty jar files

From Dev

Specifying specific jar files with maven

From Dev

Create JAR with one file in Maven

From Dev

Create jar file from maven

From Dev

Create JAR with one file in Maven

From Dev

Location of generated source files for maven directory structure

From Dev

Maven and JavaDoc: install additional (generated) files

From Dev

JOOQ Maven plugin - encoding of generated source files

From Dev

How does tar read files to create an archive?

From Dev

Create tar archive of a directory, except for hidden files?

From Dev

create a .tar file of all latest files in the directories

From Dev

Create, as a regular user, a tar with files owned by root

Related Related

  1. 1

    Maven Create Jar and exclude Files

  2. 2

    With bazel how to create a tar files with individual jar files

  3. 3

    With bazel how to create a tar files with individual jar files

  4. 4

    maven: how to include annotation-generated .java files in the .jar

  5. 5

    maven: how to include annotation-generated .java files in the .jar

  6. 6

    maven: create a jar from generated sources and add it as a dependency before compiling

  7. 7

    karaf-assembly 4.0.5 - zip ard tar.gz files are not generated at the end of a successful maven build

  8. 8

    Can tar extract jar files

  9. 9

    Why does Maven + Spring Boot create huge jar-files?

  10. 10

    How to create .bat files using Maven Appassembler that runs a JAR?

  11. 11

    Why does Maven + Spring Boot create huge jar-files?

  12. 12

    How to create .bat files using Maven Appassembler that runs a JAR?

  13. 13

    How to create tar file with only certain extensions but omitting server generated files with similar extension?

  14. 14

    Maven assembly -- how to create the project JAR with version included, but the artifact tar.gz file without?

  15. 15

    Tar Create and Split files into subdir

  16. 16

    Maven - How to exclude dependencies from generated JAR

  17. 17

    Packaging a single jar including few netty jar files?

  18. 18

    Maven creates empty jar files

  19. 19

    Specifying specific jar files with maven

  20. 20

    Create JAR with one file in Maven

  21. 21

    Create jar file from maven

  22. 22

    Create JAR with one file in Maven

  23. 23

    Location of generated source files for maven directory structure

  24. 24

    Maven and JavaDoc: install additional (generated) files

  25. 25

    JOOQ Maven plugin - encoding of generated source files

  26. 26

    How does tar read files to create an archive?

  27. 27

    Create tar archive of a directory, except for hidden files?

  28. 28

    create a .tar file of all latest files in the directories

  29. 29

    Create, as a regular user, a tar with files owned by root

HotTag

Archive