[英]Application logs not generated when JAR installed as an application
I have a java application with log4j configured to log application logs.我有一个 java 应用程序,其中 log4j 配置为记录应用程序日志。 When i run it as java -jar the application logs are generated.
当我以 java -jar 运行它时,会生成应用程序日志。 But the i need to distribute the same application as windows installer so i used Launch4j and converted the JAR to an exe file.
但是我需要分发与 windows 安装程序相同的应用程序,所以我使用 Launch4j 并将 JAR 转换为 exe 文件。 Then i used the exe file with Inno Setup to create a windows installer with JDK packaged in the installer.
然后我使用带有 Inno Setup 的 exe 文件创建了一个 windows 安装程序,JDK 打包在安装程序中。 The application could be installed successfully under Program Files (x86)and running fine.
该应用程序可以在 Program Files (x86) 下成功安装并且运行良好。 But the application logs are not generated.
但不会生成应用程序日志。 When i created the JAR, during that packaging itself the log4j.xml is included in the JAR.
当我创建 JAR 时,在打包过程中 log4j.xml 包含在 Z529E363425C8C9BFAAD07 So, it was part of the exe created by launch4j.
因此,它是由 launch4j 创建的 exe 的一部分。 The log4j.xml configuration is as below:
log4j.xml配置如下:
`<appender name="DD_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="Append" value="true" />
<param name="MaxFileSize" value="10MB" />
<param name="File" value="logs/rolling_app.log" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd hh:mm:ss}:%p %c{2} [%L] %x - %m%n" />
</layout>
</appender>`
I tried adding system variable as -Dlog4j.configuration=log4j.xml in launch4j but no logs were generated.我尝试在 launch4j 中添加系统变量为 -Dlog4j.configuration=log4j.xml 但没有生成日志。
Thanks in advance for any pointers.在此先感谢您的任何指点。
The relative path didn't work due to the reason as creating of file under the program files folder need administrator rights.由于在程序文件夹下创建文件需要管理员权限,因此相对路径不起作用。 This was further proved by the logs generating under the app folder when i start the application as Administrator.
当我以管理员身份启动应用程序时,app 文件夹下生成的日志进一步证明了这一点。 In log4j, i gave the full path as C:/logs/ and created logs folder under C drive.
在 log4j 中,我给出了 C:/logs/ 的完整路径,并在 C 驱动器下创建了日志文件夹。 Now application log file is generated in normal start mode.
现在应用程序日志文件在正常启动模式下生成。 As i can't expect the application to be started in administrator mode, i would be configuring a path outside of Program Files folder.
由于我不能期望应用程序以管理员模式启动,因此我将在 Program Files 文件夹之外配置路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.