Eric B.
Eric B.

Reputation: 24411

Deploying a Maven one-jar deploys wrong artifact

I am trying to build a single-jar Java utility. In this previous SO post, someone recommended using the onejar-maven-plugin plugin. I have tried it, but the problem I am encountering is that the plugin (1.4.4) is creates a new artifact with a one-jar.jar extension. Consequently, I end up with 2 jars in my target folder and when I try to install and/or deploy, it deploys the original jar (not the one-jar).

I have run the one-jar.jar artifact from the target folder and it works exactly as expected, so I am quite content with that. However, if I cannot deploy it properly using standard mvn deploy command syntax, the plugin doesn't really perform as expected or as required.

Is there a way to properly structure the pom configuration to avoid this issue?

My current pom reads:

                <plugin>
                    <groupId>com.jolira</groupId>
                    <artifactId>onejar-maven-plugin</artifactId>
                    <version>1.4.4</version>
                    <executions>
                        <execution>
                            <configuration>
                                <mainClass>com.nbfg.cws.cs.lendingsimulationservice.Client</mainClass>
                                <onejarVersion>0.97</onejarVersion>
                                <attachToBuild>true</attachToBuild>
                            </configuration>
                            <goals>
                                <goal>one-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Maven output when running mvn deploy:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ lss-client ---
[INFO]
[INFO] --- onejar-maven-plugin:1.4.4:one-jar (default) @ lss-client ---
[INFO] Using One-Jar to create a single-file distribution
[INFO] Implementation Version: 0.0.1-SNAPSHOT
[INFO] Using One-Jar version: 0.97
[INFO] More info on One-Jar: http://one-jar.sourceforge.net/
[INFO] License for One-Jar:  http://one-jar.sourceforge.net/one-jar-license.txt
[INFO] One-Jar file: C:\Dev\Eclipse Indigo\lssClient\target\lss-client-0.0.1-SNAPSHOT.one-jar.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ lss-client ---
[INFO] Installing C:\Dev\Eclipse Indigo\lssClient\target\lss-client-0.0.1-SNAPSHOT.jar to C:\Users\C61271B4\.m2\repository\com\cws\cs\lss\lss-client\0.0.1-SNAPSHOT\lss-client-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Dev\Eclipse Indigo\lssClient\pom.xml to C:\Users\C61271B4\.m2\repository\com\cws\cs\lss\lss-client\0.0.1-SNAPSHOT\lss-client-0.0.1-SNAPSHOT.pom
[INFO] Installing C:\Dev\Eclipse Indigo\lssClient\target\lss-client-0.0.1-SNAPSHOT.one-jar.jar to C:\Users\C61271B4\.m2\repository\com\cws\cs\lss\lss-client\0.0.1-SNAPSHOT\lss-client-0.0.1-SNAPSHOT-onejar.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.874s
[INFO] Finished at: Tue Jun 26 13:08:34 EDT 2012
[INFO] Final Memory: 21M/512M
[INFO] ------------------------------------------------------------------------

Thanks,

Eric

Upvotes: 3

Views: 2537

Answers (1)

khmarbaise
khmarbaise

Reputation: 97399

Based on the documentation you should add the configuration which exactly should solve you problem to attach the onejar file your build.

<!-- Optional, default is false -->
<attachToBuild>true</attachToBuild>

To use the created artifact you need to add the classifier which is defined by the plugin for the onejar by the option:

<!-- Optional, default is "onejar" -->
<classifier>onejar</classifier>

This means to say:

<dependency>
  <groupId>..</groupId>
  <artifactId>..</artifactId>
  <classifier>onejar</classifier>
  <verison>x.y.z</version>
</dependency>

The important thing is to use classifier. Otherwise you will get the original artifact (as you described).

If you like to have the opportunity to use the generated onejar as the main artifact (only deployed) you should use the maven-shade-plugin for such purposes. The documentation of the onejar plugin does not offer such options.

Upvotes: 6

Related Questions