Maven - Jar inside a War - java

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.

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?

How to create Jar file with external folders and Jars

I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html

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.

Eclipse Exporting to jar ignores Manifest class path: directive

I am trying to use the Eclipse export function to create a jar file to be deployed in an Axis2 deployment in Tomcat. When I have source code projects, I can export this jar, rename it to aar, and it works fine. All the classes from all the projects are present inside that exported jar.
Now I convert a few of those projects to jar files (they form a library). The primary project now points to these library jars as external jars in the build path. It builds fine. Now I want to export the same type of jar file from this primary project that no longer has access to the projects containing the library source code.
SOO...I followed these instructions to create my own Manifest.txt file that would point to these external jars using the Class-Path directive. The line appears as follows:
Class-Path: file1.jar ../../libraryJars/file2.jar
So I follow the usual export to jar (not runnable of course; there is NO main here!) with the option to use my Manifest file and the Class-Path directive in that manifest is ignored. I look inside the created jar and the only classes I find are from the primary project. All those classes in the external jars were NOT loaded.
How do I get the classes inside the external jars to be exported with the classes in the primary project when creating this jar? I understood that using the Manifest.txt approach was the way to do this. Perhaps it only works when making a runnable jar (which I cannot do)?
I do NOT want to use something as messy as ANT. If I have to resort to script files to accomplish this task I will just do the copies with a bat file.

How can I update a existing war file with additional files using Maven?

I would like to update an open-source war file in Maven with some additional class files and jar files. I also need to replace one configuration file with my own.
The simplest way I see to do this is copy over the Java source files and configuration files from the base war file and check them into my source repository. This would work, but it requires that I duplicate both source and configuration files. Thus, what I would like to do is build the base war file, check in only that war file, then run a maven build which adds my class files, extra jar files, and replaces one configuration file in the base war. The output of the Maven build would be one war file.
Does anybody have any suggestions as to how I can do this with Maven?
By the way, the base file is from jUDDI - it is juddi-war. I think the answer to the problem does not depend on the particular war file though.
You'll want to use an overlay. It's intended to add files to an existing WAR.

Categories