Using maven, how to configure a war into a ear file - java

Im bulding an ear, that has the war of a project inside. It happens that i need a second war place in another directory, to be copied into the same .ear.
Meaning i want my ear, to contain two war files.
One war is the war of the same project where the ear is built, the other war belongs to a different project.
How can i put my pom.xml in the proper way to make this?
thanks

You need to think more Maven-like to solve this problem in Maven. Every project (or module of a multi-module project) creates one artifact (WAR, EAR, JAR, ...). You do not create two artifacts from the same module or project.
If you want to create two WARs and one EAR to bundle them, you need either a multi-module project with three modules or three separate Maven projects.
Two projects/modules create the WARs, and the last one bundles them. The bundling is easy: You just need to reference the WARs as dependencies of the EAR.

Related

Prevent intermediate Maven artifacts from being uploaded

I have a project creating some FAT jar to be used via webstart loaded from an ear. This leads to the following Maven projects in a multi-module project
jar project creating the FAT jar
war project creating the webstart war
ear file containing the server application and the war file for webstart
The jar and war artifacts are only used as intermediate artifacts to be able to create the ear artifact. However, Maven handles them as artifacts and so they are always uploaded to Nexus.
Since the jar is getting real fat, I would like to avoid uploading it 3 times to nexus for each build. Is there a way to avoid this? I can think of two ways:
Moving that three projects to one pom file
Some flag / option / whatever telling Maven to handle artifacts as intermediate artifacts not being deployed or installed
Does something like this or any other solution to my problem exist?
If this is a multi-module project, you can set <maven.deploy.skip> to true in the projects where artifacts should not be deployed.

Maven combine two project

How can i combine two maven projects. One is webapp, and other is some javascript library (also webapp) which i want to combine with others project.
Or, would be better, how to add some outside folder with js files to maven project that can be deployed on testing server and then build to war.
Have a look at overlays in the Maven WAR Plugin documentation. This explains how Maven merges resources from different web projects into a single WAR.
In a nutshell, you create several WAR files of all the dependencies (usually, you already have this but you can even do this if they aren't real working web projects). Then you can pull these in as dependencies. The important part here is to specify the type of the dependency (<type>war</type>); otherwise Maven will try to add the JAR.
The WAR plugin will notice the additional WARs in the list of dependencies and merge them.
You can create One parent project and Two modul project. You will have 3 pom.xml files.
modul projects extendens dependencies from parent project. Maven parent pom vs modules pom, Multimodule project
Maven WAR Overlays could solve the problem. If you have two maven web projects, and one of your Web Project depends on the other's you could declare the dependent project as a dependency and do an overlay.
Reference:
http://maven.apache.org/plugins/maven-war-plugin/overlays.html

difference between MutliModule and EAR

What is the difference between maven multimodule project(pom packaging) and ear packaging.
As i know Ear is used to package a group of related Module (EJB, JPA, JSF).
After reading maven documentation i found that multimodule project is used for the same thing.
Are they the same? Can i use multimodule project instead of EAR? can mutlimodule project be deployed to application servers?
A multi-module project (packaging of pom) is a way of defining a parent pom that has child modules. This is convenient for many reasons. For one, you can just build the parent pom with mvn compile and it will build all of its modules, too. Without the parent pom, you'd have to go into each pom and manually type mvn compile otherwise.
Not only that, but using modules gives you other really important features. See the answer to this question. To summarize, imagine you have a continuous integration server that just installed in the middle of you building locally. By using module, you ensure that you compile against your local code instead of the continuous integration server's code. This will prevent a lot of heisenbugs(sp?).
Now the packaging of ear is not directly related to this first multi-module concept. That packaging just determines the binary output. It will output an ear file. In the maven-ear-plugin plugin, you can include other modules like wars/jars/ejbs, but it won't do any of the things I've described in the first paragraph. For example, typing mvn compile in the directory of the ear's pom.xml file will not compile the war file it depends on.
Also, you don't have to include other maven modules in your ear. Another completely unrelated project may install an ejb and you can use that ejb in your ear just as a dependency.
multi module is just a way of organising your project into modules/components.the packaging need not be ear always.it can be for instance a war project that has all its server side content as a jar file in one of its module.
in short,multi module organisation can be opted for a ear project but the converse that mutli module is always a ear project is not true.
The two are not the same. A multi-module project just builds all sub modules, it does not produce an artifact.

Eclipse WAR with 2 projects?

I am trying to export a WAR file from Eclipse. I have a "Dynamic Web Project". But I need classes created for two other projects, one a plain Java project, the other another web project. So in the Build Config I told it to add the other projects and on the "Order and Export" page I clicked the boxes to export the second and third projects. In runs fine within Eclipse, apparently finds the files from the other projects with no problem. But when I export, only the files from the first project are included in the WAR file.
How do I get Eclipse to include the other projects' files in the WAR? Apparently just adding them to the Build Config and marking for export isn't enough. Is there a problem because one of the other projects is also a web project? Does Eclipse balk at that?
I presume I could make this work by copying the files I need from the other projects to the first. But then any time they are updated, I would have to know that this had happened and copy the new versions. That would be a pain, and I thought that's what Eclipse projects were for, so I could share files between applications.
Edit
Let me clarify that I don't want to deploy 2 WARs. I have a web app written for one project that includes some classes that I want to re-use on another project. What I was trying to do was just pick up those couple of classes in the "real" WAR. I definately don't want to deploy 2 WARs because this might go on the same server as the original project, and I don't want to overwrite the existing WAR of the original project.
Thanks for any help!
You need to add your other project as a Java EE module to your web project. Right click on your web project -> properties -> Java EE module Dependencies. Add the 'other' project to it. Eclipse will include this project in the export.
Packing together different projects for deployment is achieved through an EAR file (enterprise archive). An EAR may combine multiple web projects (WAR), Enterprise JavaBeans projects (JAR), standard JARs, etc. and packs it into a single application.
Create a new EAR project in Eclipse, open its properties and check all dependencies on the Java EE Module Dependencies page. After that export the project as an EAR and deploy it.

How to generate an ear file from a maven-archetype-webapp artifact?

I currently have a project built with maven-archetype-webapp artifact. The default packaging for this project is war.
Is it possible for me to insert the maven-ear-plugin in this webapp pom.xml generate an ear file that contains this project war? I tried that, but the war file doesn't get embedded in the generated ear file. It has everything except the war file.
I read many Maven related articles, and perhaps I could use maven-archetype-j2ee-simple artifact. However, I'm reluctant to this use for 2 reasons:-
This artifact handles ejbs and all the extra features that I don't use. It makes my project looks bloated.
Second, it seems like it requires me to install the web module into the repository first before I can create the ear file. Is this the preferred way to create an ear file?
How do I create an ear file that contains the war file using maven-ear-plugin from my webapp's pom.xml? If this way is not possible, what's the preferred way?
I'm sorry if my questions sound a little novice, I realized I have whole lot more to learn about Maven.
Thanks much.
The maven ear plugin assumes that any WAR is a separate project, so you need two projects, plus a parent project. It's a function of how maven does packaging. Each project produces one artifact. There are ways around this, but Maven will punish you for your sins. This question goes into some detail on this topic.

Categories