Solved

How to write this Ant script?

Posted on 2014-10-14
19
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
19 Comments
 

Author Comment

by:Wendyu66
ID: 40380831
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
ID: 40380833
Actually... I am working on the first part now.
0
 

Author Comment

by:Wendyu66
ID: 40381225
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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 86

Expert Comment

by:CEHJ
ID: 40382035
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
ID: 40383407
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
ID: 40383409
I searched online but I did not find that Ant had an attribute to specify "Host OS".
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40383775
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
ID: 40385006
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
ID: 40385020
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 40385034
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
ID: 40385043
You can but using fileset elements makes the code more flexible and readable
0
 

Author Comment

by:Wendyu66
ID: 40385087
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
ID: 40385129
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
ID: 40385245
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
ID: 40385440
>>> 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
ID: 40385643
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
ID: 40385653
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
ID: 40385657
:)

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

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Make the most of your online learning experience.
Simple Linear Regression
Progress

690 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