I am using Maven in Eclipse and Netbeans and I notice that the Maven folder structure is quite different from each other respective of each IDE.
Understanding that the standard folder structure is:
src
target
pom.xml
How can I make Netbeans follow the same structure?
Your assumption that the default maven structure is src/target/pom.xml itself is wrong.
The default folder structure four your source files is src/main/java and for resources files is src/main/resources.
If you have static contents such as html and javascript files then they go in src/main/webapp folder.
See this link for more details.
Your IDE (be it Eclipse or Netbeans) has (and should not) NO control on how the folder structure appears when you import/create a maven project on the IDE. Rather it is controlled by Maven.
The IDE will simply display the folder structure as it is currently present.
Reorganize your folder structure based on the link I gave above and you should be good to go then.
I use Netbeans and I am having the same problem while learning from a project that is written in Eclipse. In Eclipse, why is there another folder "Java Resources"? should not all the source files be in - src/main/java and resources files in - src/main/resources?
Why use the folder Java Resources to write source files.
Related
I'm using Eclipse and m2e to import a Maven project into Eclipse.
The eclipse documentation states the following about the .project file:
The purpose of this file is to make the project self-describing,
so that a project that is zipped up or released to a server can be
correctly recreated in another workspace.
However, the .project file does not contain no information about the imported Java files nor the pom.xml. It only contains some build commands and natures. Thus, I don't understand how it makes the project self-describing.
It seems that each developer that downloads repository for the first time will need to import the Maven project inside Eclipse again. I'd like to have a meta file that contained at least the pom.xml path so that developers could have a ready environment after downloading the repository content and didn't need to import the Maven project into Eclipse. Is that possible?
Technically speaking, Eclipse doesn't know anything about maven. The .project file is Eclipse's way of storing metadata about the project in a file that's contained within the project (although nowadays some of that metadata has moved to the manifest.MF file). The .project file still contains information about natures (which are used by tools to identify which projects are of interest to the tools) and builders (which describe what tools to invoke as resources in the project are changed). In this way the .project makes the project self describing.
Maven is a relative newcomer (albeit a stable and well-established one) to the Eclipse world. As you point out maven stores all of its project info in a pom.xml file. Maven fits itself into the Eclipse world by providing two actions, "Update Project Configuration" and "Update Project Dependencies", that take the information in the pom.xml file and update the contents of the .project and .classpath files.
So instead of manually editing the .project and .classpath files as you suggest, a developer only has to invoke those two functions after extracting an Eclipse project from a repository.
I'm new to Maven. I've just installed and configured it.
When I started coding, I realized Eclipse doesn't show the error messages.
I haven't found anything helpful by searching Google. Some sources say to add java builder to your project but I already did.
Here's a screenshot.
It looks, that you had project in eclipse configured to have source code in 'src' subdirectory (and compile classes to 'bin').
Maven by default looks for java sources in src/main/java (and compile classes to 'target/classes').
So you'd need to move your source code to src/main/java or modify pom.xml to point to 'src' as source directory.
I'd suggest following maven convention and store source code in src/main/java.
You didn't create the Maven standard folder structure.
Create the structure like that:
src/main/java for Java classes and src/main/resources for properties etc., then do a right click on the project and choose Maven -> Update project configuration.
I am having a Java Web project with some class files, JSP files along with WEB-INF and META-INF folders. I want to use this project in Eclipse Helios.
For this I will need to import this project. However, Eclipse will search for .classpath and .project files in the root directory of the project. And unfortunately, I don't have these.
So, can I create one from the project?
Or do I just have to create one project and copy the files into the project? Though this will be a little tedious task if I have too many packages and class files.
Or do I just have to create one project and copy the files into the
project? Though this will be a little tedious task if I have too many
packages and class files.
It isn't tedious. Just create a blank Dynamic Web Project in Eclipse and copy the source folder. You can add a "Source Folder" to point to where your Java source files are present. It will then automatically add all the packages under it.
I'm using NetBeans to develop J2EE web service.
NetBeans create a directory called nbproject inside my project directory.
I'm wondering if I should put this directory under source control. I think it is required to build the project without NetBeans.
This is usually not required. Think of it this way: If I was to check out your project but happened to be using a different IDE, I would not require your nbproject directory. In other words: This directory is machine specific, not project specific. Hope this helps.
The nbProject folder contains all the netbeans metadata about your project. When you go Project -> properties all the settings (and others) that you find there are stored in the nbProjects folder.
EDIT:
This has been answered in another question, and the answer there is more complete and accurate
In short you should include nbproject, but not nbproject/private
If you are building your project with Maven or Gradle you should definitely exclude the folder from the VCS.
Inside the folder 'ProjectName' exists several subfolders, and of them contains java program:
ProjectName
Specifications
JavaCode
Gfx
...
JavaCode folder contains pom.xml.
I have installed m2eclipse (0.10.x) to Eclipse and imported whole ProjectName folder to Eclipse. Subfolders are displayed correctly but maven integration is not working correctly - for example I don't see src/main/java "shortcut" folder in Eclipse, but I have to click to open all folders.
If I create a new maven project with Eclipse from scratch, the integration works well.
What could be the issue?
Select the JavaCode folder and then invoke File... / Import... / Maven Project. That would bring your Java code into Eclipse as a proper project with Maven support enabled. It is fine to import several overlapping folders. So, you could use the parent for version control purposes and JavaCode would be the actual Java project you'd work with in the IDE.
Unfortunately there is no way around that, unless you want to move your pom.xml to the root project and remap all the Maven plugins to folders under JavaCode project. But that would be really bad idea and Maven integration for Eclipse may not work with such project structure without an additional tweaking.