Eclipse link web projects java build path - eclipse

In Eclipse have a java web project and I want to link it to another java project. Saying that:
Project A: Web project
Project B: Another java project
Normally can you achieve it by going to the properties of project A -> Java build path -> Projects and add the project B.
However if project A is a web project running inside tomcat then at runtime I receive a ClassNotFoundException for the classes of project B.
One solution to to problem is to export project B as a jar file and use it inside project A (put it in the WEB-INF/lib directory).
However this is not the case because I want also to debug at the same time project A AND project B

Go to Project A's Deployment Assembly property page and add Project B as a project Directive Type.

Eventually I found one good solution.
In eclipse from the properties of project A go: Java Build Path -> Source -> Link Source
in the "linked folder location" give the src folder of project B and in "Folder name" just put "src2" (just something different from "src").
This way eclipse creates a symbolic folder src2 which links classes of project B to the space of project A.
After that everything works fine:
You can compile and run project A without any ClassNotFound Exception.
You can debug classes from both Project A and project B at runtime.
Classes from project B are kept in a separate folder in the filesystem totally independent (this is also useful when you use a source control system like SVN, because two projects continue to be independent). Notice that even folder "src2" is not a real one, so no change in project A.

Related

Eclipse Mars, open type reference

I have project A and project B in Eclipse Mars.
Project A is packaged and used as dependency in project B's classpath (Eclipse's build path).
I mostly work from project A, the annoying thing is that when i want to open a type within project A with the Ctrl+Shift+T combination, it opens the compiled type in A's dependency of project B.
This page does not show anything about this.
any advice?
Rather than include ProjectA's package (JAR?) on ProjectB's build path, you should instead make ProjectB depend on ProjectA.
Open ProjectB's properties and then add the dependency here:
Don't forget to remove the ProjectA JAR from ProjectB's build path (in the Libraries tab above).

Eclipse m2e multi-module project checkout and convert to maven

I have recently had need to checkout an apache project to do some fact-finding/debugging (specifically maven-surefire-plugin, see this question). This, like most other apache projects, is a maven multi-module project. So, in eclipse, I open up the SVN Repositories browswer, add a new repository, find the project and right-click->Checkout.... In the wizard, I click Checkout as a project in the workspace and type in the name of the project.
I have the project, now I need to let eclipse know its a maven project, so right-click->Configure->Convert to Maven Project. Now the parent project is a maven project. I can right-click->Run As->Maven Build and it works. But, all the modules are just folders. Eclipse doesn't know anything about where the source code is or even if it has any. In a single module project it would have set the source folder, build folder and other configuration automatically. Further more, if you are creating a multi-module project from scratch, you start by creating the parent project, then, when you add modules to it, they each show up as individual projects in eclipse with the physical directory living under the parent project folder as needed by the default maven build process.
So now, knowing how its done when creating new projects I can File->New->Project..., choose General->Project, give the project a name (I match it to the module name), uncheck Use default location and set Location: to the path on to the module inside of the parent project folder. After clicking Finish, and repeating the process for each other module I have something that looks similar to what I would expect. I now need to convert every individual module to a maven module in the same fashion as the parent project. Great, they are all maven projects, right?
So then I open them up, and the source folder is not set.
Argh... Then I go to each project, twist it open, and on the src folder I right-click->Build Path->Use as Source Folder. Lather, rinse, repeat... Once done on all the projects, it really looks and feels like I started this project from scratch. Things function.
My question is, is it really this hard? Am I missing a shortcut? Wouldn't it make sense if Configure->Convert to Maven Project on the parent pom realized it was a multi-module project and did all the work for me? This is a very painful process for apache projects as they all seem to have many, many, modules... Anyone know of a better process?
You could try to pull all the code down outside of Eclipse, import the parent project as an existing Maven project (right-click -> Import... -> Existing Maven Projects), and see if it all comes in the way you expect. Then right-click -> Team -> Share Project... on the parent project.

Automatically update JAR in WAR dependency lib from second project in Eclipse workspace on build/deploy

I am working on a web service with a team using SVN.
The app is (currently) divided into 2 projects in Eclipse, Project A with controllers and views, and Project B with framework support and data models.
As it currently stands, Project B is exported to a JAR and placed inside webapp/WEB-INF/lib of Project A. This is how it exists in the SVN, and I am forbidden to change it.
I'm aware of Eclipse's deployment assembly configuration, but because the file must be pre-generated and placed in the lib folder, I am unable to use that method. (and this is what I want to do, but not allowed)
Also, though I understand this could be done with ANT, I don't have control over the build management, so that also is not an option.
Is there a way to automatically export Project B into Project A as a JAR, inserting it into the workspace, overwriting any previous export, automatically whenever Project B is built?
It wouldn't be automatic, but since Project B has to build the JAR, why not put the Project B JAR file into the Project A Subversion directory.
When Project B commits to Subversion, part of the commit process would be to commit the Project B JAR. Everyone working on Project A would do a Subversion update to get the latest Project B JAR.

IvyDE Resolve Dependencies in workspace with a Dynamic Web project in 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.

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.