0

Our legacy Ant build uses prebuilt Eclipse loader classes in a zip file. How can I add these to a executable JAR file with the maven-jar-plugin?

This is my current plugin config:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</mainClass>
            </manifest>
            <manifestEntries>
                <Rsrc-Main-Class>com.xyz.GuiMain</Rsrc-Main-Class>
                <Class-Path>.</Class-Path>
                <Rsrc-Class-Path>./ commons-net-3.6.jar commons-io-2.6.jar</Rsrc-Class-Path>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

I previously had the resources tag after the archive tag, but that did not work either. I believe we also have a constraint right now where our CodeMeter.jar needs to be embedded as a JAR within the executable JAR hence our use of the jar-in-jar-loarder.zip classes from Eclipse. When I had extracted all the jar class contents so they were directly in the executable JAR, we were running into JNI binding issues.

I also have the maven-assembly-plugin defined, but I'm not sure if it is required or doing anything:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>single</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Rsrc-Main-Class>com.xyz.GuiMain</Rsrc-Main-Class>
                        <Class-Path>.</Class-Path>
                        <Rsrc-Class-Path>./ commons-net-3.6.jar commons-io-2.6.jar CodeMeter.jar</Rsrc-Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

It was previously done like this in Ant:

<target name="create_cli_jar" depends="clean,init,compile,build_properties" description="Build and package xyz command line utility">
    <jar destfile="${dist.dir}/${cli.prefix}.jar">
        <manifest>
            <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
            <attribute name="Rsrc-Main-Class" value="com.xyz.GuiMain"/>
            <attribute name="Class-Path" value="."/>
            <attribute name="Rsrc-Class-Path" value="./ commons-net-3.6.jar commons-io-2.6.jar"/>
        </manifest>
        <fileset dir="${dist.dir}" includes="build.properties" />
        <fileset dir="${classes.dir}"/>
        <zipfileset src="lib/jar-in-jar-loader.zip"/>
        <zipfileset dir="lib" includes="commons-net-3.6.jar"/>
        <zipfileset dir="lib" includes="commons-io-2.6.jar"/>
        <zipfileset dir="lib" includes="CodeMeter.jar"/>
    </jar>
</target>
4
  • You just need to use Maven Shade or the Maven Assembly plugin. The commons classes would be just regular dependencies. If you post simple source using all those dependencies, someone could probably help you with the config Commented Jan 27 at 18:32
  • @g00se I believe right now we have this dependency that needs to remain as a signed jar and what it looked like when I was using the shade plugin is it was extracting the contents of the jar witch would break the library. Basically we are using the CodeMeter.jar 8.20 library from the vendor and it does not like being tampered with. The above ant build.xml excerpt could keep the commons and code meter.jars intact as an embedded jar within the executable jar. I'll update the description to reflect the codemeter jar constraint. Commented Jan 27 at 19:39
  • @g00se When you say post simple source can you expand on that? Like how we use it in the java code? Commented Jan 27 at 19:43
  • Ah ok. I didn't know there were signed jars involved Commented Jan 27 at 20:02

1 Answer 1

0

I had switched over to the assembly plugin which handles this basic thing and the config i used is captured in my answer here.

Specifically adding this section includes a directory's contents if it has been extracted:

  <fileSets>
    <fileSet>
        <directory>${project.build.directory}/loader-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
        <include>**/*</include> 
        </includes>
    </fileSet>
  </fileSets>

Of course it would be nice to know how to do this directly from a zip so not marking this as the ideal answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.