|
|
Running JobRegistryBackgroundJobRunner
Hi all,
recently I discovered spring-batch and decide to give it a try. After few pitfalls (something I discovered by myself, something with a help of you guys) I finally manage to make it work in my case.
To make long story short currently I am dealing with how to pack this background service in a JAR file and to make simple service_name.sh in order to make it work like a charm.
Currently my code is executing from Eclipse IDE, I made Java Application and configured it like this:
Main class is: org..batch.core.launch.support.JobR egistryBackgroundJobRunner
and Programm arguments are: com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/applicationContext.xml com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/fakeProfilesJob.xml
and if I run it from IDE it works.
Now I want to pack it up in JAR file, to have lib directory to hold all necessary maven dependencies and of course to have one sh script that will simulate 'Run' button from IDE.
So I've decided to give it a try with maven-jar-plugin and maven-assembly-plugin and first of all I have following sections in pom.xml
JAR plugin:Code:
lt;plugingt; lt;groupIdgt;org.apache.maven.pluginslt;/groupIdgt; lt;artifactIdgt;maven-jar-pluginlt;/artifactIdgt; lt;configurationgt; lt;archivegt; lt;manifestgt;lt;mainClassgt;org..batch.core.launch.support.JobRegistryBackgroundJobRunnerlt;/mainClassgt;lt;addClasspathgt;truelt;/addClasspathgt;lt;classpathPrefixgt;liblt;/classpathPrefixgt;lt;/manifestgt;lt;/archivegt;lt;/configurationgt;lt;/plugingt;
As you can see I am instructing JAR plugin to have JobRegistry... as MainClass in MANIFEST.MF in META-INF.
If I unpack final jar, this MANIFEST.NF looks fine so this is ok.
After that I have assembly plugin which I am instructing to pack a ZIP file, with final name, and this ZIP contains: packed service.jar, lib directory with all maven dependencies and finally it contains service.sh which has a following line:Code:
java -jar relatieplanet-commandline-fakeprofiles.jar com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/applicationContext.xml com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml
nothing more, nothing less.
What I want to achieve is that relatieplanet-commandline-fakeprofiles.jar has it's own MainClass that I've already described previously, JobRegistry... and to pass following parameters: context file that is located in
relatieplanet-commandline-fakeprofiles.jar on class-path (com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/applicationContext.xml) and jobDescription file also located on classpath (com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml)
If I examine (unpack JAR file), these two files are located on these locations I am sure So if I start this sh file, I am getting following error in console:Code:
$ java -jar relatieplanet-commandline-fakeprofiles.jar com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/applicationContext.xml com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml
Feb 15, 2011 11:48:21 AM com.mchange.v2.log.MLog lt;clinitgt;
INFO: MLog clients using java 1.4+ standard logging.
Feb 15, 2011 11:48:21 AM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
Exception in thread quot;mainquot; org..beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml] cannot be opened because it does not exist at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org..beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org..context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:122) at org..context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) at org..context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org..batch.core.configuration.support.ClassPathXmlApplicationContextFactory$ResourceXmlApplicationContext.lt;initgt;(ClassPathXmlApplicationContextFactory.java:214) at org..batch.core.configuration.support.ClassPathXmlApplicationContextFactory.createApplicationContext(ClassPathXmlApplicationContextFactory.java:192) at org..batch.core.configuration.support.DefaultJobLoader.doLoad(DefaultJobLoader.java:120) at org..batch.core.configuration.support.DefaultJobLoader.load(DefaultJobLoader.java:114) at org..batch.core.launch.support.JobRegistryBackgroundJobRunner.register(JobRegistryBackgroundJobRunner.java:139) at org..batch.core.launch.support.JobRegistryBackgroundJobRunner.main(JobRegistryBackgroundJobRunner.java:235)
Caused by: java.io.FileNotFoundException: class path resource [com/telegraaf/relatieplanet/commandline/fakeprofiles/ctx/archiveProfileJob.xml] cannot be opened because it does not exist at org..core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org..beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 11 more
So I am doing something wrong, for sure.
Can someone help me out ???
Sorry for that, I figured it out that I was giving wrong name of job description context file. It should be named fakeProfiles.xml instead of archiveProfileJob.xml. |
|