I have Apache Solr Server installed and the apachesolr module enabled. I downloaded Tika 0.4 source and built it. I moved the tika-core-0.4.jar into sites/all/modules/apachesolr_attachments/tika. In the admin/settings/apachesolr/attachments I really wasn't sure the path I was supposed to put so I tried it a couple of different ways.

  1. C:\wamp\www\repo\sites\all\modules\apachesolr_attachments\tika
  2. sites/all/modules/apachesolr_attachments/tika

When Look at Status Report, I have a Red section that reads the following:

Java executable not found	
Could not execute a java command. You may need to set the path of the correct java executable as the variable 'apachesolr_attachments_java' in settings.php.

So I placed the apachesolr_attachments_java' in settings.php two different ways:

  1. $apachesolr_attachments_java = 'C:\wamp\www\repo\sites\all\modules\apachesolr_attachments\tika\tika-core-0.4.jar';
  2. $apachesolr_attachments_java = 'sites/all/modules/apachesolr_attachments/tika/tika-core-0.4.jar';

Just so there isn't a question about it, I did run Tika after I built it to make sure it works and it did exactly what it was supposed to do so I know it isn't Tika (at least nothing obvious anyway).

Also, on line 36 in the apachesolr_attachments.install file:
$java = variable_get('apachesolr_attachments_java', 'java');
When I look at the $java variable, it contains the default, not the variable from the settings.php file.

Nothing I have done so far has worked and I continue to get the "Java executable not found" error on the Status Report page. The instructions for putting this together are very limited and I can't seem to find anything very complete on how to make this work. Can anyone help with this? I figure it is just the way I am referencing the jar file or something really easy that I am just missing but can't seem to figure it out.

Thanks in advance for the help :)

Comments

pobster’s picture

The answer is in your settings.php file;

/**
* Variable overrides:
*
* To override specific entries in the 'variable' table for this site,
* set them here. You usually don't need to use this feature. This is
* useful in a configuration file for a vhost or directory, rather than
* the default settings.php. Any configuration setting from the 'variable'
* table can be given a new value. Note that any values you provide in
* these variable overrides will not be modifiable from the Drupal
* administration interface.
*
* Remove the leading hash signs to enable.
*/
# $conf = array(
# 'site_name' => 'My Drupal site',
# 'theme_default' => 'minnelli',
# 'anonymous' => 'Visitor',

So to set a variable you simply need to use;

$conf = array(
  'apachesolr_attachments_java' => 'C:\wamp\www\repo\sites\all\modules\apachesolr_attachments\tika\tika-core-0.4.jar',
);

Pobster

pobster’s picture

Status: Active » Fixed
pwolanin’s picture

this variable should hold the path to java itself - NOT to tika. not sure why the above is working for you, but that is the general method of overriding a variable.

pobster’s picture

Apologies, my answer was simply to specify the correct way to override a variable. Afraid I don't even use this module and like the original poster, I hadn't read the status message clearly enough - I just noted what the poster was trying to do unsuccessfully and thought to give them a little direction. I just stumbled here by accident and saw a old(-ish) unanswered query I could answer easily enough.

Thanks,

Pobster

grÖs’s picture

Hello,
I actually get the same issue, but this error message stay in the report status :/

I got tika 0.7 and compile it with maven succesfully. I tested with command lines and it works well.
I put tika files in "./sites/all/modules/apachesolr_attachments/tika/" as you did (the four .jar files).

I set the variable :
$conf = array(
'apachesolr_attachments_java' => './sites/all/modules/apachesolr_attachments/tika/tika-core-0.7.jar'
in the settings.php file.
);

It don't work yet ... always the same issue. I verify that the variable is read without problems.
I see you fixed this issue, can you help me please ?

pobster’s picture

As per the comment above which you obviously didn't read; http://drupal.org/node/784612#comment-2974762

$conf = array(
  'apachesolr_attachments_java' => '/usr/bin/java',
);

Use the path to your own java executable.

Pobster

grÖs’s picture

hello,

Thanks for answering so quickly.
I just find why it didn't work : my Wamp Server was installed at "C:/Program Files/wamp".
I think that the white space " " was not interpreted.

I re-installed it at "C:/Wamp" and it works well.

Bye

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jsmoorejr’s picture

Version: 6.x-1.0-beta1 » 6.x-1.0-beta2
Status: Closed (fixed) » Active

Hoping this is the correct thing to do here by re-opening this thread...if not I apologize.

So here is my issue. I have followed post #6 and it still shows that the Java executable not found problem in the status report.

I am using Windows (please no comments about switching to Linux, lol) and the code I placed in the settings.php file are as follows:

$conf = array(
  'apachesolr_attachments_java' => 'C:\Java\jre6\bin',
);

I have restarted my web server and cleared the cache, but still nothing has changed. Apache Solr is running on my server and I have no issues with it at all, just the Apache Solr Attachments.

The status report shows my site has contacted the Apache Solr server with the following settings:
Apache Solr - Your site has contacted the Apache Solr server.
Host: localhost
Port: 8080
Path: /apache-solr-1.4.0

Has anyone had the same troubles and been able to fix it?

pobster’s picture

I would assume it's necessary to add the executable to the path, i.e. ...C:\Java\jre6\bin\java.exe

Pobster

jsmoorejr’s picture

HAHA, yep that was it. I wasn't thinking about it that way. I was thinking about it similar to creating an environment variable; giving it a path to the executable.

Thanks much, that really helped. I tried everything but that. It didn't even occur to me to try that, lol.

pwolanin’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

m2011’s picture

Version: 6.x-1.0-beta2 » 6.x-2.x-dev
Status: Closed (fixed) » Active

My path in settings.php is:

$conf = array('apachesolr_attachments_java' => '/usr/java/jdk1.6.0_24/bin/java',);

How do I verify that the path is correct? I am using the path that displays when I enter "/usr/sbin/alternatives --java config" but am still receiving the following error:

Java executable not found
Could not execute a java command. You may need to set the path of the correct java executable as the variable 'apachesolr_attachments_java' in settings.php.

Are there any other files I should check?

pobster’s picture

My advice is to go to the top of this thread and start reading... If you really can't work out how to find out where your java executable is then use; # which java

Pobster

rbryer’s picture

This thread is a little misleading in places. If you get this error it can be caused but several things.

1. It can't find the java executable
2. It can't run the java executable

By default it will just run the command 'java' - try on the command line? Does it work? If not you can force Drupal to the correct path as stated in #9.

However, you may find that even when you specify the path you still get the same error in Drupal. Again try it on the command line, run {path}/java and see what happens. On any sort of memory constraint hardware you may we get the following error.

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java Virtual Machine

This is caused by java being memory hungry by default. This is also easy to fix in the same location. You can add the memory switches to the command line you enter in settings.php. The example below set the initial heap to 20Mb and a max of 64Mb. You can tweak these to fit you environment, you can start with 256K if necessary.

$conf = array( 
	'apachesolr_attachments_java' => '/usr/bin/java -Xms20m -Xmx64m'
	); 

Again, test it out on the command line and add the -version tag e.g. java -version ...you should get a response like

java version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.5) (rhel-1.16.b17.el5-i386)
OpenJDK Client VM (build 14.0-b16, mixed mode)

The key here is that it must include the phase "Runtime Environment" as this is what the code is actually looking for .. see line 43 here

Hope that help someone.

pwolanin’s picture

Thanks - a good explanation of the possible problem - can I add that to the README?

jpmckinney’s picture

Title: Having issues trying to get the apachesolr_attachments_java variable working in the settings.php file » Improve documentation regarding java executable
Category: support » task
ericmulder1980’s picture

Version: 7.x-1.0 » 6.x-2.x-dev
Status: Closed (cannot reproduce) » Active

If adding the following code to your settings.php doesn't help perhaps you are using MAMP. This is because of a bug in the PHP stack MAMP.

more info : http://stackoverflow.com/questions/278868/calling-java-from-php-exec

$conf = array(
  'apachesolr_attachments_java' => '/usr/bin/java -Xms20m -Xmx64m'
); 

Go to your apachesolr_attachments module en locate thee apachesolor_attachments.install file. In this file locate the hook_requirements function.

Replace the following line:

exec(variable_get('apachesolr_attachments_java', 'java') . ' -version > ' . $temp . ' 2>&1');

with this line:

exec('export DYLD_LIBRARY_PATH="";' . variable_get('apachesolr_attachments_java', 'java') . ' -version > ' . $temp . ' 2>&1');

This solved the problem for me and a lot of other colleagues working on Mac.

jh81’s picture

Version: 6.x-2.x-dev » 7.x-1.0

Tried all the steps above but still would not work. I have Drupal running in Windows 2003 Server under IIIS. I was also getting a warning on the status report page as follows.

Warning: exec() [function.exec]: Unable to fork [C:\Progra~1\Java\jre6\bin\java.exe -version > H:\Inetpub\wwwroot\drupal\temp\apa123.tmp 2>&1] in apachesolr_attachments_requirements() (line 50 of H:\Inetpub\wwwroot\drupal\modules\apachesolr_attachments\apachesolr_attachments.install).

Searched on unable to fork and found out you need to give the ISUR account read rights to cmd.exe. See http://www.somacon.com/p255.php for details. Once I did that the warning went away.

nick_vh’s picture

Status: Active » Closed (cannot reproduce)
deanflory’s picture

Instructions that worked as of 2012-10-06 after receiving the "Java executable not found" error, which are FAR less complex and non-omission laiden like pretty much all others on the Web that I could easily find. Please note I have no idea if this set of instructions has any drawbacks, but it worked for me to remove that error but I have yet to test if the installed Java actually functions correctly yet other than using "java" and "java -version" ssh commands to verify it was installed.

In order to perform the following, you'll need root access to your server through SSH, using a built-in SSH app in your server software's GUI, or a separate applicatin/program like I use on Mac OS X called "Terminal" (Terminal.app). If you don't understand, ask your hosting provider about root access via a SSH terminal and see what they say. Shared hosting likely won't allow that level of access.

Instructions for Installing Java on CentOS 5

Instructions Dean followed and modified to get this customized set of steps below, THANKS CHRIS CHULD!:
http://chrisschuld.com/2008/10/installing-sun-java-on-centos-5-2/

Download the NON-RPM, non-64bit, Linux x86, Java SE 7u7 JDK (Java Development Kit which includes the JRE) file and upload it to another server since Sun's/Oracle's server would NOT allow a direct wget (only downloaded a fail.html file due to having to check a damn license agreement radio button I'm guessing, argh, time-waster for nothing):
http://www.oracle.com/technetwork/java/javase/downloads/index.html
http://www.oracle.com/technetwork/java/javase/downloads/jdk7u7-downloads-1836413.html

Now we'll upload it to the server in the /opt folder:

cd /opt/
wget http://www.yourservernameherewhereyouuploadedit.com/jdk-7u7-linux-i586.tar.gz

Now even though the other instructions try to uncompress a binary, the only packages available on Sun's/Oractle's site were either .rpm's (not using) or tar.gz (yes using), which need to be untarred and ungzipped:
tar zxvf jdk-7u7-linux-i586.tar.gz

Let's see what files are in that folder with a directory listing ("LS" lowercase):
ls

A resulting folder "jdk1.7.0_07" was created.

Now we'll remove the tar.gz downloaded/uploaded file since we don't need it anymore:
rm -rf jdk-7u7-linux-i586.tar.gz

We now need to install it and setup the alternatives correctly (these steps make it easier and faster than other sets of instructions that require changing symbolic links all over the place):

alternatives --install /usr/bin/java java /opt/jdk1.7.0_07/bin/java 2
alternatives --config java

This pulls up an option menu choice between installed java packages and in my case there wasn't another (this is the time-saver from using "alternatives --"):

There is 1 program that provides 'java'.

Selection Command
-----------------------------------------------
*+ 1 /opt/jdk1.7.0_07/bin/java

Enter to keep the current selection[+], or type selection number:

Hit enter or follow the instructions to choose by number if you have more than one java package installed.

Now we must check to make sure the install was a success:
java -version

Which displays:

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) Server VM (build 23.3-b01, mixed mode)

Now let's see that location where it was installed:

cd /usr/bin/
ls

"java" is now in the list and I'm guessing from other instructions across the Web, it's only a symbolic link to the /opt... location where we uncompressed it. Others said this was a problem for developers but it seems that the "alternatives --" method allowed us to choose and thus bypass various additional install steps to set that correctly, which may be the better path and a workaround to problems others had when developing on a server with multiple version of java installed in various locations.

Now we can look into what our new Java install has to offer, type:
java

Which shows:

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is server,
because you are running on a server-class machine.

-cp
-classpath
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D=
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:
...|:]
-enableassertions[:
...|:]
enable assertions with specified granularity
-da[:
...|:]
-disableassertions[:
...|:]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:
[=]
load native agent library
, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:
[=]
load native agent library by full pathname
-javaagent:[=]
load Java programming language agent, see java.lang.instrument
-splash:
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.

Far more simple, and far faster than others right? And it works to remove the "Java executable not found" without any modifications to any Drupal-related or site-related file.

Some keywords and phrases to help others find this:

Install Java for Drupal 7.15
Install Java for CentOS 5
Java executable error
Status Report error Java
install java 2012
install java drupal
install java centos
ssh java
easy instructions to install java on centos
java install instructions that work

Cristobal Wetzig’s picture

Cristobal Wetzig’s picture

Thank you, #19 worked for me in a mac MAMP setup.

aronne’s picture

Ther's a typo in #19.. $temp instead of $tmp, so this is the full working function for MAMP setup

/**
 * hook_requirements().
 */
function apachesolr_attachments_requirements($phase) {

  $requirements = array();
  // Ensure translations don't break at install time
  $t = get_t();
  if ($phase == 'runtime') {
    if (variable_get('apachesolr_attachment_extract_using', 'tika') == 'tika') {
      $temp = tempnam(file_directory_temp(), 'asa');
      $java = variable_get('apachesolr_attachments_java', 'java');
      //exec($java .' -version > '. $temp .' 2>&1');
      exec('export DYLD_LIBRARY_PATH="";' . $java . ' -version > ' . $temp . ' 2>&1');
      $stderror = file_get_contents($temp);
      $found = preg_match('/Runtime Environment/', $stderror);
  
      if (!$found) {
        $requirements['apachesolr_attachments_java']  = array(
          'title' => $t('Java executable not found'),
          'description' => $t('Could not execute a java command.  You may need to set the path of the correct java executable as the variable \'apachesolr_attachments_java\' in settings.php.'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
    }
  }

  return $requirements;
}
ericmulder1980’s picture

Hi aronne,

It wasn't a typo, the variable name used to be $tmp, they probably changed it to $temp in a later version. I will change my comment to prevent people from using the wrong code.

Status: Active » Closed (cannot reproduce)
nikus85’s picture

I have no idea WHY, but variable $conf['apachesolr_attachments_java'] which was set in settings.php could not be read in apachesolr_attachments.index.inc (it returned 'java' instead of my custom jre executable path).

I tried ClearindAllCaches & turning off/on the module apachesolr_attachments. I have seen from code that module's .install should warn when java executable could not be accessed, but there were no warnings.

So far, I open my main custom module for the site, and put 1 more string in hook_init() function:
variable_set('apachesolr_attachments_java', "/my/custom/path/bin/java -Xms20m -Xmx64m");