Java Reference
In-Depth Information
There is one additional thing you need to do. This project has two artifacts: the normal jar file from
which you run jobs and a jar file that you launch for each of your slave JVMs. The only difference
between the two is the main class you use. By default, your jar files are created with the
CommandLineJobRunner defined as the main class, and this works fine for the jar file from which you
execute the job. However, in the other JVMs, you don't want to execute the job; instead, you want to
bootstrap Spring and register your listeners to be able to process any items that come their way. For this
other jar file, you create a main class that bootstraps Spring for you and then blocks so that it doesn't
shut down.
But what does this new jar file have to do with your POM file? Because the POM file specifies the
main class that your jar file is configured to execute, you want to make it more versatile for you to
generate the two jar files. To do this, you define two profiles: one for each of the two artifacts you
generate. You use these profiles to define the main class that's configured for each of the jar files you
generate. Creating these profiles consists of two steps: deleting the reference to the maven-jar-plugin in
the build section of the POM file, and then adding your profiles. One is named listener and is used to
build the jar file for your slave JVMs. The other is called batch , is the default profile, and configures the
jar file to use CommandLineJobRunner as the jar file's main class. Listing 11-25 shows the new profile
configurations.
Listing 11-25. Maven Profiles Used to Generate Both Required Artifacts
<profiles>
<profile>
<id>listener</id>
<build>
<finalName>remote-chunking-1.0-listener-SNAPSHOT</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>false</index>
<manifest>
<mainClass>com.apress.springbatch.chapter11.main.Geocoder</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestFile>${project.build.outputDirectory}/META-
INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>batch</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
 
Search WWH ::




Custom Search