How to structure a maven project in Eclipse - java

If I want to have a project with both EJB/JPA sourcecode and JSF in the same project how do I set up a project like that in Eclipse? I am using Maven. Is it correct on the image below? What is the difference between source folder and folder in Eclipse, and why do I have structure twice in the project below?
GO TO http://i.stack.imgur.com/RCmI8.png for full size picture.

Yes, the structure you have is a typical folder layout for a Maven webapp project. Eclipse highlights the folders containing source code that will be compiled / placed on the classpath, but also shows you the regular folders in the filesystem.

Related

Path in Intellij Vs. Eclipse

My company is attempting to make a transition from Eclipse to Intellij Idea and I have a (might be silly) question regarding the paths.
I have a library in the root of the eclipse project and a spring configuration file which simply points to it by "folderName/file.txt". It works fine in Eclipse since it recognizes the folder. In IntelliJ however it seems to not pick the folder at all.
I've tried to mark the folder as a resource/test resource folder but it seems to simply take the contents of the folder and dump it directly into the target folder without the folder itself, just the contents.
Is there a way to configure IntelliJ to work with the folder just like in Eclipse? This is important because some are still using Eclipse, some IntelliJ, so we need a solution that will work for both.
I am guessing your are using maven since you mention the "target folder"
What happens is that since your imported the project from the maven pom.xml intellij build it by following maven.
In maven the default project structure is
this
This in maven everything you copy in the resources folder, will be copied to your root classpath. so if you make for
resources/myFolder/my.txt then in the build you will have copied to your classpath myFolder/my.txt
Anyway if you are not using maven all you have to do is go to
Project structure (ctrl+alt+shift+s) - Modules - go to your module - mark the folder that your want to add as resource

dynamic web project package structure

I have download a sample project and saw the below package structure.
src/main/java
src/main/resources
JRE System Library
Referenced Libraries
src
main
webapp
css
user
WEB-INF
target
Is it a best way to create the package structure. Normally when we create a dynamic project in eclipse it has one src folder and the WebContent folder in project root. The WEB-INF would be under the WebContent. But here we can identify two source folders and instead of WebContent we find webapp under the source folder not in root.
Despite its correct package structure or not i try to create the same in eclipse. But i cant rename the src folder to something like src/main/java know. It gives me an error
Cannot nest source folder "src/main/java" inside source folder "src".
in eclipse when create a dynamic project
This structure is maven based web base project and mostly for maven base project this structure is used, and as for as new conventions Maven is most popular deployment tool, so I myself recommend the maven base architecture.
If maven drives this organization a maven plugin exists, its goal is to generates eclipse projet.
A second plugin (an eclipse plugin) exists to faciltate the integration into eclipse.
The src/main/java folder is an automated updated duplicate of src folder. (These are the build paths configured in your project)
You should edit your files in src and the changes will be updated by eclipse to their symlinks.
First of all, its only one src folder. Eclipse displays them in such a way to make it easier to access different parts of the project. Webapp is main WebApplication Folder which contains all the goodies. The other most important folder is WEB-INF this is folder which is read protected from the client side so, you have your Java Class files and any thing which you want to protect from the client inside this folder. This folder also, contains a lib directory to contain the JAR files. This is the main overlay for the directory structure.

After building the project from pom.xml using Maven, how do I use its resources

It's been tedious. This is the API I am trying to use. Its resources were set up in a pom.xml which I built using Maven. On built up, it gave me the project socrata-publisher that has
src/main/java the source folder with packages com.socrata.api com.socrata.data, com.socrata.util where each contains only .java
files
JRE System Library and Maven Dependency hierarchies where each contains a number of jar files
Problem is com.socrata.api and the 2 other contains classes which I want to deploy in a project outside socrata-publisher. I tried using import com.socrata.api but it didn't work. Moreover, since its a Java project and not android it doesn't have the is Library option in preferences which could rather give me the solution. Both socrata-publisher and tutorial (where i want to use the resources and which is the android application) lie in the same directory eclipseApps in My Documents.
Here's a little visual queue. Help will be greatly appreciated.
You will need to first of all get the output of the socrata project and all its dependencies.
In command line, going to the project folder of the socrata project, where the pom.xml file is, run MVN INSTALL. You shall see a jar file called socrata-api.jar in $HOME/.m2/repository. If you are using windows and installed MAVEN by default, $HOME should be your user profile folder. Once you see the jar file, add it to your tutorial build path.
I think what you actually want to do is just set up the "socrata-publisher" as a project dependency for your "tutorial" project. That will allow you to reference the built Socrata libraries from the code in your project.
Right click on the project and select "Properties". From within that dialog select "Java Build Path" on the left, then the "Projects" section, and click the "Add" button to add the "socrata-publisher" project.
I think that'll work better than creating a separate jar file that you then include, and then you can also keep the socrata-publisher code up to date using Git.

Mavenising an Eclipse Java project without the wizard

This is probably a basic question for you here but here goes:
I'm building a java project using Maven in eclipse at the moment. I have a pom.xml file which is working fine, but I need to be able to organise my source files into 'src/main/java' and resources into 'src/main/resources' etc. Any other maven projects I've looked at are structured like this and the build goes to success without picking up any source files, since it "skips non existent resourceDirectory src/main/resources" and the others.
I currently have a source folder 'src', and eclipse won't let me add more source folders with 'src' in the name.
Any guidance whatsoever would be greatly appreciated.
Try right-clicking on the project and selecting Maven->Update Project Configuration from the context menu. Then refresh the project. If your pom is close to right, that should represent your project in eclipse the way you want.
Why don't you just open your pom.xml file in eclipse? It can recognize it and will built its project files correspondingly
In eclipse right click over the project / Build Path / Configure Build Path / Source (tab)/ Add folder and select the source folder you want. If the folder you need doesn't exist under /src/main create it following the maven conventions.
after that I would recommend:
mvn eclipse:clean eclipse:eclipse

Eclipse deletes java files on build of an android project

I have an interesting problem. I pull down an android project from cvs, which works fine. Once Eclipse builds the project, my .java files are removed. XML files, pngs, everything else is fine. I seem to be left with just the package tree, but no source files. Any thoughts?
Right click on the project
Properties
Java Build path
Source
Check that the src folder path is correct.

Categories