简体   繁体   English

Eclipse从构建路径中删除测试文件夹

[英]Eclipse removing a test folder from the build path

I have two folders, src and test (for junit). 我有两个文件夹,src和test(对于junit)。 When I export, the test folder gets packaged into the jar with JUnit which I don't want. 当我导出时,测试文件夹被打包到带有JUnit的jar中,这是我不想要的。 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. 我去了项目的构建路径,试图在'导出顺序'中取消选择'test'文件夹,但它不允许我取消选择它。

I then tried exclude the folder in the 'soruces' tab using * (everything), but then I got an error when I tried to export. 然后我尝试使用*(所有)排除'soruces'选项卡中的文件夹,但是当我尝试导出时出现错误。

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. 这就是我做的。

  1. right click on my project; 右键单击我的项目; choose Export 选择导出
  2. Choose Java/JAR file, Next. 选择Java / JAR文件,Next。
  3. List of projects in the workspace appears. 将显示工作空间中的项目列表。 Now expand the sub-tree of interesting project and select src folder only. 现在展开有趣项目的子树,只选择src文件夹。 The test folder should not be selected. 不应选择测试文件夹。
  4. continue creating jar file and see the result. 继续创建jar文件并查看结果。

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. 我也遇到了同样的问题,并最终通过将测试移动到一个单独的Eclipse项目中来解决它,将原始项目作为测试项目的构建路径依赖项。 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 没有测试类导出到jar或依赖项目

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). 现在,您可以指定不同的类目录(并且可能从导出中排除其中一个)。

In the project's Properties dialog (get there by right clicking the project and then click Properties), 在项目的“属性”对话框中(右键单击项目然后单击“属性”),
click Deployment Assembly on the left. 单击左侧的Deployment Assembly。
Eclipse will show all source folders. Eclipse将显示所有源文件夹。
Select the folder you wish to not be in your jar (/test) and click Remove. 选择您希望不在jar中的文件夹(/ test),然后单击“删除”。

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 在libraries选项卡中,将JUnit设置为仅对测试源可见

仅为测试源设置JUnit Visible

Export runnable jar 导出runnable jar

出口可运行的罐子

Tests and JUnit will not be packed into the jar. 测试和JUnit不会被打包到jar中。 In my case the jar is 1.8Mb smaller. 在我的情况下,罐子小1.8Mb。

右键单击文件夹>构建路径>从构建路径中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该从构建路径中排除源文件夹(在Eclipse中) - should I exclude source folder from build path (in Eclipse) 我应该将我的单元测试文件夹添加到Eclipse中的java构建路径吗? - Shall I add my unit test folder to the java build path in Eclipse? 将外部类文件夹添加到Eclipse中的构建路径 - Adding external class folder to the build path in Eclipse Eclipse-Maven:更新项目从构建路径中排除 src/main/resources 文件夹 - Eclipse-Maven: Updating project excludes src/main/resources folder from build path 将jar添加到构建路径后,jar从Eclipse中的libs(source)文件夹中消失 - 是bug还是我做错了什么? - Jar disappearing from libs (source) folder in Eclipse after adding it to build path - is it bug or my doing something wrong? 为什么在 Eclipse 中创建动态 Web 项目期间构建路径中缺少源文件夹 - Why source folder missing from build path during creating Dynamic Web Project in Eclipse 从eclipse构建中删除资源文件夹的排除? - Remove exclusion of resources folder from eclipse build? 从Eclipse的更深层文件夹执行Gradle构建 - Execute Gradle build from deeper folder in Eclipse Eclipse:从分发(jar)中排除(测试)文件夹 - Eclipse: Exclude (test) folder from distribution (jar) 从Eclipse构建路径中删除Junit - Remove Junit from eclipse build path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM