Intellij fat one jar artifact does not generate a working output - java

Intellij fat one jar artifact does not generate a working output. Below you can see my settings and project structure(left). When i click build artifact and then the generated output, nothing happens.

mssql-jdbc-6.2.0.jre8.jar has the digital signature (MSFTSIG.RSA and MSFTSIG.SF files). When the jar is repackaged, the signature becomes broken. If you remove these files from the jar (either original one or the artifact), it should start fine.
Vote for this issue to get it addressed in the future updates.

I just opened generated jar file with winrar. And deleted SIGNINGC.SF file in META-INF folder

Related

Gradle do not use the updated file from an extracted archive

I have a multi-module project that goes as follow server-core -> server-game
The server-core module bundle an app.properties file which I would like to override certain values when I build the server-game's executable jar.
To do so, I added an eachFile closure on the jar task to update the file content while building the jar but it turns out when editing the file using the ant.propertyfile task, it won't appear edited in the resulting jar:
I tried with another property file named app2.properties which is located inside the server-game resource folder and this one get updated in the final jar. More confusing when I check the app.properties file in the gradle tmp folder used to build the final jar it is properly edited.
Also if I filter the files content it will be reflected properly on the final jar for both files.
It seems that files extracted from another archive are simply ignored. If it is the case I wonder why do gradle bothers extracting them in the first place ?
Any idea of what could be wrong here ?
Edit: I created a small github project that reproduce the issue. It is available here.
Run the fatJar task and you will see in its output that only the app2.properties is updated in the resulting jar even though the app.properties has been updated in the tmp folder it has been extracted to during the build process.

How do I create a runnable JAR in IntelliJ as I would in Eclipse

My process for creating a runnable JAR from a project with many libraries with Eclipse has been.
Export > Runnable JAR > Select launch configuration > Package required libraries into generated JAR > Finish
This creates a single JAR in my export destination which I FTP to my server and run fine.
I recently switched to IntelliJ for various reasons and it has been an improvement in all cases except for building my JARs which forces me to go back to eclipse temporarily.
With IntelliJ I:
Open Project Structure > Artifacts and create a new JAR from modules with dependencies. I then have my output layout with the name of the JAR, a META-INF inside it and all my libaries with the format Extracted <lib.jar/> (sorry I can't upload screenshots on this VPN.)
I build my artifact (which is about 15MB bigger) and FTP it to my server, try to run it and I get the error:
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
How do I mimic how I do it in Eclipse?
EDIT
The two JARs that are created differ considerably:
The valid jar that Eclipse creates looks like this:
Whereas the invalid .JAR looks like this:
You're facing two issues one seems major and one is minor:
Major: signature exception
Minor: size of the jar is 15 MB greater than the jar produced by eclipse.
The solution of both of the issues lies in the way you are building the artifact. First of all, remove all extracted *.jar then add all the jar's from the available elements pan as shown in the figure.
It is obvious that adding packaged(compressed) jars only, will decrease the size. But it also solves the signing issue. For more explanation, please have a look at this article. I'll only quote one line.
It's probably best to keep the official jar as is and just add it as a
dependency in the manifest file......
It seems that some of the dependencies are signed and repackaging messes up the META-INF of your project.
If you are using Maven you need to put META-INF directory under /main/resources folder instead of main/java.
Reference: Intellij - Nikolay Chashnikov
Then you can execute the runnable jar normally with java -jar filename.jar
You can these steps:
1) File -> Project Structure -> Project Settings -> Artifacts -> Jar -> From modules with dependencies
2) Check the Include in project build checkbox.
3) Right mouse click on module -> build module 'ModuleName'
you could try using a gradle script. eclipse will make you a gradle project. you can use that build file with any ide. it has a built in jar task.

netbeans not generating classes when build is issues, but the program runs when compiling

So I have been using netbeans and successfully was able to do generate jar file in the dist folder ( using clean & build).
Now suddenly this does not work. It generates a jar file that does not run. Upon inspection, I found that the jar file does not have classes in it ( only folder structure). I also noticed that the build folder does not have classes.
However, when I run it by clicking the green arrow, it runs and the build folder has classes. When I do Clean/build to generate the jar file in the dist folder, then the build folder resorts to empty classes and empty jar file.
Any idea? I restarted netbeans, did a refresh and all that but no luck
Please help
I found the solution for many people running into this issue. It is the missing eclipseLink Library

Project Utility Jar is not being added while generating EAR

I am using eclipse to build the EAR of my project. So I have various module and several utility jar in my application deployment descriptor(refer fig 1). Now my problem is when I am trying to export the EAR using eclipse, the EAR file is properly containing the content of Module but Project utility jar is not being exported(look at the size of jar file in ear which is 181 bytes ). Could you please suggest me how can I achieve that.What do I need to modified so that utility jar exported properly
Finally I have found the answer to my question after head crunching research. The problem with my application was the corrupted value in the "org.eclipse.wst.common.component" file. Which can be found in the .setting folder of you project. The above mentioned file had the duplicate entry for the same project. So default process was getting confused which path to include. I have manually removed the duplicate entry and the issue resolved.
Modify the MANIFEST.MF file of the EAR project to add the utility JARs

pimp up a plain jar to be a maven jar with internal pom.xml for Artifactory

I need to use a xyz.jar wich was generated with ant. Hence, the transitive dependencies are missing. So I had the idea, to modify the xyz.jar to add the internal META-INF/maven/groupId/artifactId/pom.xml and pom.properties files.
When I deployed it to Artifactory, it ignored them and generated it's own pom.xml without dependencies.
What has one to do, Artifactory deploys the pom.xml lying about in the same folder as the xyz.jar file?
Lost way too much time on this allready...
Chances are that Artifactory skips the deployment of the internal POM because it cannot read the POM's physical size from the archive (done for historical reasons); You can verify this by looking at the log for a warning message along the lines of:
"Found pom.xml file with size -1 inside the zip. Ignoring"
If you've already gone to the lengths of creating a customized POM file, you can paste it's contents in the POM content editor of the artifact deployer or deploy it independently; though the first option will give you the benefit of auto detecting the deployment coordinates for the JAR file.
It might be a better idea to add it's dependencies to your pom instead of rigging a third-party library to use maven.
That being said, make sure your pom.xml is valid XML (most modern IDEs can validate xml for you) and make sure your properties file includes version, group id, and artifact id.
Artifactory has changed the way that it handles POM generation in different versions, so, depending on your version, you may have some sort of generate pom option that you have to turn off on deploy. I think they have a deploy time pom editor or something like that in the newer versions.
modify the ant that create an xyz.jar to produce runnable jar - the jar should have all its deppendencies packaged inside.(create a lib directory in your xyz project and put all the jars xyz deppends on inside this directory, then export your project to jar with all the libraries packaged inside)
good step-by-step example how to create an ant script can be found here.
good luck!

Categories

Resources