aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes problem in making jar and war based on the 'src' package hierarchy! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "problem in making jar and war based on the Watch "problem in making jar and war based on the New topic
Author

problem in making jar and war based on the 'src' package hierarchy!

yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
hello all,

I have the package hierarchy like this,

src
- com.test.servlets -> contains all the servlet sources (*.java).
- com.test.beans -> contains all the bean sources (*.java).

with 'ant' build tool, i compiled all the files and store the class files in the 'build' folder. Then the build folder will be,

build
- com.test.servlets -> contains all the class files of servlets (*.class).
- com.test.beans -> contains all the class files of beans (*.class).

What i need to do,
I need to fetch the class files from the build folder and bundle the web contents(servlets, jsp, images) in the web archive (.war)
and
I need to bundle the beans(core business classes and interfaces) in generic archive (.jar).

[Note: In both archives, the package hierarchy should be the same (in the above) ]

How it can be done?


Thank You!

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Yuvaraj,
What do you have so far? What problem are you running into?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
hello sir,

problem means, In what way i can write an Ant Task to build the war and jar from the 'build'(which has the compiled class files) folder. that is,


build
---------- servlet classes --------> to war
---------- bean classes --------> to jar.

I think it might be clear!

Thank You for your Reply
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

Jeanne was asking you to post the Ant tasks that you have so far to build your WAR and JAR (see NotACodeMill). And asking you to say why those tasks were not behaving as you expected.


JBoss In Action
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Peter: Right.

Yuvaraj: Note that Jeanne is a female name.
yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
hello sir/madam,






My code here is,



here i need to bundle the bean classes only into the jar file!



sorry if i pasted a long code here!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

What have you tried for line 50? Hint: make use of the "includes" and/or "excludes" properties to select only the "com.testbean.beans" classes.

And now for another hint:
By the way, you should also change line 31 to only copy the com.testbean.servlets classes to the WAR:



You might have to try different "includes" settings, the one I gave should work but I didn't try it out so I cannot guarantee it.
yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
hello peter,
Already I have tried the thing you have mentioned!

If we use, includes='com/testbean/servlets/**/*.class' -> It will fetch the class files from the given path (not the entire package hierarchy i think) and will store them in the war.

But, for example,

if i include the war file(we have created in the previous step) in my application, can i use like,

import com.testbean.servlets.TestServlet;

(this statement might show some error about the path(com.testbean.servlets) we have specified)


Thank You for your reply peter!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5772
    
    7

If we use, includes='com/testbean/servlets/**/*.class' -> It will fetch the class files from the given path (not the entire package hierarchy i think) and will store them in the war.

I disagree.

My simple build.xml file:


My file structure:


The ant run:


The contents of the two JAR files:


I assume that this is what you wanted to do.
yuvaraj KumarAmudhan
Ranch Hand

Joined: Aug 22, 2009
Posts: 110
Yes! This one! I'll try this.


Thank You Peter and All!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in making jar and war based on the 'src' package hierarchy!
 
Similar Threads
Tomcat unable to find servlet in Shared linux java hosting Server
we can deploy a folder instead of jar or war what is the difference
diff between jar, ear and war files in detail
Ant Build Failing -- Need a way to pick jar file during run time.
Diff. Btwn EAR, WAR, & JAR Files????