The basic setup of Solr 4.10 with Eclipse 4.4 and Wildfly 8.1 requires quite a bit of configuration. First of all, be sure that your system fulfills the following requirements.
Prerequisites
- Java Development Kit (jdk1.8.0_25)
- Eclipse Java EE IDE for Web Developers (Luna Service Release 1 (4.4.1))
- Apache Maven (already included in Eclipse)
- WildFly Application Server (wildfly-8.1.0.Final)
- JBossAS Tools (3.0.0.CR1) for Eclipse)
The specified version numbers are the versions I’m using. The tutorial should however apply to other major versions, too.
Setup a WildFly Project in Eclipse with Maven
Open Eclipse and add a new server (“File > new > Server”). If JBoss Tools are installed, you can choose WildFly 8.x and create it without further changes. However if you’re running multiple web projects on the same instance of WildFly you may consider creating an own Server Runtime Environment with a custom WildFly configuration file. Deploying your web app to the workspace metadata instead of the JBoss deploy folder may also be advisable. You find these options by double clicking your server in the “Servers” view.
Maven Configuration
Then create a new “File > new > Maven Project”, skip archetype selection and give it let’s say “illucit-solr” as Artifact Id and “com.illucit” as Group Id. The packaging type must be “war”. The next step is to customize the pom.xml
. During this process you have to “maven-update” the project (select the project and press “ALT+F5”) a couple of times. Check out my example pom.xml
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.illucit</groupId> <artifactId>illucit-solr</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <!-- Charset --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- Plugin versions --> <version.compiler.plugin>3.2</version.compiler.plugin> <version.source.plugin>2.4</version.source.plugin> <version.javadoc.plugin>2.10.1</version.javadoc.plugin> <!-- Recent versions of plugins for use in child projects --> <version.war.plugin>2.6</version.war.plugin> </properties> <build> <finalName>${project.artifactId}</finalName> <sourceDirectory>src</sourceDirectory> <testSourceDirectory>test</testSourceDirectory> <resources> <resource> <directory>resources</directory> </resource> </resources> <testResources> <testResource> <directory>testresources</directory> </testResource> </testResources> <plugins> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <warName>illucit-solr</warName> </configuration> </plugin> <plugin> <artifactId>maven-source-plugin</artifactId> </plugin> <plugin> <artifactId>maven-javadoc-plugin</artifactId> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>${version.compiler.plugin}</version> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> </configuration> </plugin> <plugin> <artifactId>maven-source-plugin</artifactId> <version>${version.source.plugin}</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <version>${version.javadoc.plugin}</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>${version.war.plugin}</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <attachClasses>true</attachClasses> <warSourceDirectory>WebContent</warSourceDirectory> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> |
Now create a folder called WebContent
right under the project, if not yet present, and place an index.html
in it with some content, like “Hello illucIT Software!”. Add the project to your WildFly instance and start the server. When the startup succeeded, browsing http://localhost:8080/illucit-solr/index.html
should yield the content of your index.html
file.
The URL to the web app can easily be modified by putting a jboss-web.xml
file in WebContent/WEB-INF:
1 2 3 4 |
<?xml version="1.0" encoding="UTF-8"?> <jboss-web> <context-root>/</context-root> </jboss-web> |
The index.html
file should now be accessible by browsing http://localhost:8080/index.html.
Adding Solr Dependencies
To run the Solr example, add the following section to your pom.xml
:
1 2 3 4 5 6 7 |
<dependencies> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> <version>4.10.3</version> </dependency> </dependencies> |
The following Maven update may take a while. Now if you started Eclipse with a JRE instead of a JDK, a Maven dependency problem
Missing artifact jdk.tools:jdk.tools:jar:1.6 occurs. To fix this, launch Eclipse with the a JDK. Edit eclipse.ini
and add the following lines
1 2 |
-vm {jdk.home}/bin/javaw |
right before the -vmargs
parameter. Restart Eclipse and “maven-update” your project. The error should now disappear. Another solution for that problem would be to include this dependency in the pom.xml
:
1 2 3 4 5 6 7 |
<dependency> <groupId>jdk.tools</groupId> <artifactId>jdk.tools</artifactId> <version>1.6</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> |
The tools.jar
must be referenced relatively to ${java.home}
. But this doesn’t solve the eclipse error1, so I continue with the first solution.
If you try to start WildFly now, it fails with the following error message:
1 |
15:33:43,174 WARN [org.jboss.modules] (weld-worker-6) Failed to define class org.apache.hadoop.hdfs.web.resources.UserProvider in Module "deployment.illucit-solr.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/apache/hadoop/hdfs/web/resources/UserProvider (Module "deployment.illucit-solr.war:main" from Service Module Loader) |
To fix this you need to update Google Guava, which is pulled in as a dependency by solr-core
in an old version.
1 2 3 4 5 |
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>16.0.1</version> </dependency> |
WildFly should start now without any errors and all Solr dependencies available.
Copy Solr Files into your Eclipse Project
The last step is to import the Solr example web app into Eclipse. Download Solr 4.10.3 and unpack it. Extract solr-4.10.3\example\webapps\solr.war
and copy the content into the WebContent directory of your workspace. After you deleted the lib
directory and weblogic.xml
, your project should look like mine.
Visiting the Solr Admin Panel http://localhost:8080/admin.html
however fails with an exception
Caused by: java.io.IOException: Can't find resource 'solrconfig.xml' in classpath or 'C:\wildfly-8.1.0.Final\bin\solr\collection1\conf' .
So we finally got Solr running with Eclipse 4.4 and WildFly 8.1! The remaining part of the configuration highly depends on your needs and the structure of your Solr index and search. So I leave it up to you, to set this up. But a good starting point would be to copy the solrconfig.xml
from solr-4.10.3\example\solr\collection1\conf
into the resources
directory directly under your project (see also pom.xml
, where this directory is defined as resource directory).
- Maven not picking JAVA_HOME correctly on Stack Overflow