I'm generating a jar file with following assembly file:
<assembly>
<id>job</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>${groupId}:${artifactId}</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory></outputDirectory>
<unpack>true</unpack>
<includes>
<include>${groupId}:${artifactId}</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
I tried add the following to the above as extension and changed format field to tar from jar. It just created a tar instead of jar, which is of no use.
<files>
<file>
<source>${project.basedir}/runConcept.sh</source>
<outputDirectory></outputDirectory>
<filtered>true</filtered>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</file>
</files>
How do i prepare a tar file with jar and shell scripts. So when i untar, it should have a jar and shell scripts.
If I understand well, you want to create a tar that will have a script runConcept.sh with the jar of your project at the root, and this jar would contain its dependencies your project code and its dependencies in a lib folder.
The problem that I see (I think) is that when you will want to execute your main jar, the classloader will not be able to find the libraries inside your jar and then will not be able to execute it.
But if you still want to try it this way, this is what I would do. (you can find other solutions after)
Solution number 1...
Make a first execution of the maven-assembly-plugin
with an assembly file copied from the jar-with-dependencies
assembly of the plugin with the property unpack
set to false and the outputDirectory
set to where I want, like :
<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>jar-with-dependencies-packed</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Make a second execution of the maven-assembly-plugin
that will be executed after the previous one (otherwise we won't be able to include the jar ^^) in which you just have to include your script and the jar
<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>job</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>src/main/scripts/runConcept.sh</source>
<outputDirectory></outputDirectory>
<filtered>true</filtered>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
</file>
</files>
<fileSets>
<fileSet>
<directory>${project.build.directory}/assembly-test/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Solution number 2...
As I think that solution number 1 might not work, I would create a classical jar-with-dependencies that I would include in the tar with scripts.
Solution number 3...
Because you want it, there is a maven plugin called One-JAR
that could handle the build of your jar with jars inside, and then run the assembly to build your tar.
See there : http://one-jar.sourceforge.net/