In this section we will see how to create a multicore Solr embedded in Apache Tomcat.
What we suggest is managing each single core as a single Maven module as we raw in the previous chapter, then using this new archetype to aggregate all together in a single multicore instance.
The first step to do is creating the archetype, so just type:
$ mvn archetype:generate -DarchetypeCatalog=http://sourcesense.github.com/solr-packager/archetype-catalog.xml
then, when prompting:
Choose archetype: 1: local -> solr-standalone-archetype (Solr Packager Standalone Archetype) 2: local -> solr-multicore-archetype (Solr Packager Multicore Standalone Archetype) Choose a number: : 2 Define value for property 'groupId': : your.groupid Define value for property 'artifactId': : your.multicore.artifactId Define value for property 'version': 1.0-SNAPSHOT: : Define value for property 'package': your.groupid: : Confirm properties configuration: groupId: your.groupid artifactId: your.multicore.artifactId version: 1.0-SNAPSHOT package: your.groupid Y: : Y
let's analyze deep inside the created structure
The generated archetype has the following structure:
your.multicore.artifactId/ ├── pom.xml └── src └── main ├── filters │ ├── dev.properties │ ├── prod.properties │ ├── stage.properties │ └── test.properties └── solr └── solr.xml
The filters approach is the same as we adopted in the previous chapter, so nothing to add in this section.
Let's suppose we want to include the your.groupid:your.artifactId:1.0-SNAPSHOT Solr Core in our new multicore artifact; first of all, let's add the dependency in the pom.xml (don't forget to install, first!)
... <dependency> <groupId>your.groupid</groupId> <artifactId>your.artifactId</artifactId> <version>1.0-SNAPSHOT</version> <!-- | This is the mysterious artifact we raw in the previous section --> <classifier>master-resources-${environment}</classifier> <type>zip</type> <scope>provided</scope> </dependency> ...
then, add the core in the solr.xml
<solr persistent="true"> <cores adminPath="/admin/cores"> <core name="your.artifactId" instanceDir="your.artifactId" /> </cores> </solr>
We're now ready to package our Apache Solr based application: open the shell, go to the new generated archetype location and run
$ mvn -P(dev|test|stage|prod) package
the artifact of our interested is generated under target dir (last postfix depends on which profile were enabled)
target/ ├── your.multicore.artifactId-1.0-SNAPSHOT-multicore-(dev|test|stage|prod).zip
Let's unzip it
$ cd target $ unzip your.multicore.artifactId-1.0-SNAPSHOT-multicore-${profile}.zip
we can now execute the Tomcat-based Solr instance:
$ cd your.multicore.artifactId-1.0-SNAPSHOT-multicore-${profile} $ ./bin/catalina.(sh|bat) (run|start)
now open your preferred browser on go to
http://localhost:8080/
if you can see the Apache Solr admin list, your Solr instance is up and running! :)