[英]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. 这就是我做的。
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: 我知道这是一个解决方法,而不是直接解决问题的方法,但对我而言,它似乎是所需解决方案的最佳近似值:
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设置为仅对测试源可见
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.