简体   繁体   English

JAR 作为应用程序安装时不生成应用程序日志

[英]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.

相关问题 从 jar 运行我的应用程序时,我的 UI 设计器抛出 NPE 生成 JPanel - NPE being thrown from my UI designer generated JPanel when running my application from a jar 如何在Azure应用程序日志中记录由Java / Spring Boot应用程序生成的自定义应用程序日志? - How to log custom application logs generated by Java/Spring Boot app in Azure Application Logs? 如何检查Openshift Pod中安装的Java应用程序日志 - How to check Java application logs installed in Openshift Pod 没有为在Websphere Application Server 8上发布的Web Service生成日志 - Logs not getting generated for Web Service published on Websphere Application Server 8 如何监视安装在Cloud Foundry上的可执行jar应用程序 - How to monitor executable-jar application installed on cloud foundry 使用wlfullclient.jar在WebLogic 10.3.4上部署已安装的应用程序 - deploy already installed application on WebLogic 10.3.4 using wlfullclient.jar 取消部署应用程序时如何清除Tomcat日志 - How to clear Tomcat logs when undeploying the application 未从依赖的 JAR 应用程序生成日志文件 - Log file not getting generated from dependent JAR application 应用程序安装时的事件(Android) - Event when application gets installed (Android) Eclipse:编译依赖应用程序时导出JAR - Eclipse: Exporting JAR when compiling a dependent application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM