How to set additional Class-Path entries in manifest with onejar Maven plugin?
Asked Answered
B

3

10

Is there a way to add an arbitrary classpath entry to a JAR file manifest using onejar-maven-plugin?

I found the way to configure maven-jar-plugin to do this, but it appears that there is no such option for onejar-maven-plugin.

This is not done to find additional classes (otherwise why use the onejar plugin, right?), but rather to locate a configuration file that must be external to the JAR.

Is there a direct solution or a workaround for this?

Bergman answered 11/6, 2015 at 16:31 Comment(0)
H
5

Is the usage of the one-jar plugin really required? You can achieve the same goal (packaging in one single jar your application AND all the required dependencies, including transitive ones, AND add configuration for Class-Path AND using a more stable/standard plugin) applying the following approach:

  • Configure the Class-Path entry in your application Jar using the Maven Jar Plugin and the approach you mentioned in the question
  • Use the Maven Assembly Plugin to package one single JAR including dependencies, as explained here, in another stackoverflow question/answer.

An example of one-jar executable file (without using the one-jar plugin) could be as following:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <!-- your further configuration here -->
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.sample.MainApp</mainClass>
                        <!-- your further configuration here -->
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

If you need to further play with classpath and Maven, I would suggest to also check this question here on stackoverflow.

Hoxsie answered 8/12, 2015 at 16:3 Comment(0)
W
3

Adding arbitrary manifest entries is possible in 1.4.5:

<plugin>
    <groupId>org.dstovall</groupId>
    <artifactId>onejar-maven-plugin</artifactId>
    <version>1.4.5</version>
    <executions>
        <execution>
            <configuration>
                <manifestEntries>
                    <Build-Status>Yes</Build-Status>
                </manifestEntries>
            </configuration>
            <goals>
                <goal>one-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The onejar-maven-plugin project doesn't seem to be in active development anymore, so you might want to switch to other solutions (e.g. maven-assembly-plugin) eventually.


The plugin is not available on Maven Central. Someone else put up a version of it to Maven Central with a different group ID.

Weigle answered 8/12, 2015 at 16:20 Comment(0)
R
0

Additional libraries can be added to the classpath at the time of launch. The property one-jar.class.path can be used

one-jar.class.path
Extra classpaths to be added to the execution environment. Use platform independent path separator '|'

Example: --one-jar.class.path="./lib/two.jar|/opt/lib/three.jar"

Source: http://one-jar.sourceforge.net/index.php?page=details

Rodas answered 15/12, 2015 at 5:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.