在 Eclipse 中从 jar 或 war 中排除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1489179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:57:23  来源:igfitidea点击:

exclude files from jar or war in eclipse

eclipse

提问by Jay

Is there a way to tell Eclipse to not include specified files, directories, or patterns in a JAR or WAR?

有没有办法告诉 Eclipse 在 JAR 或 WAR 中不包含指定的文件、目录或模式?

回答by Rich Seller

You can specify includes and excludes by opening the Project Properties (alt-enter) then opening Java Build Pathand the Sourcetab. Against each source location there is a little plus sign, click on that then select Includedor Excludedthen select the Edit...button.

您可以通过打开 Project Properties ( alt-enter) 然后打开Java Build PathSource选项卡来指定包含和排除。每个源位置都有一个小加号,单击它,然后选择包含排除,然后选择编辑...按钮。

source path screenshot http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.user/gettingStarted/images/qs-WorkingWithExistingLayout26.png

源路径截图 http://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.user/gettingStarted/images/qs-WorkingWithExistingLayout26.png

You can then specify multiple patterns for files to be included/excluded. These files will not be processed to the output directory. The patterns follow Ant's wildcard patternsso you have quite fine-grained control over what to include.

然后,您可以为要包含/排除的文件指定多个模式。这些文件不会被处理到输出目录。这些模式遵循Ant 的通配符模式,因此您可以非常精细地控制要包含的内容。

include patterns screenshot
(source: eclipse.org)

包括模式截图
(来源:eclipse.org

回答by Max Rydahl Andersen

We fought with this problem too and didn't find a good standard solution for it in Eclipse WTP.

我们也解决了这个问题,但在 Eclipse WTP 中没有找到一个好的标准解决方案。

Hence we added Project Archives to JBoss Tools (http://jboss.org/tools) which allow you to control explicitly via "ant filter sets" what goes in and what goes out of your archive. This archive you can then deploy with the standard WTP mechanism for deployment on the server types supplied by JBoss tools.

因此,我们向 JBoss 工具 ( http://jboss.org/tools)添加了项目档案,它允许您通过“蚂蚁过滤器集”明确控制进入和退出档案的内容。然后,您可以使用标准 WTP 机制部署此存档,以便在 JBoss 工具提供的服务器类型上进行部署。

We are working on adding similar support back into native Eclipse WTP, but that won't be available until sometime next year.

我们正在努力将类似的支持添加回原生 Eclipse WTP,但要到明年某个时候才能提供。

回答by windsor

to add to what @Rich_Seller said: in Eclipse Indigo:

添加到@Rich_Seller 所说的内容:在 Eclipse Indigo 中:

  • Select your package from the package view right click, and choose Export.
  • Choose Java -> JAR file from the "select an export destination" tree.
  • Click Next to go to the next page of the wizard.

  • Under the "Select the resource to export" you are presented with a tree view here you can select and deselect components that will be included and excluded from the JAR.

  • 从包视图中右键单击选择您的包,然后选择导出。
  • 从“选择导出目标”树中选择 Java -> JAR 文件。
  • 单击下一步转到向导的下一页。

  • 在“选择要导出的资源”下,您会看到一个树视图,您可以在此处选择和取消选择将包含和排除在 JAR 中的组件。

回答by Pablo Jomer

I think including an XML file in another and then removing its visibility in the war file should give you an on off switch.

我认为在另一个文件中包含一个 XML 文件,然后在 war 文件中删除它的可见性应该会给你一个开关。