March 23, 2009

how to create different project jar file and exclude some files or folders

In java projects sometimes we need setup dependencies among modules by sharing code via JAR files. In some cases its required that the some module for ex module_a is a dependency for two other modules, lets say module_b and module_c. module_b requires all the code in module_a except for the files in package /org/, similarly module_c requires all files/classes in module_a except in package /net/

Here is the sample ANT code to do that

Following ANT target creates a trimmed version of module_a classes, by excluding the org folder

<target name="make-jar-for-module-b" depends="compile-classes ,clean-jars">
<jar index="yes" jarfile="${}/module_a_for_b.jar" compress="true">
<fileset dir="${}">
<exclude name="**/org/**" />

Following ANT target creates a trimmed version of module_a classes, by excluding the net folder

<target name="make-jar-for-module-c" depends="compile-classes ,clean-jars">
<jar index="yes" jarfile="${}/module_a_for_c.jar" compress="true">
<fileset dir="${}">
<exclude name="**/net/**" />

Here we assume that you are already done with ANT targets for compiling classes and cleaning the jar folders.

On executing these targets you will get the required dependency jars by name module_a_for_c.jar and module_a_for_b.jar

How do I know if I have Sun Java Development Kit installed?

It normally happens that we need to check if JDK is installed on our system.

You can check it in a couple of ways as explained below:

For Windows:
  • If you are on windows and the kit was installed using the standard JDK installer you can find it in "Control Panel > Add Remove Programs".
  • Also check for directories in the windows installation drive. I am assuming its C:. The location can be C:\jdk.....<version>or c:\program files\java\<java version> this folder can also contain JRE, so check the folder name, if its prefixed/suffixed with jre, then its not the right one.
  • Other option is to see if environment var JAVA_HOME is set. For this just hit echo %JAVA_HOME% on command prompt. This will tell you the Java install dir.
  • In case nothing was found on JAVA_HOME var, you can also echo %PATH% variable to see, if its having java in it i.e. PATH variable points to the java bin folder having executables like java, javac, jar. So in case you find any thing on it. This will take you to java install dir.
  • If you have not installed using installer i.e. you have unzipped it. Then simplest is to do file search for java, javac etc. The folder holding these files will point you either to JRE or JDK
For Linux
  • If installed using some installer or linux tool like apt-get or yum then hit on shell $ whereis java it should show you available folders having java installed. for ex  /usr/bin/java /etc/java /usr/share/java
  • other wise just do a file search for javac, it should help like windows.