Apache Ant Build, jar with external librarys - ant

i have a Apache Ant build.xml to create a simple executeable jar file, but this file is very big.
Now i have the idea to build a executeable jar file with my code and have a directory named "lib" with all external jar files.
I think this will reduce the size of my application to 3%.
Thanks for your help.

Related

Why does GRADLE uploads the wrong JAR file of my Grails application to MAVEN repository?

I haven an Grails 3.1.8 application and building an executable jar file, which runs fine. Now I wanna upload the produced jar file to my maven repository by using the gradle maven plugin. Here the problem begins. The upload tasks uploads the wrong JAR file.
If I execute 'grails assemble' two files get produced:
100032 mcc-1.0.9.jar
4880 mcc-1.0.9.jar.original
As you can see, the first file having the bigger size is obviously the fat jar file, which works fine. After the assemble task the 'upload' task is executed and uploads the smaller file. I tried also to define the artifact:
artifacts {
archives file: file("build/libs/mcc-1.0.9.jar")
}
Then the fat jar get overwritten or is not produced at all:
4880 mcc-1.0.9.jar
4880 mcc-1.0.9.jar.original
and the small JAR gets uploaded again. How can I force gradle to take the fat jar file or at least produce only the correct file?
Thanks to Hubert Klein who answered my question in the comment section of this article: https://dzone.com/articles/grails-goodness-creating-a-fully-executable-jar.
This happens because the uploadArchives task depends on the jar task by default. But then the bootRepackage task is not executed, that actually overwrites the jar file with the full executable jar file.
If you add to your build.gradle file that the task uploadArchives depends on the assemble task the bootRepackage task is invoked before uploadArchives:
uploadArchives.dependsOn(assemble)
I had the same issue
gradle clean build assemble artifactoryPublish

Maven Assembly Plugin and Executable jar

I'm able to successfully build the Maven assembly plugin in my project and generate a jar file with all the needed dependencies. But now I also want to instruct Maven after building me the jar file with dependencies, go into the target folder where the jar file with dependencies is located and run my main program.
Should I consider looking into the Maven Exec Plugin for what I want to acheive?
Yes the exec-maven-plugin is the right choice. The question is if you like to start the assembled jar archive or just a java class with it's dependencies.

How to build exploded jars using Ant task?

Kindly suggest how to build exploded jars using Ant task?
Thanks.
An exploded jar is simply a directory which has the same structure as a jar file. Just use copy, for example, to put all the files you want in this directory.

How should the log4j.properties put inside the war file using ANT build tool?

I have a log4j.properties that sit right under the src folder. When I building my war file using ANT tool, the particular properties file wasn't pack inside WEB-INF/classes folder, and it was right under the "root" directory of the war file (if you unwar it). I heard from my colleague mention that this is not correct. May I know is this true? If no, how should I correct it?
THanks #!
Yes, log4j.properties (or any other resource loaded from the classpath) should be at the root of your Java source folder (src/main/java, build/main, src, JavaSource, or however you have your project configured).
In the WAR, it should be under WEB-INF/classes, not at the root (as if you unzipped it).
If this is not the case, being able to see your ANT build file would be very helpful. You should have something like this line configured within your war task:
<classes dir="build/main"/>
As long as you have a build/main/log4j.properties in your Ant basedir, this should work as you're expecting.

Separate same jars in different WAR of a EAR

currently we are facing one problem. We are building a ear which contains multiple war files. In 2 of the WARs contains same jars. Both these wars need these jars during deployment.So Is there any way in ANT I can built it so that these jars will be in one single place and it will not create any problem during the ear deployment.
well, you can do it the portable way:
Place the library jars at the root of .ear file.
Example:
library jar -> lib1.jar, lib2.jar
[EAR STRUCTURE]
your.ear
|--yourfirst.war
|--yoursecond.war
|--lib1.jar
|--lib2.jar
Update the MANIFEST.MF files in both the .war files to point to these jars
like so:
Class-Path: lib1.jar lib2.jar
(dont forget to add a space and a newline character to the end of the above line if this is the last entry in the manifest)
You can put those shared JARs into the EAR's lib directory. Those will then be available on the classpath for any WARs in that EAR.

Resources