{{{#!wiki red/solid Beginning with Solr 5.0, Solr is no longer distributed as a "war" (Web Application Archive) suitable for deployment in any Servlet Container. Solr is now distributed as a stand alone java server application, including start and stop scripts for use on Unix and MS-Windows platforms, as well as an installation script for setting up a "production" installation of Solr on *nix platforms managed via /etc/init.d. See https://wiki.apache.org/solr/WhyNoWar
}}}

Solr with Glassfish v3

Solr runs fine with Glassfish, see the instructions in the generic Solr installation page for general info before consulting this page.

Simple Example Install

Login to your administrative console, typically http://servername:4848.

Look for Enterprise Service on the left hand side and click on it. Look for "System Properties" tab along the top, click on it. Here you will setup your Solr home and data directories. Click on "Add Property" and in the name field put:

solr.solr.home and in the value put the fully qualified path to your solr folder. Example in Linux would be /opt/solr.

solr.data.dir and add the location of your data directory, an example might be /var/solrdata/ You will need to ensure that the permissions are set here, consult Solr installation documentation for assistance.

Then click on "Save" button in the upper right hand corner. I then restarted my Glassfish server to ensure the properties were set by clicking on the "General" tab and then "Restart".

Once this is done, you may deploy the war. For apache-solr-1.4.0, you should copy apache-solr-1.4.0/dist/apache-solr-1.4.0.war to your $GLASSFISHHOME/glassfishv3/domains/domainname/autodeploy. You can then verify that Solr deployed by going to that folder and you should see apache-solr-1.4.0.war.deployed.

Check the logs directory ($GLASSFISHHOME/glassfishv3/domains/domainname/logs) and you should see the Solr start up including it finding the solr.solr.home and solr.data.dir parameters. Goto http://'servername':8080/apache-solr-1.4.0/ to confirm successful installation.

Glassfish and UTF-8 (only needed before Solr 4.1)

(warning) Solr4.1 Solr now parses request parameters (in URL or sent with POST using content-type application/x-www-form-urlencoded) in its dispatcher code. It no longer relies on special configuration settings in Tomcat or other web containers to enable UTF-8 encoding, which is mandatory for correct Solr behaviour.

Solr now works out of the box with e.g. Tomcat, JBoss,...

In older Solr versions (before SolrTomcat]), you have to revisit this: Solr and Glassfish appear to have a problem similar to Tomcat with UTF-8 [http://wiki.apache.org/solr/SolrTomcat and using GET to make the requests.

Glassfish accepts the URL to contain UTF-8, but seems to fail with the query parameters. This is how I handled this problem, I am sure there is a better way.

Here is how the problem shows itself:

Goto to http://localhost:8080/apache-solr-1.4.0/admin/form.jsp and search for num*é*ro. Then check the glassfish server.log and you will see:

{{

}}

Note how Glassfish handled the encoding, it converted the single double-byte to two single-bytes.

I happen to be using Solrj for my application, and so my solution was to switch to POST rather than GET. I did this here:

            return server.query(new solrQuery().setQuery(query), METHOD.POST);

Note the METHOD.POST which obviously POSTs the data as parameters which Glassfish does seem to support. That bypasses the issue of running a non-Embedded Solr instance on Glassfish with UTF-8 queries under Solrj.

UTF-8 and sun-web.xml (only needed before Solr 4.1)

You can also create sun-web.xml inside $GLASSFISHHOME/glassfishv3/domains/domainname/applications/<solr-directory>/WEB-INF with the following content:

<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
<parameter-encoding default-charset="UTF-8"/>
</sun-web-app>

If you need to add another solr instance follow the these steps:

1) cd to $GLASSFISHHOME/glassfishv3/domains/domainname/autodeploy directory mentioned above.

2) copy apache-solr-1.4.0.war to <some-other-name>.war in the autodeploy directory. This will create a second instance that is using the same solr.solr.home and solr.data.dir as the first instance.

3) To change the solr home you need to edit the web.xml file, which will be in $GLASSFISHHOME/glassfishv3/domains/domainname/applications/<some-other-name>/WEB-INF

A - The entry you need to change is this one:
<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>

<env-entry-value>/put/your/solr/home/here</env-entry-value>

<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->

Just remove the comments above and below the env-entry tags and change the env-entry-value field and you are almost done. There is one gotcha, if you try to restart the application after editing the solr home, glassfish will give you a really long error message complaining about the position of env-entry. Basically, it wants the env-entry to be near the bottom after mime-mapping and before the </web-app>. So move the section there before saving.

B - Also, before restarting the application, you have to change the location of the data dir so it doesn't use the solr.data.dir. Create the directory you added in env-entry-value, put the need files and directories in it and in the conf directory under the just created directory change the dataDir in the solrconfig.xml file.

C - After editing the env-enty-value in the web.xml, creating the solr home, and editing the dataDir in solrconfig.xml, you need to restart the application. To do so go to the administrative console, http://servername:4848, look for Applications on the left, click on it, select the application you need to restart, and click restart. If everything went ok, it will give you a message that you were successful and even create the data dir.

  • No labels