Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Maven to create runnable jar with dependencies and pack that into a zip with other files
    primarykey
    data
    text
    <p>I have looked all over and have seen some similar questions and answers but nothing that seems to line up perfectly with what I am trying to achieve. I am currently able to successfully build a runnable jar with dependencies, which is great. The relevant section of my POM is this:</p> <pre><code> &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt; &lt;version&gt;2.2.1&lt;/version&gt; &lt;configuration&gt; &lt;descriptorRefs&gt; &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt; &lt;/descriptorRefs&gt; &lt;archive&gt; &lt;manifest&gt; &lt;mainClass&gt;com.main.whatever&lt;/mainClass&gt; &lt;addClasspath&gt;true&lt;/addClasspath&gt; &lt;/manifest&gt; &lt;/archive&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;single&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>Now what I want to do is take the runnable jar that's created and put that into a zip file with some other files that are in a directory. I've tried adding another descriptor that points to a XML assembly file that tries to create the zip, but there is a dependency problem where it can't find the JAR file being created in the above step. I can't figure out how to specify for one to run first. I've searched high and low and just can't figure out what the best way to do it is -- there are many answers out there regarding multiple modules, multiple plugin calls, dependency sets, and so on. I'm just looking for the best practice and simplest approach.</p> <p>Thanks!</p> <p>Edit: So I seem to have achieved what I was trying to do by using this approach:</p> <pre><code> &lt;plugin&gt; &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;jar-with-dependencies&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;single&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;descriptorRefs&gt; &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt; &lt;/descriptorRefs&gt; &lt;archive&gt; &lt;manifest&gt; &lt;mainClass&gt;com.jasonwjones.hyperion.jessub.Jessub&lt;/mainClass&gt; &lt;addClasspath&gt;true&lt;/addClasspath&gt; &lt;/manifest&gt; &lt;/archive&gt; &lt;!-- this creates a warning during the Maven package, which I don't love --&gt; &lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;execution&gt; &lt;id&gt;dist&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;single&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;descriptors&gt; &lt;descriptor&gt;src/main/assembly/dist.xml&lt;/descriptor&gt; &lt;/descriptors&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>And then a simply assembly:</p> <pre><code>&lt;assembly&gt; &lt;id&gt;dist&lt;/id&gt; &lt;formats&gt; &lt;format&gt;zip&lt;/format&gt; &lt;/formats&gt; &lt;files&gt; &lt;file&gt; &lt;source&gt;target/${project.artifactId}-${project.version}.jar&lt;/source&gt; &lt;!-- &lt;source&gt;target/${project.artifactId}-${project.version}-jar-with-dependencies.jar&lt;/source&gt; --&gt; &lt;outputDirectory&gt;/&lt;/outputDirectory&gt; &lt;/file&gt; &lt;/files&gt; &lt;fileSets&gt; &lt;fileSet&gt; &lt;directory&gt;${project.basedir}&lt;/directory&gt; &lt;includes&gt; &lt;include&gt;*.txt&lt;/include&gt; &lt;/includes&gt; &lt;outputDirectory&gt;/&lt;/outputDirectory&gt; &lt;/fileSet&gt; &lt;fileSet&gt; &lt;directory&gt;${project.basedir}/src/main/resources&lt;/directory&gt; &lt;includes&gt; &lt;include&gt;*&lt;/include&gt; &lt;/includes&gt; &lt;outputDirectory&gt;/&lt;/outputDirectory&gt; &lt;/fileSet&gt; </code></pre> <p> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload