Separate same jars in different WAR of a EAR - ant

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.

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

Create war without manifest

I need to create a war file through ant build without a manifest file. I want the war to me created without the manifest file.
I am using tag in build.xml to create the war.
you can use <zip/> task with .war extension for destfile attribute to achieve the same result as the <war/> task (without manifest.mf).
<zip destfile="..\...\WarFile.war"basedir="..\basedir" update="true"/>
in case WarFile.war already exists, although you've written I need to create a war file , the attribute update="true" will be of use (by only updating and not overwriting the file).
All a war file is is a zip file in a specific format. That is libraries go in a particular place, class files go elsewhere, etc. The <war> task has sub-entities like <classes/> and <lib> that make configuring a war file correctly without knowing exactly where everything has to go.
However, you can correctly format the war yourself, and use <zip/>.
Why don't you want a manifest file? A manifest, if you don't specify anything, will contain nothing but the Java version used for the build, and the Ant version and won't affect the execution of your war at all.
What you can do is put useful information into the manifest. For example, we use Jenkins for our builds, and we put in the Jenkins project name and the build number which helps us understand what was included in the war.
There's no reason not to use a manifest file. And, a manifest file can contain useful information (which is accessible to the Java program too).

Apache Ant Build, jar with external librarys

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.

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.

Resources