1

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:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>

                <archive>
                    <manifest>
                        <mainClass>com.main.whatever</mainClass>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>   

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.

Thanks!

Edit: So I seem to have achieved what I was trying to do by using this approach:

            <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.jasonwjones.hyperion.jessub.Jessub</mainClass>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>

                        <!-- this creates a warning during the Maven package, which I don't
                             love -->
                        <appendAssemblyId>false</appendAssemblyId>

                    </configuration>
                </execution>
                <execution>
                    <id>dist</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/dist.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

And then a simply assembly:

<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
    <source>target/${project.artifactId}-${project.version}.jar</source>
  <!-- <source>target/${project.artifactId}-${project.version}-jar-with-dependencies.jar</source> -->
  <outputDirectory>/</outputDirectory>
</file>
</files>
<fileSets>
<fileSet>
  <directory>${project.basedir}</directory>
  <includes>
    <include>*.txt</include>
  </includes>
 <outputDirectory>/</outputDirectory> 
</fileSet>
<fileSet>
    <directory>${project.basedir}/src/main/resources</directory>
    <includes>
        <include>*</include>
    </includes>
    <outputDirectory>/</outputDirectory> 

</fileSet>

jwj
  • 528
  • 3
  • 13
  • Can you add the content of you assembly xml? You are also missing the reference to the assembly xml in your plugin declaration. I have done what you are trying to do in the past just fine. You have the phase (package) defined correctly as well. – CoolBeans Dec 01 '11 at 22:44
  • Please do post your solution as an answer, rather an edit. – Angelo Fuchs Apr 30 '14 at 12:57
  • https://stackoverflow.com/questions/35217128/is-it-possible-to-build-a-java-project-only-once-using-eclipse-and-share/35359756#35359756 – Thanga Sep 11 '17 at 08:14

1 Answers1

2

Create another module that depends on the current one that does the assembly of the executable jar and the rest of the stuff. Remember the Maven mantra .. one output artifact per module ;-)

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • I am still fuzzy on how modules work (I need to go read up on them)... but I did get it to work by using another approach, which I'll post in the original comment to get your thoughts. I'm not sure if the way I'm doing it is Maveny or not... – jwj Dec 02 '11 at 06:11
  • A module is just another maven project (separate folder and pom.xml) and it will in your case have a dependency on the runnable jar. – Manfred Moser Dec 02 '11 at 08:15