Build path entry is missing: /src/test/java - java

While running my java project on Eclipse Luna, I have some errors due to which I suppose related to this problem.I right click on the project, choose properties --> java build path --> source, I see a warning at the top:
And it seems that I have forgotten to add this package at the beginning of my project.I want to add it now, but I cannot do it via "Add Folder" button.When I press "Add Folder" button, a window appears like this one:
However, I believe I should add it under "Java Resources" on the tree:
How can I modify this?
Thanks for any help..

src/test/java is just maven's default entry for any test classes. If you have (or plan to have) test classes, you can create a new folder structure test/java below your src folder and afterwards select it in the dialog you've shown. If you don't plan to have any test classes, you can safely remove the entry from the build path.

This worked for me:
mvn clean install

How to add missing src/test/java folder to the maven project in Eclipse
1) Create a folder test/java under src folder
2) Right click on the project and choose Maven --> Update Project --> choose for Force update of Snapshot/Releases and click ok. Now test folder should appear as src/test/java in Eclipse project explorer

Related

Is there any alternate to acquire dependencies without using POM.xml?

My question is, I don't want to write XML code for dependencies in the POM.xml again and again.
For example, I want to use the log4j JAR in my project. instead of writing XML code is there any option to download the related JAR files?
Alternate method is downloading the jars from sites like maven or java2s.com and add them to your build path.
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.
Hope that helps
Of course you can download (or copy) these jars, and then manually add them to your build path.
For instance in eclipse, you can select all the libraries under the "Maven Dependiences" and copy them to other folder eg. in other project. Then you need to select these libraries and using the right mouse button add them to build path, done :)
You do not need to write them again and again. You can define and install a parent pom with the common dependencies you use and refer to it in each project pom.
First you could download jars you need in your project from corresponding websites.
Next,follow the steps below:
Step 1: Create a folder under the project to save the JAR package.We usually store jar packages from the outside in the [lib] folder.
Step 2: Copy the jar to the lib folder.
Step 3: Right-click on the project name, and select it in turn [Build Path] - > [Configure Build Path...]
Step 4: In the open window, select the Libraries page and click on the right button the [add JARs...] then select the jar package we just copied into the project, and then click [OK] to close the window.
Finally, we can use this jar package in Eclipse
Yes you can add them through the java build path from your IDE. However, I would recommend that you add these jars as dependencies in the pom.xml and build your project through maven. This will make sure that you will not run into any error regarding the missing dependencies in case any jar gets deleted accidentally or if you want the same set of jars for a new project. And understanding a pom.xml is not a difficult task

"Source folder is not a Java project" error in eclipse

I am trying to import maven project into eclipse 4.2 version.Its not importing the project properly. Its giving me error "Source folder is not a Java project" while I am trying to create a new call in it. Even ctrl+mouse click is also not working. I don't understand the problem. Even when I right click on project and select build path it shows me no action available. Anyone face the same issue
In the maven project directory try
mvn eclipse:eclipse
that may do the trick.
I ran into the same issue and fixed it by converting my project to faceted form.
Right click your project > Properties > Project Facets > Convert to Faceted Form, and select Java.
I had the same problem... But you just need to update "source Folder" to correct source "src/main/java" from whatever mentioned in the pop up:
[]
Either turn your project into Eclipse project, using mvn eclipse:eclipse, or install Maven Integration for Eclipse plugins, like m2eclipse, and import project as a Maven project.
I got the same error in a slightly different context (Indigo with m2eclipse):
I imported a multi-module (1 jar module and 1 war module) maven project into Eclipse. Everything worked fine (clean, install OK) until I tried to add a new class to one of the modules and got the "Source Folder is not a Java project" error.
I solved this by opening the properties on the parent project and selecting the following Project Facets:
Java
Dynamic Web Module
This solved the problem. My guess is that, because the parent project for a multi-module project has pom packaging (<packaging>pom</packaging>), Eclipse doesn't know what kind of projects the parent project encloses (i.e. if the packaging were jar, it would know that it's a java project; if the packaging were war, it would know that it's a static or dynamic web module, etc.)
This is just my guess, but the fix worked for me, and it makes sense.
for those who already see java selected, uncheck and check it again.
select apply to override the existing setttings. finally it works !
Right click your project > Properties > Project Facets > Convert to Faceted Form, and select Java
Right click your project > Maven > Update Project
This step will add your project so the issue resolves easily.
mvn eclipse:eclipse
will resolve this problem. convert to maven project.
I had this error because I tried to create a new Project by doing "Ctrl+N", typing "Project" on the Wizard's input label and then just pushing "Enter" until it was created.
I solved this by typing "Java Project" instead of just "Project".
You can also create a JAVA PROJECT by going to File > New > Java Project.
open cmd and run the following command in the folder of your project-
mvn eclipse:eclipse
This did the trick for me
If you are having maven project and you are getting this error. You can follow below steps.
Right click on the project and select properties.
Then click on Project Natures
In the dialogue box, click on Add and in the warning click on OK.
Filter java in the popup box and click on OK.
Click on apply and close.
It will add java nature to your maven project and you will not get this error anymore.
Right click your project > Properties > Project Facets > Convert to Faceted Form, select Java, and apply&close

How to achieve that Eclipse clean and build (aka rebuild)?

I deleted my ./bin folder in an Eclipse Indigo (super similar to Helios), and now I am wondering how to rebuild my Java project. I just cannot find a button like we can see in Netbeans.
For Eclipse you can find the rebuild option under Project > Clean and then select the project you want to clean up... that's all.
This will build your project and create a new bin folder.
In Eclipse there is an "Auto Build" option, which is checked by default. When it is checked, you don't need to build your project, this happens automatically. If this behaviour is unwanted, uncheck this option and click build project whenever you want.
To clean a project, select Clean Project. This will delete the bin folder, however if Auto build is checked, it will be immediatelly regenerated.
In case you are unable to find a file in Eclipse code after pulling code from git or creating a file in intelliJ seperately (my case) you ca do the following
Right click on 'src' folder and in the menu that appear click on the 'refresh' button

Eclipse Java Missing required source folder: 'src'

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.

Eclipse removing a test folder from the build path

I have two folders, src and test (for junit). When I export, the test folder gets packaged into the jar with JUnit which I don't want. I went to Build Path for the project an tried to deselect the 'test' folder in 'order of export' but it does not allow me to deselect it.
I then tried exclude the folder in the 'soruces' tab using * (everything), but then I got an error when I tried to export.
How do I exclude my test folder from the export?
I have just did it and it worked fine for me. Here is what I did.
right click on my project; choose Export
Choose Java/JAR file, Next.
List of projects in the workspace appears. Now expand the sub-tree of interesting project and select src folder only. The test folder should not be selected.
continue creating jar file and see the result.
I also met the same problem and eventually resolved it by moving the tests into a separate Eclipse project, placing the original project as a build path dependency of the test project.
I know this is rather a workaround than a desired direct solution of the problem, but to me it looks like the best approximation to the desired solution:
test code separation achieved
possibility to test package-private class members is still there
no test classes exported to jars or dependent projects
The only drawback is that an extra project needs to be created.
I think you first need to segregate the test classes into another build directory.
You can specify the build output directory for every source folder: Go to "Configure Build Path >> Source Tab". Check "Allow output folders for source folders". Now you can specify different classes directories (and presumably exclude one of them from an export).
I have found a way.
Put all your test code in a separated folder and set "Contains test sources" to "Yes"
In the libraries tab, set JUnit to be visible for test sources only
Export runnable jar
Tests and JUnit will not be packed into the jar. In my case the jar is 1.8Mb smaller.
In the project'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 folder you wish to not be in your jar (/test) and click Remove.
Right Click on the folder > Build Path > Remove from build path .

Categories