4

Trying to start Solr with sunspot but having an issue with the Java Runtime Environment by getting this error.

root@oktobTest:~# dokku run oktob bundle exec rake sunspot:solr:start
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:203:in `ensure_java_installed'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/server.rb:27:in `initialize'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `new'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:38:in `server'
/app/vendor/bundle/ruby/2.1.0/gems/sunspot_solr-2.2.0/lib/sunspot/solr/tasks.rb:10:in `block (3 levels) in <top (required)>'
Tasks: TOP => sunspot:solr:start
(See full trace by running task with --trace)

Solar is up and running on the remote server.

Java is installed

root@oktobTest:~# which java
/usr/bin/java

And this is the output of sudo update-alternatives --config java

root@oktobTest:~# sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
* 2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1072      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1073      manual mode

I edited /etc/profile file to export the path inspired by discussions here and here and javaandme

JAVA_HOME=/usr/java/default
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH

I'm not sure about the path above is it correct or not.

config/sunspot.xml file

production:
  solr:
    hostname: localhost
    port: 8983
    log_level: WARNING
    path: /solr/production
    # read_timeout: 2
    # open_timeout: 0.5

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO
    path: /solr/development

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING
    path: /solr/test
Community
  • 1
  • 1
Ahmad Ajmi
  • 7,007
  • 3
  • 32
  • 52

3 Answers3

3

To me, reinstallation JDK(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) fixes the problem that happened during the first use of solr in El Capitan

aquajach
  • 2,548
  • 2
  • 23
  • 29
3

I got the same error. When running the following command.

$ bundle exec rake sunspot:solr:start -t

** Invoke sunspot:solr:start (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:solr:start
rake aborted!
Sunspot::Solr::Server::JavaMissing: You need a Java Runtime Environment to run the Solr server

By using this command

$ bundle exec rake --execute 'puts which java'  

I am getting '/usr/bin/java'.

But by the following command

$ java --version -> 'No Java runtime present, requesting install.

I am using Mac OSX and it prompted a message and clicking on more info it goes to:

oracle.com/technetwork/java/javase/downloads/index.html

So I installed JDK 8 from the link:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

for mac OSX

http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-macosx-x64.dmg

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

After that Solr server run successfully :) .

In your case you have to reinstall the JDK from the above link to make it work

You have openJDK runtime environment. Switch to Java(TM) SE Runtime Environment, to make Solr work. Read this (difference-between-oracle-jdk-and-open-jdk)

Run the Solr server background by

$ bundle exec rake sunspot:solr:start -t

Successfully started Solr ...

Stop Solr server:

$ bundle exec rake sunspot:solr:stop -t 

Start solr server in the foreground:

$ bundle exec rake sunspot:solr:run -t
Abhi
  • 3,361
  • 2
  • 33
  • 38
0

There are some topics about this problem. If you are sure that Java on the server is fine, please try to paste in configuration file (config/sunspot.yml) for the relevant environment this line "solr_home: solr" and start solr server by "RAILS_ENV=[your_env] bundle exec sunspot:solr:start"

Radek
  • 202
  • 2
  • 6
  • I did `solr_home: solr` but no success, and when I include `RAILS_ENV=production` inside the command I recieve `App oktob RAILS_ENV=production does not exist` – Ahmad Ajmi May 18 '15 at 18:05
  • Sorry, but I think there is a problem with your machine/hosting, as you can see you can't even start simple command. Where are you hosted and which distribution are you using? – Radek May 18 '15 at 20:40
  • I'm using DigitalOcean with Ubuntu and Rails deployed with Dokku, but everything is working and the Demo app is running at 46.101.47.185 and Solor at http://46.101.47.185:8983/solr/#/ – Ahmad Ajmi May 19 '15 at 06:27
  • Sure, so maybe this tutorial would by helpful: [link](https://www.digitalocean.com/community/tutorials/how-to-install-solr-on-ubuntu-14-04) – Radek May 19 '15 at 11:58
  • Yes I have used this article as my main source. – Ahmad Ajmi May 19 '15 at 16:32