I have a Java Gradle application that logs correctly during development, but does not work correctly when it is distributed.
When I run the program in my IDE (IntelliJ if that is relevant) the logging is formatted correctly, however, when I run "./gradlew distZip" and use the distributed software on our production server it does not create a log file and looses the logging.properties configuration it should have.
The logger pulls input from my logging.properties into LogManager, creates a handler with a simple formatter (configured in logging.properties), and adds the handler to the logger:
LogManager.getLogManager().readConfiguration(
new FileInputStream("./src/main/java/logging/logging.properties"));
FileHandler handler = new FileHandler("myLog.log", FILE_SIZE, 4, true);
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);
When I run this in IntelliJ I get a set of output files: myLog.log.x and log entries in those files match the properties I created:
[2022-07-12 09:26:32] [INFO] APPLICATION: Setting up application
[2022-07-12 09:26:32] [INFO] Starting server on port: 8080
[2022-07-12 09:26:32] [INFO] Updating data from API
...
When I run the bat file from the distribution it logs to the terminal and gives an IO error:
Jul 12, 2022 12:53:09 PM logging.ApplicationLogger getLogger
SEVERE: .\src\main\java\logging\logging.properties (The system cannot find the path
specified)
I think this makes sense, since the distributed bat file doesn't know about the development file structure. What I don't know, is how to compensate for whatever "./gradlew distZip" does to the file structure. I tried adding the logging.properties file to the distribution as an additional file, but that didn't work.
How do I reference my logging.properties file so that it is found by my distribution?