Jar creation for java stand alone application using ant
Introduction to the ant:
Here is the Demo for Creating the jar file with external libraries using ant
- Ant means another neat tool.
- It is a Java-based build tool from Apache Software Foundation.
- Ant file is written in XML file .when run the ant its search for the build.xml file.
- It is used to automate the build and deployment process.
- It basically compiles the code, package the code deploying the binaries into the server.
Problem with IDE'S:
- For example, the client asked a create a jar for sending an email of user information to one particular person . in this scenario you need to a create sample java standalone application and create a sample java class for send email.
- Send an email using the Gmail SMTP you need to add the external libraries activation.jar and java-mail-1.4.4.jar after adding the jars and build the project you will ger jar file in dist folder in-case if you are using net-beans.
- By default net-beans not adding the external libraries into the final component(jar), once you extract the jar file.
Here is the ant file, you need to add the file in build.xml before the </project> tag on your project.
<target name="-post-jar"> <property name="store.jar.name" value="Javamail"/> <property name="store.dir" value="dist"/> <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/> <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/> <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip"> <zipgroupfileset dir="dist" includes="*.jar"/> <zipgroupfileset dir="dist/lib" includes="*.jar"/> <manifest> <attribute name="Main-Class" value="${main.class}"/> </manifest> </jar> <zip destfile="${store.jar}"> <zipfileset src="${store.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/> </zip> <delete file="${store.dir}/temp_final.jar"/> </target>
Here is the Demo for Creating the jar file with external libraries using ant
0 Response to "Jar creation for java stand alone application using ant"
Post a Comment