问题
I can't start Solr 4.10.4 on Windows as it is stating:
Java 1.7 or later is required to run Solr
Here is where it gets fun, I have Java JRE 1.8_102 already installed and if I type java -version in a command prompt it properly displays the Java version. If I try to launch on the next line using Solr.cmd -f, it gives me the error.
For another level of testing I dropped in Solr 5.1.0 and it starts without issue via Solr.cmd -f
Since it works in 5.1.0 and the Java version is correct, why doesn't it work with 4.10.4?
I have the JAVA_HOME environmental variables/paths and registry entries set correctly from what I can tell, or else Solr 5.1.0 wouldn't launch. (I point to the jre directory for HOME and the jre\bin for the Path).
回答1:
I had a similar issue with 6.6.2 and the problem turned out to be a small bug in the solr.cmd script.
In the resolve_java_info subroutine it is doing a string compare rather than a numeric compare on the version. So editing this block of code:
REM Extract the major Java version, e.g. 7, 8, 9, 10 ...
for /f "tokens=1,2 delims=." %%a in ("!JAVA_VERSION_INFO!") do (
if "%%a" GEQ "9" (
set JAVA_MAJOR_VERSION=%%a
) else (
set JAVA_MAJOR_VERSION=%%b
)
)
and changing
if "%%a" GEQ "9" (
to:
if %%a GEQ 9 (
by removing the quotes fixed the issue.
回答2:
Look at the Look at the bin\solr.cmd
script.
That is where the Solr figures out which JVM to use. It is also where that error message comes from. (https://github.com/apache/lucene-solr/blob/branch_4x/solr/bin/solr.cmd)
The relevant section is this (or similar):
REM Verify Java is available
if NOT DEFINED JAVA_HOME goto need_java_home
"%JAVA_HOME%"\bin\java -version:1.8 -version > nul 2>&1
IF ERRORLEVEL 1 "%JAVA_HOME%"\bin\java -version:1.7 -version > nul 2>&1
IF ERRORLEVEL 1 goto need_java_vers
set "JAVA=%JAVA_HOME%\bin\java"
It looks to me as if the problem is that your %JAVA_HOME%
is not set correctly.
Since it works in 5.1.0 and the Java version is correct, why doesn't it work with 4.10.4?
The solr.cmd
script was rewritten in Solr 5.x. Compare the two versions that you have installed.
回答3:
I have tried the below fix, and it is worked.
https://issues.apache.org/jira/browse/SOLR-12141
patch: https://issues.apache.org/jira/secure/attachment/12916463/12916463_SOLR-12141.patch
回答4:
It ended up not being the Variable, but rather I was trying to start using Solr.cmd, where I needed to start Solr via browsing to example: java -jar start.jar. I am unsure why Solr.cmd won't work, but can work around it.
回答5:
In my case I have installed Java 10.0.2 and I got the error Error:Java 1.7 or later is required to run Solr, but 1.8 Installed
I have checked the code and the printed the variable JAVA_MAJOR_VERSION, which is always set to 0, then I changed the line
REM Extract the major Java version, e.g. 7, 8, 9, 10 ...
for /f "tokens=2 delims=." %%a in ("!JAVA_VERSION_INFO!") do (
set JAVA_MAJOR_VERSION=%%a
)
to
REM Extract the major Java version, e.g. 7, 8, 9, 10 ...
for /f "tokens=1 delims=." %%a in ("!JAVA_VERSION_INFO!") do (
set JAVA_MAJOR_VERSION=%%a
)
Note: tokens is changed
For my case it worked. in case if it didn't help you, you can debug solr.cmd a little. :)
来源:https://stackoverflow.com/questions/46125765/java-1-7-or-later-is-required-to-run-solr-but-1-8-installed