Eclipse:如何在构建中包含文件,但不在导出中

发布于 2025-01-21 07:14:26 字数 886 浏览 0 评论 0原文

在Eclipse中,我知道如何通过将其添加到构建路径中来包含其他文件。而且我知道如何通过在随附的文件夹上添加/排除过滤器来将文件排除在构建中。但是我要弄清楚的是如何组合两个组合,例如在构建中包含文件,而不是导出中的文件。而且我想在没有蚂蚁,毛过等的情况下这样做。

这就是情况:

我有一个简单的Java项目。它包括一个属性文件,其中包含服务器的登录信息。我想要一个将此文件包含在类路径中的构建,以便在我在Eclipse中开发和调试时找到它。但是,当我准备出口可运行的.jar时,我希望它排除此文件,因为它是安全风险等。

为了讨论,让我们假设该项目结构:

MyProject
    +----bin
    +----lib
    +----src
    +----resources
             +----application.properties
             +----version.properties

理想情况下,我希望构建和导出忽略application.properties,但包括版本。然后在运行时间(无论是在Eclipse& rounnable .jar中),我希望该应用程序能够在资源/文件夹中找到应用程序。

不起作用:

我尝试了一些变体,例如在构建路径中包含“资源”文件夹,但不包括应用程序。

解决方案?

我怀疑这从根本上不能在Eclipse中完成,因为它似乎要求该文件同时在buildpath上同时进行。

我知道我可以打开.jar并删除文件。这可能是我最终得到的,但是我宁愿为那些追随我的人提供更清洁的解决方案。这似乎是一个常见的情况 - 配置文件一直排在jar之外,但仍在构建路径上。你们其他人如何处理这个?

In Eclipse, I know how to include additional files in a build by adding them to the Build Path. And I know how to exclude files from a build by adding include/exclude filters on the included folder. But what I'm trying to figure out is how to do a combination of the two such as include a file in the build but not in the export. And I want to do this without Ant, Maven, etc.

Here's the situation:

I have a simple Java project. It includes a properties file with logon information for a server. I want a build that will include this file in the classpath so that it is found while I'm developing and debugging in Eclipse. But, when I'm ready to export a runnable .jar, I want it to exclude this file because it's a security risk, etc.

For sake of discussion let's assume this project structure:

MyProject
    +----bin
    +----lib
    +----src
    +----resources
             +----application.properties
             +----version.properties

Ideally, I'd like the build and the export to ignore application.properties but include version.properties. Then at run time (both in Eclipse & from runnable .jar) I'd like the app to be able to find application.properties in the resources/ folder.

Doesn't work:

I've tried some variations like including the "resources" folder in the build path but excluding application.properties, But this seems to also prevent application.properties from being found at runtime.

Solutions?

I suspect that this fundamentally can't be done in Eclipse alone as it seems to require the file to be simultaneously both on and not on the buildpath.

I know that I can just open the .jar and remove the files. This is probably what I'll end up with, but I'd rather have a cleaner solution for those who come after me. This seems like it would be a common scenario -- configuration files kept out of a jar but kept on the build path. How do you others handle this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2025-01-28 07:14:26

添加您需要的东西在本地运行,并且不应将其包含在jar (tab 依赖项),而不是项目的java构建路径

Add the things you need for running locally and that should not be included in the JAR to the launch configuration (tab Dependencies) instead of to the Java Build Path of the project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文