I'm using the Spring CommandLineJobRunner
to run a batch job from the command line (batch file). The job fails with a ClassNotFoundException
for classpath:/application.xml
. Earlier in the logs however it says it loaded 51 bean definitions for the same file.
Successfully loading beans:
[2015/12/30 13:43:37.838] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
Loaded 51 bean definitions from location pattern [classpath:/applicationContext.xml]
Exception:
[2015/12/30 13:43:40.136] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner]
No XML-based context named classpath:/applicationContext.xml. Trying class-based configuration.
[2015/12/30 13:43:40.138] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner]
Job Terminated in error: classpath:/applicationContext.xml
java.lang.ClassNotFoundException: classpath:/applicationContext.xml
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)
Relevant batch code to start job (applicationContext.xml
is in the config directory):
SET CURR_DIR=C:\OtherLines\JavaBatchTest\RUS
SET CONFIG_FILES=%CURR_DIR%\build\resources\main\com\rusbatch\config\
SET COMMON_LIB=%CURR_DIR%\lib\*
SET PROJECT_LIB=%CURR_DIR%\build\libs\*
SET LOG4J_CONFIG=%CURR_DIR%\build\resources\main\com\rusbatch\config\log4j.xml
SET LOG_PATH=%CURR_DIR%\logs\
SET JAVA_EXE="C:\Program Files\Java\jre1.8.0_65\bin\java.exe"
SET USER_CLASSPATH=%COMMON_LIB%;%PROJECT_LIB%;%CONFIG_FILES%
%JAVA_EXE% -Xms512m -Xmx1024M -DENV=UNIT -DSYSENV=U -cp %USER_CLASSPATH% -DLOG4J_CONFIG=%LOG4J_CONFIG% -DLOG_PATH=%LOG_PATH% org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/applicationContext.xml updateInspectionDateJob >> logs\%_JOB_NAME%.log
In response to Aurelien, changing from classpath:/applicationContext.xml
to applicationContext.xml
in the batch file does the following. Note the different stack trace and that the file name changed in both successful places of the log file:
Successfully loading beans:
[2015/12/30 14:39:27.834] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
Loaded 51 bean definitions from location pattern [applicationContext.xml]
Exception:
[2015/12/30 14:39:30.579] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner]
No XML-based context named applicationContext.xml. Trying class-based configuration.
[2015/12/30 14:39:30.581] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner]
Job Terminated in error: applicationContext.xml
java.lang.ClassNotFoundException: applicationContext.xml
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)
LOGS: View the log here