maven


Error in running a spring batch war file


I have created a spring batch project and created a war file for the same using maven
<modelVersion>4.0.0</modelVersion>
<groupId>com.batch</groupId>
<artifactId>dms-batch-app</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>dms-batch-app Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jdk.version>1.8</jdk.version>
<spring.version>4.0.6.RELEASE</spring.version>
<spring.batch.version>3.0.7.RELEASE</spring.batch.version>
<quartz.version>1.8.5</quartz.version>
<build>
<finalName>dms-batch-app</finalName>
</build>
I am able to generate a war file but when i deploy on the tomcat server and start the tomcat application it throws the below error
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/jar:file:org/springframework/batch/core/schema-drop-mysql.sql]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jar:file:org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/jar:file:org/springframework/batch/core/schema-drop-mysql.sql]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jar:file:org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:441)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:208)
at org.springframework.jdbc.datasource.init.CompositeDatabasePopulator.populate(CompositeDatabasePopulator.java:61)
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:49)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:108)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:93)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 25 more
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/jar:file:org/springframework/batch/core/schema-drop-mysql.sql]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:132)
at org.springframework.jdbc.datasource.init.ScriptUtils.readScript(ScriptUtils.java:278)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:438)
... 32 more
I am connection to a database in the context xml as shown below
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
</jdbc:initialize-database>
But as per the error the war is not able to read from the jar file. Also i modified the same and kept the ddl scripts under resources folder , yet the war again goes to pick the ddl scripts from the jar file itself.
Kindly provide a solution to this.
And , what will be a better option , deploying spring batch project as a jar file or as a war file ?
Kindly help.
Try this versions:
<jdbc:script location="/org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="/org/springframework/batch/core/schema-mysql.sql" />
<jdbc:script location="classpath:/org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="classpath:/org/springframework/batch/core/schema-mysql.sql" />
<jdbc:script location="jar:file:org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="jar:file:org/springframework/batch/core/schema-mysql.sql" />

Related Links

Hg : join many repositories into a single one
Artifact has not been packaged yet - maven-dependency-plugin
how to make a automation testing framework
Maven module dependency and resources
Permission denied error
Apache Maven Error : Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom: 2.5 to central
Replace tokens from one file to another using Ant script
How to run all the test files and trigger test using maven-surefire plugin
Execute a separate Java process in the classpath of a module
How to trigger distribution module when rebuilding sub module in Maven?
java.nio.file.InvalidPathException: Illegal char <:> at index 4: http://central.maven.org/maven2/org/jboss/weld/servlet/weld-servlet/2.1.2.Final
Openshift deploy with additional Maven command line options
netbeans 8 aspectj perf4j and maven
Adding all jars from a Nexus repo to Leiningen dependencies list
Hadoop Maven Dependencies for MapReduce
Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path with maven and spring boot

Categories

HOME
maven
fft
umd
echarts
android-youtube-api
webrequest
synchronization
adfs
virtualization
applepay
medical
offline
floating-action-button
handsontable
u-sql
mapserver
remote-access
fortumo
visual-studio-cordova
zebra-printers
workload-scheduler
fatal-error
windows-7-x64
ef-migrations
ab-testing
interop
alpine
xlsxwriter
facebook-instant-articles
android-widget
buildbot
selectedindexchanged
phpfox
fluentvalidation
nat
karaf
language-concepts
fusionpbx
overriding
revolution-slider
file-format
simplexml
retina-display
space-complexity
neuroscience
mixture-model
ssjs
powershell-dsc
jsch
filepicker
react-scripts
clean-architecture
hls.js
togetherjs
nativeapplication
media-player
gstreamer-0.10
skype4py
apachebench
asp.net5
energy
hsv
vhd
sframe
drawbitmap
sankey-diagram
jsapi
system.reflection
cctv
neolane
ceil
bundles
google-cloud-save
web2py-modules
dbconnection
html4
free-variable
rdoc
multipage
labwindows
nsdatecomponents
gnustep
horizontal-accordion
appendto
mysql-error-1005
web-application-design
ncqrs
sector
ugc
multiple-languages
wsdl.exe

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App