Use External log4j2 Properties on Java -cp Command - Stack Overflow

admin2025-04-26  4

I want to migrate an existing jar file to a consolidated server. I have the Jar, the existing log files, application.properties, and the sh file to trigger the Jar file to begin with. In the old server, the jar is triggered with this command:

java -cp /rheldedicatedserverappc/batch/routine_job.jar com.mycompany.anappC.RoutineJob

The problem is when I move it to new server, and recreate the log4j2.xml based on existing logs in new server it can't create logs, because it keeps looking for the path old server

Here's the run script

java -Dlog4j.configuration="/rhelconsolidatedserver/appc/batch/config/log4j2.xml" -cp /rhelconsolidatedserver/appc/batch/routine_job.jar com.mycompany.anappC.RoutineJob

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Properties>
        <Property name="LOG_DIR">/rhelconsolidatedserver/appc/batch/logs</Property>
    </Properties>
    <Appenders>
        <Console name="LogToConsole" target="SYSTEM_OUT">
            <PatternLayout
                pattern="[%d{dd-MM-yyyy HH:mm:ss}] [%-5p] [%X{processID}] [%c{1}] - %m%n" />
        </Console>
        <RollingFile name="LogToFile"
            fileName="${LOG_DIR}/oaapi-batch.log"
            filePattern="${LOG_DIR}/routine_job.%d{dd-MM-yyyy}.log.gz"
            ignoreExceptions="false">
            <PatternLayout>
                <Pattern>[%d{dd-MM-yyyy HH:mm:ss}] [%-5p] [%X{processID}] [%c{1}] - %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" />
            </Policies>
            <DefaultRolloverStrategy max="7" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="com.bca.oaapi" level="debug" additivity="false">
            <AppenderRef ref="LogToFile" />
            <AppenderRef ref="LogToConsole" />
        </Logger>
        <Root level="error">
            <AppenderRef ref="LogToFile" />
            <AppenderRef ref="LogToConsole" />
        </Root>
    </Loggers>
</Configuration>

What should I do without recreate the new jar?

转载请注明原文地址:http://anycun.com/QandA/1745599517a91002.html