I have two folders, src and test (for junit). When I export, the test fold开发者_如何学Goer 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 .
精彩评论