IvyDE Resolve Dependencies in workspace with a Dynamic Web project in Eclipse - eclipse

I have a large application with many eclipse (actually using Spring Source Toolsuite) projects with ivy managed dependencies for each project. We currently have it setup and working where you can have project A (a dynamic web project that generates a war) and project B (generates a jar) setup such that project A depends on project B and if you only have project A in your workspace, it will go pull the jar file generated by project B from the ivy repository. We setup the deployment assembly to take the eclipse library generated from the ivy resolve and put it in the WEB-INF/lib directory so we can easily deploy to tomcat.
With the manual process, all of this works. I can make a change to project B, publish it to my local ivy repository, and re-resolve the dependencies on project A, and I get the new project B jar file and everything compiles and updates on tomcat as expected.
The problem I'm having comes when I change the ivy resolve settings of project A to "Resolve dependencies in workspace". When I make changes in project B, project A successfully notices the change and compiles correctly, but the deployment assembly breaks. When I go look in tomcat, it has a folder for project A's context root, but it is empty. If I uncheck the "Resolve dependencies in workspace" checkbox, the context root folder gets populated and everything returns to a working state.
I can continue doing the manual process, but it is a huge timesavings if I can get ivy to use my workspace first, then get the jar from the repository if the project does not exist in my workspace. Any suggestions would be greatly appreciated!

The solution was to add the Utility Module facet to project B (Project Properties->Project Facets->Utility Module) so that eclipse would know the structure of the jar file that is supposed to be generated.

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.

Can't get eclipse kepler to deploy dependency projects of dynamic web project

I've recently upgraded from Eclipse Juno to Kepler, and have imported some old projects into a new workspace, but unfortunately I cannot get publishing of one of my web projects to work. It has dependencies on a couple of other projects in the same workspace, and these projects are listed in the 'deployment assembly' tab with entries like
Source Deploy Path
/eventserver WEB-INF/lib
that I have added using the 'Add/Project' option (I'm pretty sure I've previously used 'Add/Entries from Classpath' but that option does not list the projects, so I don't know what's going on). But neither the projects' code nor their dependencies are being deployed to WEB-INF/lib when I publish the main project. Also, I have the following warning showing up:
Description Resource Path Location Type
Projects must be referenced by an EAR or a WAR to use classpath publish/export dependencies whose runtime path (../) maps into the parent component. eventserver P/eventserver Classpath Dependency Validator Message
which I only used to get if I didn't have a main project that referred to the utility project.
Any ideas what's going on?
Create an EAR project using this link:
http://www.eclipse.org/webtools/jst/components/j2ee/scenarios/application_creation_tutorial.html
After creation, try to Add the Project in server entry.

Eclipse adding the project overrides maven dependency

I have a maven project that uses other small projects. And I added them to master's pom file.
So my Eclipse project properties looks like following:
>Master project
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1.jar
>smallProj2.jar
The thing is I do not have the all code for smallProj1 and smallProj2 and whenever add them to my workspace Eclipse overrides the maven dependencies and simply calls the two projects instead the jar files from my local maven repository and then I have all over the code those red underlines. Project properties in Eclipse looks as following after I add them to my workspace:
>Master project
>smallProj1
>smallProj2
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1 (not jar anymore - folder)
>smallProj2 (not jar anymore - folder)
Since I also want to have a look to smallProj1 and smallProj2 code while I am coding, I want to keep them both in my workspace. But I want my Master project to use the jar files that I provided, not the small projects in the workspace.
Any ideas on that?
You could right click on a project and set "Maven" -> "Disable Workspace Resolution". This will let Maven find the dependencies from Maven and not within the workspace. I don't think it is possible to do this on a dependency basis.
But I think in your case it would be better to fix the broken smallProjX in your workspace (as they exactly contain the code you need), so that the master project could be build correctly.

Eclipse can't resolve transitive dependency projects?

In a Java project in Eclipse, I am trying to debug project A.
Project A has a dependency on B.jar, normally B.jar comes from my .m2/repository.
but now I want to make some temp changes to B's code, and have it reflected in A,
so I directly edit the source code in B project in eclipse, and set B as a dependency project in A's build path. Additionally, both A and B refer to C.jar as their dependencies.
This builds A fine, but when it is run, A's classpath contains 2 copies of all the classes and resources in C.jar. this creates a problem for those hibernate hbm.xml mapping files in C.jar and I got errors saying duplicate mapping for...
This looks to be a defect in eclipse, in that it lacks the resolution ability as maven posseses. is there a way to work around this? (apart from building B and installing to .m2 instead of having it as a dependency project)
Thanks
You mentioned "[setting] B as a dependency project in A's build path" - do you mean editing eclipse's build path or editing the project's POM? I'm guessing the former, in which case make sure that you have the latest version of the m2eclipse plugin installed and that both projects A & B are Maven eclipse projects. If it is set up correctly then your projects should look have an 'M' on their project icons, and the icons of any workspace dependencies should look like folders.

Maven project in eclipse - deployment assembly fails build

Sorry for being verbose...
I have some existing maven projects. I imported them into Eclipse using Maven -> Import existing Maven projects.
This gave me 6 individual projects and one project which lists all 6 under it. (The umbrella project has 6 modules defined in it which translated to 6 eclipse project - as I understand how maven works)
One of the project A requires two other project B and C (at compile time and run-time).
Build path -
On the build path of A I have one of the libraries as Maven dependencies. And it builds fine.
Deployment assembly -
On the deployment assembly of A however there is no entry for deploy to web-inf/lib. Because of that when tomcat starts it doesn't find any required jars or the project B and C.
So I added an entry to deployment assembly as : source - maven And dependencies deploy - web-inf/lib.
Tomcat comes up and my webapp for project A comes up.
This however breaks the eclipse build - upon build eclipse complains:
"Invalid classpath publish export Project entries not supported"
This I see is because, under build path, there is new entry added to web-inf/lib to publish/export under maven-dependencies. Removing that removes maven entry from the deployment assembly as well.
The only workaround is that in the deployment assembly I specify the web-inf/lib under target generated by maven but that causes stale copies of project B and C to be picked up.
Why I need this setting is because when I make changes to project B and C in Eclipse and build them in Eclipse I want to see the changes when I am debugging project A. I don't want to run maven builds on B and C again since its time consuming.
Any help is much appreciated.
I did try including the MAVEN2_CLASSPATH_CONTAINER but that is always empty and when tomcat runs it cannot find the necessary libraries. (BTW what vale is the MAVEN2_CLASSPATH_CONTATINER set to?)
This is on Eclipse Indigo Mac OSX.
You need to add the relevant project/s to your Deployment Assembly.
Right Click Project -> Properties -> Deployment Assembly -> Add
I solved just doing this:
right click on my eclipse project-> Maven -> Update Project Configuration...
Figured it out ..but not completely...
So I added maven dependency in the deployment assembly as I mentioned earlier.
Maven dependency -> WEB-INF/lib
AND additionally added project B and C as well :
B -> WEB-INF/lib and C->WEB-INF/lib
Somehow this way B and C are not added to the publish/export in the java build path. I don't know how eclipse knows to not export B and C from maven repo but to export it from project B and C itself.
Anyways thats for some other day..
for now i m happy :)
For anyone else that searches for this, it seems that you can also manually add the following to the .classpath file
<classpathentry combineaccessrules="false" kind="src" path="/B"/>
By including Maven Dependencies, you are including dependencies for project B and project C. It turns out, you also have to include project B and C manually.
The exact fix which works is.
project A -> properties -> Deployment Assembly
Click Add and then Project. Select B and C. Problem will get fixed after rebuilding.
I had this problem, but I believe none of these answers correctly fix the problem. Instead they workaround m2eclipse (which should manage classpaths and deployment assembly for you). For me, the problem that I was using m2eclipse without m2eclipse-wtp (a separate plugin).
See this SO answer for the plug-in details.
You can add the relevant projects / or maven java build path entry if using maven to your Deployment assembly (project -> properties -> deployment Assembly)
Then checks if theses relevant project are Facets compatible. (project -> Project Facets)
This error can occur if you have multiple entries of same jar in you class path. So you need to check your classpath and remove duplicate entries.