Organizing non-Maven source code in Eclipse projects - eclipse

I am working with some sample source code that comes with a book that I recently purchased. This sample source code does not use Maven. When I imported the sample source code into Eclipse, it created a zillion new projects, cluttering my Project Explorer. I want to organize all the source code from the book under one Master project, whose name is derived from the book. After playing around quite a bit, I came up with a working solution that is reproduced below:
Created a Maven project, choosing the book title as the Artifact Id
{thereby organizing all the child projects under the book title}
In the Maven project, created multiple directories from Eclipse,
one for each chapter of the book (New --> New Folder --> Folder name) {this ensures that Eclipse has visibility to the directories}
Closed Eclipse
Copied the source code, chapter by chapter, to each of the directories created under the Maven project
Relaunched Eclipse
Sequentially imported the projects from each directory created under the Maven project directory in Step #2 (Import --> General --> Projects from Folder or Archive)
Although I have been able to realize my goal, I am uncomfortable with the fact that I am creating the Maven project solely for the purpose of organizing multiple non-Maven projects under one parent project. I am not making any use of neat Maven features like dependency management.
Q) What is the best way to organize multiple non-Maven projects under one parent project in Eclipse?

First of all, if these projects are all test projects unrelated to other projects, you can just create a new Workspace in Eclipse.
If this is not what you want, you can define Working Sets that organise projects.
It is usually not necessary to put projects into subfolders to organise them.

Related

Multi module maven project is not showing in package structure but as folder structure in eclipse

I have successfully imported a multi module maven project from GitHub into my eclipse and able to build it successfully.
But the problem is project is being shown in folder structure but not as package structure which is making my day tedious.
Could anybody else faced this issue? Please do suggest your ideas.
Check out if the Project view in hierarchical mode would be a better fit for your need.
See Eclipse 4.5M5:
The Project Explorer now provides the ability to view the projects in a hierarchical (a.k.a. nested) form.
For modular projects, this allows to have your Project Explorer mapping more closely the organization of your modules as they are on the file system.
This hierarchical view of projects often makes easier to navigate modular projects.
Hierarchical view of projects can be triggered from the Project Explorer view menu, under the Projects Presentation item.
Then it makes the folders that are at the same location as a project replaced by the project, and the projects that are nested under other projects will not be shown as root elements.
In the folder where you have downloaded the project from git, you will see a .project file. You need to provide buildspec and natures information in that xml file.
In my case the .project xml file looks like this -
Now, make sure that you have provided the buildspec and natures information as shown in example above.
Once you have made the changes to .project xml file -
Right Click the Project >> Refresh
Right Click the Project >> Maven >> Update Project
You will see that the project (source) folder structure is represented in desired format.

In Eclipse, how do I exclude test folder of one maven project from another project that has as a dependency?

I have two maven projects imported into Eclipse in the same workspace. Both have a class with the same name and package, but different implementations and in different locations in each project. Let's call this class com.namespace.Factory
Project A has Factory under its test folder, i.e: /src/test/java/com/namespace/Factory.java
Project B has Factory under its main source folder, i.e: /src/main/java/com/namespace/Factory.java
There is also a Project C which is dependent on both. Project C also uses Factory from Project B for some of its unit tests. Problem now is Eclipse can't compile Project C because it can't differentiate between the two Factory classes. If I build all projects in command line, they don't have issues.
You would think that Eclipse would ignore the Project A Factory class since it is in test.
I am using the m2e plugin. My current work around is to setup m2e to not resolve Project C's dependencies within the workspace. This forces it to download the jar that will not have test in it. However, this means I have a change in either A or B, I have to manually install A or B push the latest jar to the local repo, and update Project C's dependencies to pull down the latest jars.
Is there a way to exclude the Project A test folder from the build path in Project C so that I can continue resolving everything within the workspace? It feels like Eclipse is breaking something that is fundamental to maven projects.
I think you're just another user affected by the upstream bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=376616
To sum it up, the bug report discussion includes:
JDT implements just one buildpath per Eclipse project. This is very unlikely to change, since this was fundamental design choice and many APIs and implementation details rely on that.
Well, but that doesn't really answer your question I guess.
So I see multiple options here, depending on how much influence you might have on the projects:
either try to rename one of the classes => names would be unique
or if the classes contain basically the same functionality, play with dependencies between projects, or even create new one, that the other 2 would depend upon
that's pretty much what comes to my mind right now
Perhaps you can try this:
In project A's Properties dialog (get there by right clicking the project and then click Properties),
click Deployment Assembly on the left.
Eclipse will show all source folders.
Select the test folder (/test) and click Remove.

Eclipse buildpath automatically taking all JARs of a linked directory

This issue is a variation on the one described here: Eclipse buildpath automatically taking all JARs of a internal directory
But instead of any local folder, I'd rather have a linked folder from another project be picked up automatically in the buildpath.
Basically, I have a main project in my workspace that holds directories lib, ext-lib that contain multiple jar files each. These jar files may be upgraded/removed or new ones added every few days.
I also have many other projects in the workspace that relay on the exact same (up-to-date) jars from my main project.
My goal is that as I modify the jars in these two folders in my main project, to have them as linked folders in all other projects and have those linked projects dynamically picked up as part of the buildpath of all those projects.
Any suggestion on how to do that in eclipse would be highly appreciated.
Unfortunately, the "dynamic directory" plugins people mention can not work with "linked" folders :(
Sincerely,
Guy
I would suggest creating a USER LIBRARY in eclipse and then using that in all of your eclipse projects.
Try going into preferences Java -> Build Path -> User Libraries and creating a new user library with all your jars. Then use this everywhere you need these jars.
See this page for more details.
Also, this page explains creating a user library in a bit more detail. There is also a use-case there which seems a bit more aligned to what you had in mind:
6.2.1. Linked Library Project
A useful hybrid strategy is to configure a user library that is also available as a linked folder in your Eclipse workspace. Follow these steps:
1.
Create a simple project in your workspace. Unlike Java projects, a simple project has no Java build path configuration in its properties. Use the command File > New > Project > Simple Project.
2.
Uncheck the option to use a default project location within the workspace folder and enter the path for your \eclipse-contrib\libraries folder (see Figure 6-8).

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.

Can a single Subversion repository managed as multiple projects in Eclipse?

I have a Helpdesk application that contains modules that can be downloaded and installed separately as required / preferred by the users. The structure is very similar to many software such as Drupal, which modules can be loaded/unloaded easily.
I'm using a single SVN repository for this Helpdesk application and create different tags for each module. And on my Eclipse I have everything as a single project.
My question is, can a single Subversion repository managed as multiple projects in Eclipse?
Can I create one Eclipse project for the whole application and at the same time for each module?
Another requirement is that by splitting each module as a different project would make Eclipse builds faster.
The reason is, I want to delegate programming work of each module to another person without the need to expose everything. The person would only see & work on the module only but commit to the main repository.
I know that Eclipse will have configuration files for every project, would there be any conflict.
I've had good look storing multiple Eclipse projects in one repository. Each of the projects is stored in a separate folder under the repository's root. Then, I use Subclipse to check out each of those folders as a separate Eclipse project.
I do not think that you should nest Eclipse projects (so that a master project contains many sub-projects).
Instead of the master project, you could group the individual projects into what Eclipse calls a Team Project Set (found in the Export/Import menus). This is an XML file that defines where all the projects are. You can put that file into Subversion as well.
So, you would have all the module's projects, and that XML file (which is not a project itself), all in Subversion (could be the same repository, could be spread over several).
I don't believe this is strictly possible. Personally, I would split the modules up into different projects entirely, and I would probably use Eclipse's plugin structure to resolve dependencies between them and the main project. If you ship the plugins as jars, they're still modular. Then, you can control each plugin as a separate project in Eclipse, and a separate folder in SVN.
That is no problem at all! Just create your trunk/tags/branches structure on your svn repo. Create your differen projects and then check thos projects into your trunc folder on your svn system. Finished!