Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate jardesc content into jar-command

Tags:

java

eclipse

jar

I am making some WebFilters for our WebLogic server and I've got everything up and running.

The problem is how I package the filters into jar-files. If I use the following jardesc-file and create the jar-file from Eclipse, everything is working fine and WebLogic has no problems loading the webfilter class. But as soon as I try to manually create the jar-file using just jar.exe I am hitting ClassNotFoundExceptions when loading the webcontainer in WebLogic.

Working jardesc-file:

<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
    <jar path="C:/Workspace/Java/Jars/jars/corsfilter.jar"/>
    <options buildIfNeeded="true" compress="true" descriptionLocation="/CorsFilter/corsfilter.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
    <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
    <selectedProjects/>
    <manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
        <sealing sealJar="false">
            <packagesToSeal/>
            <packagesToUnSeal/>
        </sealing>
    </manifest>
    <selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
        <file path="/CorsFilter/.project"/>
        <file path="/CorsFilter/.classpath"/>
        <javaElement handleIdentifier="=CorsFilter/src"/>
    </selectedElements>
</jardesc>

Current jar-command:

jar -cvf corsfilter.jar .project .classpath -C .\bin dk\akait\filters\cors\CorsFilter.class

The jar-command creates a jar-file that seems to be equivalent to the one generated using the jardesc-file in Eclipse, except for what looks like some kind of symbolic link to the META-INF-folder in the root of the jar-file.

Content of working jar-file: Working jar-file

Content of non-working jar-file enter image description here

Can anyone explain what the right command for executing jar.exe is, given the jardesc-file?

Or

Can anyone explain what the META-INF file in the not working jar-file is?

Updated with output of jar-command run using jdk-1.8.0_111 Output of jar-command

like image 584
Falle1234 Avatar asked Jan 18 '17 08:01

Falle1234


1 Answers

As already mentioned in the comments. I would think this is more like a problem with WinRar as with the actually created jar-file. Probably eclipse doesn't use the jar command internally to create jar-files based on the jardesc descriptions. And the jar-files differ somehow in their internal structure.

However I'd suggest not to rely on the eclipse output, if you want to create a jar-file that you are going to distribute somewhere. I personally like gradle a lot and it is pretty easy to use.

Simply create a build.gradle file in you project root directory with the following content:

apply plugin: 'java'

// this is only needed, if you want to include the single file only
// by default all compiled files will be added to the output jar
jar {
  include "dk/akait/filters/cors/CorsFilter.class"
}

task wrapper(type: Wrapper) {
  gradleVersion = '3.3'
}

Run

%PATH_TO_YOUR_GRADLE_BINARIES%/gradle wrapper

This will generate a local wrapper bat file that is used to ensure you are using the desired gradle version.

Run

%PROJECT_ROOT%/gradlew.bat build

and locate the jar-file under

%PROJECT_ROOT%/build/libs

You will however need to follow some conventions and place your java sources under a folder called src/main/java for this to work out-of-the-box. Or follow this documentation to setup different source folders.

like image 115
dpr Avatar answered Nov 09 '22 11:11

dpr