Ant build.xml ear generation - java

I have a j2ee application. That application is packaged as ear file. Inside that ear file there are two wars. Can anyone guide me that how I create an ear file consisting those war's inside that ear with ant build.xml script.

You can use command line to create EAR using below command:
jar -cvf <<ear file name>> <<war files to be included>>
You can also refer to question how to create ear file, and include war and jar files inside that.
Also, if you want to do it using build.xml, you can refer How do I create an EAR file with an ant build including certain files?
I hope it helps.

Related

Ant War Task: how to specify several folders with class files and libs

I have a Java webservice project. I want to build the War file using Ant War Task. As the project depends on sub projects (non web projects) there are several folders with class files and libs that have to been put in the War.
Is it possible to make the Ant War Task search more than one folder for class files? Same for libs.
Or do I have to copy all the class files in one folder first and give that folder to the Ant War Task?

Maven - Jar inside a War

I'm converting an old Ant build into a Maven project and I would like to maintain the exact structure of the resulting War file that they created using Ant. Here is the desired structure of the War file.
Here is the structure of the project before it is compiled and packaged.
I'm having trouble figuring out how to create a jar of example.java and place it into a folder called applet which is at the same level as the other folders from the web folder. I can restructure the project any way I like but I have to keep the resulting war file's structure the same. So how do you create a jar file and a war file and place the jar file inside the war?
Note: I've been trying to use this example here, How to create a jar from part of my project that is packaged as a war, but the structure is so different I'm having trouble getting it to be exactly what I'm after.
P.S. I'm also curious as to why they set up their Ant build this way to begin with. I mean, what is the point of having the classes packed up in a jar and placed inside the applet folder rather than just putting them in the traditional place inside a war which would would be under WEB-INF/classes/java/com/example/*.class.
The easiest is to move example.java into its own module with jar packaging (i.e. sub project) and then use Maven Dependency Plugin to copy that artifact into the /applet folder before packaging your war.

creating jar with exploded war component in maven

I have a pom.xml which currently generate war file. I want to create a JAR and the jar which i am creating should have the two directories, one is war in the exploded form and another is some config folder.
My new jar should have below structure.
application.jar
|__application_war_directory
|__config folder
I am new to maven. Can you please anyone help me

how to create ear file, and include war and jar files inside that

I am trying to create an EAR file from the command prompt. I have used
jar -cvf myServletWAR.ear .
But my question is, how can I get this EAR file to have WAR files and JAR files inside it?
Do I need to create the war file separately and include in the ear file?
I can't use the ANT file for this, as there are few restrictions on this project.
One of my EAR files has structure as follows:
app.ear
- APP-INF
- lib
// libraries (.jar) here
- META-INF
- MANIFEST.MF
- weblogic-application.xml
- module1.war
- customlib.jar
This archive is being deployed onto WebLogic 10.3.
Remeber .ear is just a ZIP file, so you can always create it this way, although it seems messy.
check if jar cmd is working if so, create the jar of your class files and descriptors etc.
After that jar -cvf <<earname>> <<files want to be in the ear >>
Could you try this :
jar -xvf myServletWAR.ear
You could also refer to :
How to add a WAR file into an existent EAR file? and how to I have two .war files within one .ear file?
You would have to add these EAR file references in the application.xml of the ear file.
If you have generated a client and EJB together, they are automatically packaged into an enterprise archive file (.ear) and you do not need to do this. Otherwise:
Package the EJB's .jar file into an .ear for your application. To do
this use a jar command similar to the following:
jar -cvf myApplication .ear myService.jar
If you have a client .war file you can add that to the .ear file in the same way.
Create a deployment descriptor application.xml either using your
application server's tools or by copying and editing a sample, as
follows:
Locate a sample .ear, which is in examples directory in
mapdemo/mapdemo/repos/myService.deploy/JMapServ-WL.ear
Extract the descriptor application.xml from the .ear file, using the following jar command:
jar -xvf JMapServ-WL.ear META-INF/application.xml
Make a copy of the application.xml descriptor and edit it, replacing JMapServ with the name of your .jar file. You can also add the name of your .war file if you added that to the .ear file.
Put the descriptor in the meta-inf subdirectory of the directory containing your .ear file.
Package the descriptor into your .ear file using a jar command similar to:
jar -uvf myService.ear META-INF/application.xml
If you want to create an ear from the command line, following are the options that you can try.
Option 1. Using an ant build and use the ear task. Configure this ear task as stated in stackoverflow question on ant ear task usage
Note: Maven based build is preferred over ant these days.
Option 2. If you can use maven, configure your modules and use maven ear plugin to generate an ear. The below command will be able to generate the ear.
mvn clean package
Refer to the maven question regarding a Java EE project for more information on configuring war, jars for an ear.
.jar file into an .ear
jar -cvf myApplication.ear myService.jar
.war file you can add that to the .ear file in the same way.
Refer http://supportline.microfocus.com/Documentation/books/sx51/thdpoy10.htm

how to package the .class under the web-inf/classes as a jar and put it to the web-inf/lib dir

I have a java web application name webapp,when I export it to a war,the source codes will be compiled to the WEB-INF/classes.
Now I want these classed be compressed to a jar,and put into the WEB-INF/lib.
I have tried this:
create a new java project named webapp_jar.
Copy all the source codes under the webapp/src to the webapp_jar/src,configurate the build path to make the project work.
Add the webapp_jar reference to webapp project.
However ,when I run the webapp,it seems that the classes defined at webapp_jar can not be found.
Is this possible?
BTW,I use the eclipse ee ide.
have you try ant https://ant.apache.org/ ?
you could make a jar and copy it to folder you want and build the war after.
But , if I anderstand, you would package all the app to a jar ?
I think your webapp can't work without a servlet or two ...
This is really easy to do with maven by creating two subject projects, one to build the war, and the other as a jar project and then use the jar project as a dependency on your war project which would put the jar inside the lib directory when packaging the war.
No I use the Web Deployment Assembly settings in eclipse. I worked.
You can find details here.

Categories