Eclipse:从分发 (jar) 中排除(测试)文件夹

Eclipse: Exclude (test) folder from distribution (jar)

假设我有一个简单的项目结构,将应用程序源与测试源分开,例如:

Project
  |-src
  |-test

我想使用 Eclipse 从可执行 jar 中排除 test 文件夹。

Eclipse 让您 select 创建 jar 时要包括哪些文件夹。它不允许您在创建 可执行 jar 时执行此操作。 在寻找解决方案时,我发现了以下建议
manually edit the ant buildor maven,
exclude test folders from classpath
moving test files to a separate project
edit the exported jar

虽然所有这些都可能有效,但这不是我要找的:配置 Eclipse 以执行此操作的简单方法。

(在 Netbeans 中,它非常简单地将源包文件夹与测试文件夹分开,请参见下图)

最好的方法是按照 maven Standard Directory Layout 并将您的项目设置为 mavengreadle 项目。

对于普通的 eclipse Java 项目,您可以在项目根目录中为您的测试创建一个新文件夹(例如:test)右键单击它并 select "add to build path" .

在即将推出的 Eclipse Photon (4.8) 版本中 a source folder can be marked that it contains test code可运行 JAR 文件 导出向导排除了此测试代码。

你可以download the milestone 5 (M5) of the Eclipse 4.8 SDK here and soon (probably Monday) also the Photon M5 Eclipse IDE packages here.