Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a maven assembly that includes shell scripts and properrties file not in jar?

Tags:

java

maven

build

Im trying to use Maven to build a standalone application

Using the assembly plugin described at How do you create a standalone application with dependencies intact using Maven?

This creates widget distribution zip containing

widget-1.0
widget-1.0/lib/widget.jar
widget-1.0/lib/3rdpartyjar1.jar
widget-1.0/lib/3rdpartyjar2.jar

...

but in my src tree I have:

src/main/bin/widget.sh 

and this doesnt make into the final distribution zip, I would like it to go here

widget-1.0/widget.sh

Also in my src tree i have a properties file in

src/main/properties/widget.properties

that currently make its way into

widget-1.0/lib/widget.jar

but because I want it to be editable I want it to be in

widget-1.0/widget.properties

Is it possible to do this within maven ?

EDIT Using information in blog got working as follows:

  1. Renamed bin folder to scripts folder because this is standard Maven name
  2. Moved widget.properties into script folder
  3. Modifed my assembly.xml to contain a fileset

Here is the new xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>
    <dependencySets>
        <dependencySet>
            <scope>runtime</scope>
            <outputDirectory>lib</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.build.scriptSourceDirectory}</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>widget.sh</include>
                <include>widget.properties</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

However minor point but unable to find a list of maven standard folder variables anywhere , i.e is there an equivalent to ${project.build.scriptSourceDirectory} for the properties folder

like image 945
Paul Taylor Avatar asked Jul 24 '12 13:07

Paul Taylor


People also ask

What is an assembly maven?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.

What is fileset in maven?

Defines the rules for matching and working with files in a given base directory. Element.

Does jar file contain dependencies?

Normally, when we package a project into a jarW file, the jar file doesn't contain its dependencies, so the dependency jar files would need to be included in the classpathW in order to execute a class in the project's jar file that uses one of the dependencies.


1 Answers

I found this blog post to be a good tutorial on how to do this.

Also, I think the name of the folder in which you place your files is relevant. Maven obviously does different things with files in src/main/java than with files in src/main/resources. I'm not 100% sure, but the name of this folder might mean the difference between a file ending up inside the jar or not.

Here is a list of Maven directory name properties.

like image 70
jqno Avatar answered Oct 18 '22 01:10

jqno