0

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

tfbbt8
  • 325
  • 4
  • 13
  • 1
    http://stackoverflow.com/a/27253204/3166303 – leeor Dec 30 '15 at 20:13
  • Have you tried without "classpath:/" instruction in front of applicationContext.xml ? – Aurelien Dec 30 '15 at 20:32
  • @Aurelien I have, edited question with the slightly different behavior. What stumps me is that the same file name is used in two places yet it is successful in the first use. – tfbbt8 Dec 30 '15 at 20:48
  • Could you try to change the name of applicationContext.xml to jobContext.xml ? Maybe the applicationContext.xml successfully loaded by org.springframework.beans.factory.xml.XmlBeanDefinitionReader is inside one of your dependency jar and it is not the one you are expected. – Aurelien Dec 30 '15 at 21:17
  • Changed to jobContext.xml and passed it as the argument to CommandLineJobRunner. The file name changed for both the successful bean loading and the exception with otherwise the same stack trace as after the edit made above. – tfbbt8 Dec 30 '15 at 21:25
  • Can you post your full log so we can understand the context of where these messages are coming from? – Michael Minella Dec 30 '15 at 21:51
  • Edited: added link to logs – tfbbt8 Dec 30 '15 at 22:17
  • Did you take a look at the link in the first comment? – Gergely Bacso Dec 30 '15 at 22:47

0 Answers0