Solved

How to write this Ant script?

Posted on 2014-10-14
19
313 Views
Last Modified: 2014-10-16
Hello experts,

I must tell that I am not good at Ant script. This is my first time to work on it. Following is a piece of build script. Can anybody help to convert it to Ant script?
set jdk=C:\jdk1.8.0_20
set meap_sdk=C:\cannon\canon\MEAP_SDK
set meap_login_sdk=C:\cannon\canon\MEAP_Login

%jdk%\bin\javac -d build -classpath %meap_sdk%\MEAP\DistributableSoftware.jar;login.jar;json.jar;%meap_sdk%\MEAP\Environment_on_PC\lib\meap.jar;%meap_sdk%\MEAP\Environment_on_PC\lib\osgi.jar;.-sourcepath src/com/nq/boot/*.java src/com/nq/utilities/*.java src/com/nq/boot/*.java  src/com/nq/nativecanon/fax/*.java -target 1.1 -source 1.2
pause

%jdk%\bin\jar cfm0 Canon_3_Dev.jar META-INF\MANIFEST.MF -C build com bundle.permissions DistributableSoftware.jar .\json.jar .\BC.jar .\image\*.png .\jregex1.2_01.jar .\res\en\*.htm .\res\*.properties

pause

Open in new window

Today is my due date for this script. So please help.
Thanks so much!
0
Comment
Question by:Wendyu66
  • 11
  • 7
19 Comments
 

Author Comment

by:Wendyu66
Comment Utility
I will work on the javac part. Can anybody help me with the 2nd part? That is
%jdk%\bin\jar cfm0 Canon_3_Dev.jar META-INF\MANIFEST.MF -C build com bundle.permissions DistributableSoftware.jar .\json.jar .\BC.jar .\image\*.png .\jregex1.2_01.jar .\res\en\*.htm .\res\*.properties

Open in new window

Thanks so much.
0
 

Author Comment

by:Wendyu66
Comment Utility
Actually... I am working on the first part now.
0
 

Author Comment

by:Wendyu66
Comment Utility
Here is what I have -
	<target name="build-jar" depends="compile">
		<echo> check class dir: "${classes.dir}/boot"  </echo>
	        <jar destfile="${final.jar}" >
	        	
	         	<fileset dir="${classes.dir}/boot"/>
	        	<fileset dir="${classes.dir}/comm/cache"/>
	        	<fileset dir="${classes.dir}/comm/service"/>
	        	        			
	        	<fileset dir="${classes.dir}/configuration"/>
	        	<fileset dir="${classes.dir}/data"/>
	        	
	<manifest>
	        	    <attribute name="Built-By" value="${user.name}"/>
	        	    <section name="common">
	        	      	<attribute name="Manifest-Version" value="${version}"/>
	        	      	<attribute name="Bundle-Vendor" value="nQueue Billback"/>	        	     
	        	      	<attribute name="Bundle-ClassPath" value="DistributableSoftware.jar ./json.jar ./BC.jar ./image/*.png ./jregex1.2_01.jar  ./login.jar ./commons-lang-2.6.jar ./meap.jar"/>
	        	      	<attribute name="Applet-Name" value="Canon_3_Dev"/>
	        	      	<attribute name="Import-Package" value="./res/en/*.htm"/> 
	        	      	<attribute name="Application-Id" value="./res/*.properties"/>
	        	    </section>
	        	    
	        	  </manifest>
	        </jar>
	</target>

Open in new window

============================
Above piece of script runs smoothly and creates a jar file, however the jar file misses a lot of content that is class files. What's wrong with this script?  Can anybody look into it?

Thanks so much.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Here is what I have -
But that's incomplete and therefore useless to post. You are aware it's incomplete? If not, then that's why it doesn't work properly ;)
0
 

Author Comment

by:Wendyu66
Comment Utility
Thanks CEHI for your reply. That was correct. I only posted a part of my ant file.

Now that my ant script works and creates jar file, however I found something that was strange. I developed my ant script and ran it on Eclipse on Windows. With this script I created a jar file. When I used 7-Zip to review its contents, I found that one of the properties of the jar file was "Host OS" and its value was "Unix".  I had expected this value to be "FAT" ("Windows"). Do you know where I can control this value in an ant file?

Thanks
0
 

Author Comment

by:Wendyu66
Comment Utility
I searched online but I did not find that Ant had an attribute to specify "Host OS".
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I found that one of the properties of the jar file was "Host OS" and its value was "Unix".  I had expected this value to be "FAT" ("Windows").
I've never heard of such a property. FAT in any case is a type of file system and only incidentally associated with Windows. Sounds like something you don't need to worry about.
0
 

Author Comment

by:Wendyu66
Comment Utility
Hi CEHI,

 Following is a bat file. How can I include the "bundle.permissioins" and ".\res\*.properties" in my Ant script?
%jdk%\bin\jar cfm0 Canon_3_Dev.jar META-INF\MANIFEST.MF -C build com bundle.permissions DistributableSoftware.jar .\json.jar  .\res\en\*.htm .\res\*.properties

Open in new window


I did following

<jar destfile="${final.jar}" basedir="${build.dir}" compress="false" keepcompression="false">
                     
                     <property file="res\LoginSetting.properties"/>
                     <loadfile property="permissions" srcFile="bundle.permissions"/>
 </jar>

Open in new window


but failed. Any ideas how to this?
0
 

Author Comment

by:Wendyu66
Comment Utility
just found it...   using "includes" seems to

 <jar destfile="${final.jar}" basedir="${build.dir}" compress="false" keepcompression="false" includes="res\LoginSetting.properties;bundle.permissions">

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
You need to use a fileset inside jar. Try

<fileset dir="." includes="bundle.permissions"/>

<fileset dir="." includes="res/**.properties"/>

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You can but using fileset elements makes the code more flexible and readable
0
 

Author Comment

by:Wendyu66
Comment Utility
Yes, that works. Thanks a lot.

Here comes another question. Do you know how the bat command
 
%jdk%\bin\jar cfm0 Canon_3_Dev.jar META-INF\MANIFEST.MF -C build com bundle.permissions DistributableSoftware.jar .\json.jar .\BC.jar .\image\*.png .\jregex1.2_01.jar .\res\en\*.htm .\res\*.properties

Open in new window


works? I mean, how the "bundle.permissions" and ".\res\en\*.htm .\res\*.properties" work here?

What I feel strange is that I can not find files of "bundle.permissions" and ".\res\en\*.htm .\res\*.properties" in the jar file created with this jar bat command.  On the other hand, with "<fileset dir .../>", I can find these files in the jar created with my ant script.

Any ideas why the jar file created with the jar bat command does not have these files?
0
 

Author Comment

by:Wendyu66
Comment Utility
I read this on Oracle's website
 
 
jar cf jar-file input-file(s)
The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file.

Open in new window


but why I could not find those files in the jar file created with the bat command?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Any ideas why the jar file created with the jar bat command does not have these files?
Because it's ... wrong? ;)
0
 

Author Comment

by:Wendyu66
Comment Utility
>>> Because it's ... wrong? ;)

Absolutely! I ran the bat script a moment ago and this time it created those files in the jar file! I do not know why but this is really crazy!
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
a. is this issue with the batch file just of academic interest or is it practical?
b. i hope you're not confusing the batch file's creation of the jar with Ant's when you said the batch file worked ;)
0
 

Author Comment

by:Wendyu66
Comment Utility
to answer your questions -
a. it's practical
b. no, I did not confuse one with the other.

I go to close this thread. I assign the points to you.

Thanks so much for your time!
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)

Actually the command line version looks right to me. Try it after making sure you completely deleted earlier versions
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now