15

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

Community
  • 1
  • 1
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351

1 Answers1

17

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.

jqno
  • 15,133
  • 7
  • 57
  • 84
  • thanks looks like a great blog, I'll work through it and see if it solves my problem. Actualy my question was incorrect i store widget.sh in a bin folder, amended question to inidcate this. – Paul Taylor Jul 24 '12 at 13:44
  • @PaulTaylor I've edited my answer to reflect your edit in the question. Good luck :)! – jqno Jul 24 '12 at 14:05
  • @PaulTaylor Cool! I also found you a list of directory variables, BTW, to answer the last part of your question. – jqno Jul 24 '12 at 14:26
  • 1
    thanks doen;t seem to be a properties varaibles but found could use with ${basedir} instead i.e ${basedir}/src/main/properties – Paul Taylor Jul 24 '12 at 15:29
  • In case anyone is looking for the resources directory (broken link): ${project.build.sourceDirectory} – Miguel Jiménez Apr 04 '17 at 17:22
  • The Maven directory name properties [link](https://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-properties.html) is broken in @jqno s answer. [This](https://cwiki.apache.org/confluence/display/MAVEN/Maven+Properties+Guide) maybe a replacement, please correct as necessary. – Deer Womb May 03 '17 at 21:17
  • 1
    @DeerWomb Thanks for letting me know about this. I managed to find the new location of the original page I linked to, although yours indeed contains the same information. I updated my answer accordingly. – jqno May 04 '17 at 07:22