简体   繁体   English

打包在不同的OS中时,java.util.Logger的行为有所不同

[英]java.util.Logger behaves differently when packed in different OS

I run a java program from a jar file in Linux Redhat 4.3 and use eclipse for creating the jar file from my project. 我从Linux Redhat 4.3中的jar文件运行Java程序,并使用eclipse从我的项目中创建jar文件。

If I create the jar file when running eclipse in linux everything is ok (normal logfile name and normal text format in the logfile). 如果我在Linux中运行eclipse时创建了jar文件,则一切正常(日志文件中的常规日志文件名和常规文本格式)。

However, if I create the jar when running eclispe under WinXP (and send it to my linux server via ftp) the logfile name is java0.log.0 and the text inside is in XML. 但是,如果我在WinXP下运行eclispe时创建了jar(并将其通过ftp发送到我的linux服务器),则日志文件名为java0.log.0,并且其中的文本为XML。

one more thing - my program uses SimpleFormatter as the formatter for the log file. 还有一件事-我的程序使用SimpleFormatter作为日志文件的格式化程序。

any ideas? 有任何想法吗?

java.util.logging.FileHandler will log by default as XML. 默认情况下, java.util.logging.FileHandler将以XML记录。 So I wonder if you're not specifying the path to your logging configuration properly. 因此,我想知道您是否没有正确指定日志记录配置的路径。 Thus it'll work on Linux, but not on Windows. 因此,它将在Linux上运行,但不能在Windows上运行。

How are you creating the Jar file "in eclipse"? 您如何“在Eclipse中”创建Jar文件? Are you using Eclipse's Export -> Java -> JAR File? 您是否正在使用Eclipse的Export-> Java-> JAR File? Or are you running an ANT or Maven script through Eclipse? 还是您正在通过Eclipse运行ANT或Maven脚本?

If you're just exporting from Eclipse directly - I'd recommend using ANT or Maven to get a repeatable build process not tied to the IDE. 如果您只是直接从Eclipse导出-我建议您使用ANT或Maven来获得不依赖于IDE的可重复构建过程。

If you're building from ANT or Maven, I'd check for local configuration overriding something to do with logging in the build script. 如果您是从ANT或Maven构建的,我会检查本地配置是否覆盖与登录构建脚本有关的内容。

It may also be that there's a platform specific path embedded in the application or build script and your log4j properties file isn't being found, so log4j is just going with defaults. 也可能是在应用程序或构建脚本中嵌入了特定于平台的路径,并且未找到您的log4j属性文件,因此log4j仅使用默认值。 Though, I'm not sure if XML formatting and the log file name format you specified is the default. 不过,我不确定您指定的XML格式和日志文件名格式是否为默认格式。

您的计算机可能使用了不同的JAVA编译器版本-也许在版本之间存在不同的默认行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM