sometimes i face project structures in Package Explorer that are at "src/main/java". But if i work for myself it is only "src". Howto take controll of that?
Difference between two projects in eclipse: left: one folder named "src/main/java" right: one folder named "src", one subfolder named "main.java"
Thanks - Enomine
The default source folder for a Java Maven project is src/main/java. In the project on the right, the source folder is set to src via the following line in the pom.xml file:
<sourceDirectory>src</sourceDirectory>
If you remove the line or change the value, right-click the project and choose Maven > Update Project... to have Eclipse read the pom.xml file and update the source folder location accordingly.
Difference: Let's first understand the meaning of both the folders. In the left image src/main/java is the source folder which is used by eclipse to build the project. In the right image src is the source folder with the package main.java
Solution: It is not possible to edit your source folder So you have to copy your files and create a new source folder with name src/main/java.
#howlger
Project structure and pom
I think i did right now. I clicked right, choosed "Build Path" -> "New Source Folder". Then it worked. With the Properties-Menue "Java Build Path" it didn't work.
Thanks - Enomine
The projects with src/main/java as source folder are maven projects. Maven is a build infrastructure which i.a. manages library dependencies, and provides conventions for the project folders, like src/test/java for unit test sources, and src/main/resources for non-java sources like images and *.properties files.
Best would be to import the project as maven project (here it is not gradle). It might be that you need a plugin in eclipse; for a while I am using an other IDE.
Create a new maven as trial.
Maven projects are controlled by a pom.xml so a recognition as maven project is best.
In my opinion, there are two ways how to solve it:
1. go to project -> build path -> configure build path -> Java build path and then in source tab add your src/main/java folder
2. There is also an arrow near the "Project explorer" which lets you customize your workspace. you can try to change "project presentation" or "package presentation"
Related
I have a project in Eclipse for which the Pom file(pom.xml) and Eclipse project file(.project) are not in the same directory. The Pom file is next to the source code.
The project resources in Eclipse are defined as Linked Resources(http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-13.htm).
I added the pom file as a Linked Resource then and converted the project in Eclipse to a Maven project(Configure -> Convert to Maven Project).
Unfortunately Eclipse is not showing the Maven Dependencies for that project and these are not resolved. Just having the Eclipse project file next to the pom and resources works well for that project but I cannot eventually use it(it's a company rule).
Tanks a lot in advance for your help
Unfortunately Eclipse is not showing the Maven Dependencies for that
project and these are not resolved.
Yeah, and I believe that the Eclipse project files are not going to pick up your changes when you convert to a maven project. This is simply the way maven works because you have the .project file elsewhere.
One note may be helpful: it is generally considered bad practice to check in your .project & .classpath files into src control, no matter where they are located. Can you try and have those files removed from source control and generated for each developer locally.
Personally, I always do that when I first create the Eclipse workspace by creating my project from the pom file: File -> import -> Existing Maven Project and then I browse to the pom.xml file. My understanding is that this is (for many) the preferred way to create the java project in Eclipse.
How do I create the src/main/java and src/test/java in my default web application project in Eclipse without Maven? My current folder structure is
TestApp
├── JavaResources
│ └── src
│ └── com.mypackage
└── WebContent
As you've discovered, you can't have a source folder inside another source folder, so before you can create src/main/java you have to tell Eclipse not to treat src as a source folder. To do this, right click on the src folder and select build path -> remove from build path.
Once you have done this src will appear in the folder tree in its normal place, so you can create the main and java folders under it, and move the existing src/com to src/main/java/com. Finally right-click the newly-created java folder and select build path -> use as source folder.
I have solved this issue by below steps:
Right click the Maven Project -> Build Path -> Configure Build Path
In Order and Export tab, you can see the message like '2 build path entries are missing'
Now select 'JRE System Library' and 'Maven Dependencies' checkbox
Click OK
Open Properties > Java Build Path for the project. Select the Source tab and use Add Folders to add source folders.
Remove the actual source folder definition in the build path and add a new source folder an name it src/main/java
If the package structure is setup as src.main.java.com.inventica, instead of com.inventica, that’s usually because under project properties > Java build path > Source, the source folder is setup as src instead of src/main/java. There’s no easy way to fix this, so remove src as a source folder and click ok.
Now Eclipse will show a folder hierarchy src/main/java. Browse to the java folder > right-click > build path > use as source folder.
After this, you may have to fix the Eclipse .project and .classpath files to have it use Maven to manage dependencies, builds etc.
Typically, you can copy this from a working project since there isn’t anything project specific here assuming you’re structured as a standard Maven project.
the problem will be solved by checking on 'JRE System Library' and 'Maven Dependencies' checkboxs Click OK. this is found in the project's 'build path option'
If you don't find the Included Path just add the path it will resolve.
Solution One:
Change the JRE version to 1.8 and change it back to the original version (for maven-archetype-webapp, the original version is 1.7).
Solution Two:
Check the JRE option and Maven Dependencies option in "Order and Export".
Simple solution would be create 'java' folder directly one the drive into src/main even before opening it in eclipse that way eclipse will not complain about the issue.
How to include (NOT ONLY reference) JAR file into existing project? I added it by using Project properties - Build path - add external jar's. But when I export my project, and then import it in another computer, this library was missing.
Drag it into your project view so it appears in the project as any other file.
Right-click the jar in the project view and add to build path.
Put your jars into a directory of your project e.g yourproject/lib so that external libraries are accessed through a relative path. And then use "Add JARs" option to add the jar to build path as in eboix's link.
You want to export your project as an archive (Export -> General -> Archive File), and then import your project as an existing project (Import -> General -> Existing Projects into Workspace). This way the project will be identical to the exported version and all of the configuration will be right.
Oh, and do what the other people suggest and copy the Jar file into the project so you don't have to reference it as an external Jar file (and everything is in one place).
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
I imported a jar file into workspace and this is the error I get:
Description Resource Path Location Type
Project 'Interpreter1' is missing required source folder: 'src' Interpreter1 Build path Build Path Problem
How can i get rid of this error?
Right-Click Project --> Build Path --> Configure Build Path; unselect the SRC, save, select again.
This solved my problem.
Go to the Build Path dialog (right-click project > Build Path > Configure Build Path) and make sure you have the correct source folder listed, and make sure it exists.
The source folder is the one that holds your sources, usuglaly in the form: project/src/com/yourpackage/...
Right Click Project -> New -> Folder -> Folder Name: src -> Finish
Here's what worked for me: right click the project-> source -> format
After that just drag and drop the source folder into eclipse under the project and select link.
good luck!
Edit your .classpath file. (Or via the project build path).
Right-Click Project --> Build Path --> Configure Build Path-->source-->(Select missing folder or path)-->Add Folder-->Apply-->Ok
Create the src folder in the project.
I was confused by this for hours.
Right click on project -> Build Path -> Configure Build Path -> Add Folder
One of the build path issue is it cannot find the correct /src/conf source folder. Right click on each project, Build Path > Configure Build Path. Under the Source tab, remove the folder with a red cross icon on the bottom right. It will work for the situation that there is a small red exclamation mark “!“ bedore your project name!
In eclipse, you must be careful to create a "source folder" (File->New->Source Folder). This way, it's automatically on your classpath, and, more importantly, Eclipse knows that these are compilable files. It's picky that way.
If you are facing an error with the folder, such as src/test/java or src/test/resources, just do a right click on the folder and then create a a new folder with the name being src/test/java. This should solve your problem.
I think it's because of the .classpath getting saved with the deleted source folder configuration.
Create the missing folder [ 'src' in your case] manually inside the root of the project. When I say manually, I meant outside Eclipse, using the file explorer.
Then, come back to eclipse and refresh the project. Now, the error saying it's already there will be gone.
Now, Right click on the project > Build Path > Configure Build path. It should take us to the Java build path side menu.
Make sure we are on the 'Source' tab. Delete the source folder causing the problem. Now, maybe the folder might show up in the project structure and you may delete that too.
Eclipse wouldn't let me point to an existing (or add a new) source directory.
Eclipse's configuration files can be wonky. In my case I should have started simple. Right click the project and click Refresh.
In my case eclipse reported this in the Problems view on the parent project which does not have any code. I just delete the error whenever it is reported on this parent project where src folder is really not needed.