在 Eclipse 中放置 config.properties 和 log4j.xml 的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9942386/
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-19 17:56:22  来源:igfitidea点击:

where to put config.properties and log4j.xml in Eclipse

javaeclipselog4jclasspathconfiguration-files

提问by mitchmcc

When I first developed my Java app, I ended up with my config.properties and log4j.xml files in the 'src' directory. This worked fine running in Eclipse, but now I am trying to deploy to a Linux server.

当我第一次开发我的 Java 应用程序时,我的 config.properties 和 log4j.xml 文件最终位于“src”目录中。这在 Eclipse 中运行良好,但现在我正在尝试部署到 Linux 服务器。

When I deploy, I take the exported app jar file and explode it, but it of course does not have the 'src' directory.

当我部署时,我获取导出的应用程序 jar 文件并将其分解,但它当然没有“src”目录。

When I move the two config files back to the root of the app, log4j is complaining that it cannot find the log4j.xml file.

当我将两个配置文件移回应用程序的根目录时,log4j 抱怨它找不到 log4j.xml 文件。

I have tried to set the Run/Debug classpath as noted in several posts, but the Classpath tab already appears to show the app's main directory there.

我已尝试按照几篇文章中的说明设置运行/调试类路径,但“类路径”选项卡已出现在那里显示应用程序的主目录。

What I need is to understand how I should lay out things like these two configuration files in Eclipse, so that when I export to a jar for deployment they are still visible.

我需要的是了解我应该如何在 Eclipse 中布置这两个配置文件之类的内容,以便当我导出到 jar 进行部署时,它们仍然可见。

Thanks,

谢谢,

Mitch

米奇

回答by jaspreet

Place the log4j.xml on src/main/resources in eclipse. It should work.

将 log4j.xml 放在 eclipse 中的 src/main/resources 上。它应该工作。

回答by abhiroop

You have to add a line.

您必须添加一行。

 Log4jConfigurer.initLogging("SpringTest/src/log4JTest/log4j.xml");

to inform log4Jthat from here it should pick all custom info.

通知log4J从这里它应该选择所有自定义信息。

回答by Kuldeep Jain

If you have placed your log4j.xmlor log4j.propertiesfile in your srcfolder then it should work fine for the exported jar file as well. You could have a look this postwhich is similar.

如果您已将您的log4j.xmllog4j.properties文件放在您的文件src夹中,那么它也应该适用于导出的 jar 文件。你可以看看这篇类似的帖子

回答by Alonso Dominguez

maybe configuring it as "classpath:log4j.xml" in your applicationContext.xml is enough, or, if it is not what you really want I suggest you to take a look about how to set it up using the approach of a Log4jDirectConfigurer.

也许在 applicationContext.xml 中将其配置为“classpath:log4j.xml”就足够了,或者,如果这不是您真正想要的,我建议您看看如何使用Log4jDirectConfigurer.