Creating SAR file with Ant - ant

I am reworking a build, and notice that the ear file contains a Service archive file (sar). I'd like to build the sar file in Ant. I suspect I could probably use the ear or zip task to do this, and simply name the file as *.sar. However, I want to be sure that this will work.
What task would I use in Ant to create a SAR file?

It seems you should use the standard JAR task in ANT. According to the JBoss documentation, SAR files contain an extra file:
META-INF/jboss-service.xml
The following "hello world" example has a sample project attached:
https://community.jboss.org/wiki/ExampleHelloWorldService

A sar file is a special kind of jar file (with certain files in WEB-INF, etc.). So you can use the jar task, e.g.:
<jar destfile="${sar.filename}">...</jar>

Related

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 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.

give input to a runnable jar file through a file

I have created a jar file using ant. I want the jar file to take input from a external file.
How can we achieve this?
The java task has an input attribute that specifies the file that should be used as stdin.

Delete generated files when original is modified with Apache Ant

I want to delete the generated files (".tmp" and ".bak") in the build directory when the source file (".xml)" is modified with Apache Ant. All files have the same name, but different extentions.
I'm not able to create the fileset to do this.
You can use a file mapper in place of a fileset.

Resources