如何使用 Maven 将文件添加到类路径而不添加到 jar 中?
我想向类路径添加一些配置(由 maven-jar-plugin 生成),但我不希望它们位于 jar 内,而是位于外部文件夹中。这样我就可以编辑配置而无需重新打包。 我找到了一个解决方案 如何使用 exec 插件执行应用程序时添加类路径条目,但是有没有更简单的解决方案?
或者也许我错了,这是一个不好的模式 - 将配置存储在类路径中但在 Jar 之外?也许最好将应用程序配置存储在用户的主目录中并在运行时将它们添加到应用程序中?
例如,我想允许最终用户编辑 log4j.properties 和翻译。
问候,
I want to add some configs to the classpath (generated by maven-jar-plugin), but I don't want them inside a jar, but in an external folder. That way I'll be able to edit configs without repackaging.
I found one solution How to add a classpath entry when executing the app with exec plugin but is there a less complicated solution?
Or maybe I'm wrong and it's a bad pattern - storing configs in the classpath but outside a Jar? Maybe it's better to store app configs in the user's home directory and add them to the app at runtime?
For example I want to allow the end user to edit log4j.properties and translations.
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议有一个默认位置来查找应用程序配置(例如用户主目录,如您所建议的),但允许用户提供 agrument/System 属性来覆盖此位置。在我看来,假设查看类路径并不是最好的解决方案,因为类路径的概念对于大多数用户来说是相当陌生的,甚至对于某些程序员来说很难确定。
I'd suggest having a default location that it looks for the app configs (e.g. user home directory, as you suggested), but allow the user to provide an agrument/System property to override this location. Assuming to look on the classpath is not, in my opinion, the best solution, since the concept of a classpath is a fairly alien thing to most users, and can even be hard to determine for some programmers.
我认为 Melv 是对的 - 最好将配置存储在主目录中并提供更改它的能力,但如果有人需要向类路径添加某些内容 - 您只需将以下代码添加到.
如果声明
true
,那么依赖类路径也会被添加。I think that Melv are right - better to store configs in Home directory and provide ability to change it, but if someone need add something to classpath - you just can add following code into
<configuration><archive>
.If you declare
<addClasspath>true</addClasspath>
, then dependency classpaths also will be added.