deployment assembly using maven-eclipse-plugin - eclipse

I am using maven-eclipse-plugin for working with a war project. This war project uses maven overlay method to include another war. When I deploy it using Maven, everything goes well. When I test the war locally in eclipse, it fails because the dependent war resources are available only in the target folder. To solve this, I go the deployment assembly and manually add the target folder. Is there way I could tell eclipse-maven-plugin to add the following line to org.eclipse.wst.common.component file inside the .settings folder when running the eclipse:eclipse goal.
<wb-resource deploy-path="/" source-path="/target/finalname"/>

You can embed any additional eclipse properties in your pom for mvn eclipse:eclipse.
The plugin reference has some examples for adding build commands, resources, facets, and of course also adhoc configuration.
You can probably copy paste something from there to help you.

Related

Making Eclipse Maven repository inside the project

I'm a real beginner to Maven and Spring framework in eclipse so excuse me if this sounds trivial..
I have created a MVC web project in eclipse using the STS plugin on my windows computer, but my problem is that the location of the jar and configuration files that maven is set to by default is: C:\Users\MyName.m2\repository
This is a problem for me because eventually I'm going to make a WAR file out of my project and deploy it on a Linux machine, which does not have Maven installed on it.
My question is, is it possible to take all the jar files in my Maven repository, and make a local repository on the project itself rather than on an absolute path on the machine (sort of like a lib folder within the WEB-INF in the project that will hold all the maven jars and that maven will direct itself to it), and thus making the transition to the Linux machine smooth
I understand there is this classpath variable named M2_REPO, but doesn't seem to be editable or accept relative path rather than absolute.
Thanks in advance
Since you are using maven and you are adding your dependencies on your pom.xml, then all the dependencies with a scope of "compile" will be added to your final war file created by the maven war plugin under the WEB-INF/lib folder, this means that you should not worried about having maven in your linux server, since the war file that you are going to deploy will contain all the necessary dependencies. If you want to confirm this, just create a package of your project using "mvn clean package" and check the "target" folder generated by maven, you will see a "war" file, and you can unzip your file to check what contains.

Eclipse Deployment assembly for Maven build overlay option

I have my enterprise project which contains 2 WARs. There are some common resources in those WARs, in project structure we have base project which is web project. and base project contains common resources for 2 WARs. for those 2 WARs in project structure we have 2 separate web project.
When I do build through maven then I use a overlay option of maven to build a 2 WARs to be merged with a base project WAR. So that common resources from base project war is merged in both WARs from EAR.
I have created a eclipse project by following command,
eclipse:eclipse -Dwtpversion=2.0 eclipse:configure-workspace
Now I want to configure these project in eclipse(Kepler) so I can run those from eclipse by configuring application server on eclipse.
But above commnad add base war file directly in deployment assembly of WARs from EAR, instead of merging it as happening in overlay option of maven build.
I tried to fix this by manual configuration of deployment assembly but there is no option for adding folders from different project.
I have google a lot for solution for this but no luck.
Thanks in advance.
After lot f google one thought came to my mind, how this is been handled in myeclipse?
I have downloaded myeclipse and imported my project in myeclipse, then added maven nature to all project.
Then I have checked deployment assembly of WAR project, there base project added in deployment assembly without any value in deploy path, then i had opened .setting folder from WAR project I have checked the org.eclipse.wst.common.component file where i have found one entry which were doing overlay maven build in deployment assembly, that line is as follows,
<dependent-module deploy-path="/" handle="module:/overlay/prj/base-project?includes=**/**&excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>
here is a solution for overlay issue of maven build, which we need to configure in deployment assembly in component file of .setting folder of project.

Exclude Ivy Dependencies in WAR File

I use Eclipse and the Ivy plugin IvyDE.
I currently create a WAR file by using Eclipse's export to WAR functionality. I don't use an ANT build file - I let Eclipse handle that.
When I export to war, all the dependencies in the ivy.xml file get copied to the war file's bin directory. I want to exclude one (or more) of them. How do I do that?
What't the simplest way to accomplish this? If possible, I would like to avoid creating my own ANT build files and continue to use Eclipse's export tool and the IvyDE plugin.
For me the following did the trick:
copy the ivy.xml to e.g. ivy-nodeploy.xml
create/select the configurations you want to include in the deployment assembly in ivy.xml
create/select the configurations you don't want to include in the deployment assembly in ivy-nodeploy.xml
add a new ivy-library to the build path where you change the default ivy-filename to
ivy-nodeploy.xml
That way you still have all ivy managed libraries at compile time in your build path but only libraries configured in ivy.xml get included in the war file.
Right click on your project's ivy.xml, and choose "Add ivy library".
In the main tab are customization settings for the build configs, and it looks as though you can choose the conf you desire (i.e. set it to runtime). I war using Ant, so I've never tried it. I presume this will accomplish what you desire.

I need Eclipse to deploy the WAR file my ANT script builds, not what it builds internally

I'm using Eclipse Helios. I have a dynamic web project going and I've set up Eclipse to use an Ant Builder to generate a WAR file. This all works fine; if I change a .java file, Eclipse automatically runs my build.xml via Ant and updates my WAR. If I deploy the WAR to an external instance of Tomcat, it works perfectly.
However, when I tell Eclipse to run my project under Tomcat, it is not using the WAR file generated by the Ant build, or using my Ant script to generate a temporary WAR.
I know this because my build.xml script includes some additional XML configuration files in WEB-INF/classes in the WAR that are not ending up in the WEB-INF/classes dir that Eclipse pushes out.
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
An alternate approach would be to tell Tomcat when it is building a WAR to do so by adding a list of files, but I can't seem to find a way to do that either.
I'm also curious how Eclipse knows what to publish since it is obviously ignoring my build.xml and my previously-generated WAR file.
Eclipse deploys a web application by looking at the Web Deployment Assembly options for your project. You can see this by right-clicking the project, choosing Properties, and then click on Deployment Assembly. Eclipse usually uses an expanded directory deployment here rather than creating and deploying a WAR (this is based on the server plugin being used, but I think most of them use an expanded directory structure for speed). If you export as a WAR it will create a WAR with the same content.
There are two main choices to do what you'd like:
Modify the Web Deployment Assembly options to match exactly what you would like in the deployed app
Don't use Eclipse's deployment; add an "External Ant Builder" to the "Builders" options for your project (right-click project, choose Properties->Builders). You can then select which targets in the ant file you want to use when eclipse builds the project. One of these options can be a deployment step
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
I'm an IntelliJ user, so take this with a grain of salt. But...
Right-click on the Project Explorer target/foo.war, select Mark Deployable.
Then right-click on the foo.war file again and Run As... -> Run On Server...
Choose the JBoss instance.
If you go to the Servers view, you'll now see your WAR file under the JBoss instance as /proj_root/target/foo.war
Oh Eclipse, sigh...

In eclipse, is there a way to specify a location other than the WEB-INF, for web.xml

I want to place development web.xml in another folder in eclipse.
This can be done using the Deployment Assembly properties. Right click on the web project, choose Properties, and then navigate to the Deployment Assembly panel. Remove the /WebContent entry (pointing to /) and then add another entry, of type Folder. It should be rooted where you want to keep the web.xml, and mapped to /.
This technique can be extended to make Eclipse work with arbitrary build tool source layouts.
You might want to use Apache Ant
for that purpose. You may define a "conf" directory and place all you config files there, or a resource directory for the same reason.
If haven't use ant for that purpose, I strongly recommend you to do so.
Here is a sample ant build.xml for a web app Sample Build.XML
I'll use Maven myself, but since you're just beginning, Ant would be just fine.
I am using the eclipse builder and not ant.
Actually what i did was that i defined web.xml in another folder. So now I have two web.xml, one for welogic with a lot weblogic specific stuff like filters. And i have another for development which i placed in another folder, in the web project and added this folder to the deployment descriptor for tomcat in eclipse. So now when i deploy the application, the web.xml for tomcat which is in my specified folder owerwrites the web.xml present in web-INF folder(in the deployment directory).
Looks to me a nice workaround.