0

I'm using maven-assembly-plugin to create a output jar from my maven project. The relevant protions of my pom.xml look like this:

.
.
.
<dependencies>
    <dependency>
      .
      .
      .
    </dependency>
    .
    .
    .
</dependencies>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        .
        .
        .
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.package.TheApp</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
        .
        .
        .
    </plugins>
</build>
.
.
.

When I run `mvn clean install assembly:single`` the resulting jar file does contain the dependencies, but it does not contain my project files. Running the jar with

java -jar TheApp-0.1.2-SNAPSHOT-jar-with-dependencies.jar

I get the message Error: Could not find or load main class my.package.TheApp. So how can I include my project files? (I thought of setting useProjectArtifact, but according to the maven-assembly-plugin doco this property is by default true.)

halloleo
  • 9,216
  • 13
  • 64
  • 122
  • 2
    Remove the configuration `..` and keep convention over configuration. furthermore bind the plugin to the package phase as documented here: https://maven.apache.org/plugins/maven-assembly-plugin/usage.html#Execution:_Building_an_Assembly and in the end you can use `mvn clean package` ... – khmarbaise Mar 25 '20 at 06:40

1 Answers1

0

By poking around on Stack Overflow I found the solution:

Run mvn clean compile assembly:single instead of mvn clean install assembly:single. :-)

Or even better bind in the pom.xml the assembly to the package phase (thanks @ khmarbaise!):

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  .
  .
  .
  <executions>
    <execution>
      <id>make-assembly</id> <!-- this is used for inheritance merges -->
      <phase>package</phase> <!-- bind to the packaging phase -->
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

and then run mvn clean package (or mvn clean install if you want to).

halloleo
  • 9,216
  • 13
  • 64
  • 122
  • 1
    Bind the plugin to the lifecycle so you can use `mvn clean package` instead add supplemental goal...and `install` is not necessary... – khmarbaise Mar 25 '20 at 06:54