Eclipse removing a test folder from the build path - java

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 .

Related

How do I get IntelliJ's Project Files view to show the packages and directories in the source folders?

I can't seem to figure out how to get IntelliJ to show the directories under src/main/java and src/main/resources. I've tried to delete my .idea file and reimport the project but that did not help. If you notice in the first image below, there is no arrow next to these source folders. The second image is what my source folders look like when I go to File > Project Structure > Modules. I see all of the directories/packages in the second picture, but I want to be able to navigate to them in the Project Files section.
How do I correct this?
Found the answer, just in case anyone else runs into this problem.
FYI, I'm on a Mac.
Go to File > Project Structure.
Make sure you are under the "Modules" section (under Project Settings on the left).
Select/Single-click the module that is giving you issues.
Click the minus sign above the module to delete the module (this will not delete the module from disk).
After deleting the module, add the project/module back again by going to the same place as before, but clicking the plus sign instead of the minus.
I think my particular issue is when I originally added my project and modules, I selected a specific Maven profile and for some reason IntelliJ wasn't allowing me to see my sub-directories under my source files in my project files view.

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

Build path entry is missing: /src/test/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

Add .jars in alternative folder

I am new to Eclipse and Java, and I know that .jar files I need to add into libs derectory so that compiler could recognize them. How I can add .jars not only in libs folder but also in other folder too. How can I configure Eclipse to do that?
It's easiest if you have the jar files visible in the package explorer to start with, i.e. within your project directory. At that point, you can just right-click on the jar file, go to the "Build path" section of the context menu, then select "Add to build path".
If the jar file is elsewhere and you don't want to move it, you can right-click on the project, and under the "Build path" part of the context menu, select "Add external archives...". Then find the jar file in the file browser, and hit OK.
All of this can also be done from the project properties dialog, in the Java Build Path section.
Right Click project
Select Properties
Select Java Build Path
Under Tab Libraries Click on add jars or add external jar to add the required jars
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items:
Code in the source folders
Jars and classes folder associated with the project
Classes and libraries exported by projects referenced by this
project
Our goal is to feed our classes with the dependent classes present in the jars during compile time. Eclipse provies with number of easy ways to do it .Here you can find a good article about how to add the jars in the projects with screenshorts attached to it http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

eclipse and SVN adding jar files

I'm trying to make modifications to the trunk found at https://wafle.svn.codeplex.com/svn SVN repository location. The way that I did this in Eclipse was that I used Subclipse, added a new repository location, then opened up the project and right clicked on the trunk. Then I clicked "checkout" and checked it out as a new Java project. Then I found the folder containing the source code that I want to change and recompile and I used Build Path->Make source folder. Next, I realized that I needed 190394994 jar files that were all in different places under the project's "Third Party" folder. So I used Build Path->Configure Build Path in Eclipse, then individually added each jar I needed through "Add External Jars".
My question is; did I do all of this right, and is there something I could have done more easily, such as import all the jars at once instead of individually clicking each?
Thanks.
I'm guessing that you are embellishing a little and didn't add 190 million jar files by hand. (Even at 1 jar click per second, you would be going nonstop for 2,200 days.) Incidentally, you can shift-click and choose many jars from the same directory.
The secret is in the .classpath file; that is where the build path is stored. Someone before you has probably created a fully-orbed .classpath file and stored it in SVN.
If you created this as a new Java project, it will begin with a very simple .classpath with the folder for your project's class files and the JRE. (Apparently, SVN does not overwrite it with the .classpath or you chose not to merge your local version with the one from SVN.)
Next time, you might want to overwrite your project's .classpath with that fully-orbed one on SVN. Refresh and look at the Build Path. They should be all there and in place.
First thing: rajah9 is exactly correct - there is a .classpath file already.
You just got a little hung up on a really odd svn repo layout. the java stuff is mixed in with the .net stuff. Check out the trunk and then do a file > import... then select general > existing projects into workspace. You'll want to select the Source/JNAWindowsAuthProvider/ folder.
There is already a .classpath that references the jars in the ThirdParty folder. (not quite 190 million)
Second thing: when you added the jars as external jars, it makes an absolute path to the jar file. you want to always avoid that, if you hit the add jars button it will be a relative path.

Categories