ROR项目Solr状态查询报错:无法找到主类org.apache.solr.util.SolrCli
Hey there, let’s work through this Solr issue you’re hitting with your Rails project. It’s definitely odd that the process is running fine on port 8983 (PID 17919) but the service solr status command throws that class not found error. Here are actionable steps to fix it:
Step 1: Confirm Solr’s Installation & Missing JAR
First, let’s check if the required JAR file exists:
- Run
which solrto get the path to your Solr binary. The parent directory (e.g.,/opt/solror/usr/local/solr) is your main Solr installation folder. - Navigate to
server/lib/inside that directory and look forsolr-cli.jar—this is whereorg.apache.solr.util.SolrClilives. If it’s missing, your Solr installation might be corrupted, and you’ll need to re-download and install the correct version.
Step 2: Fix the Service Script’s Path Configuration
The service solr command relies on a script (usually at /etc/init.d/solr or /lib/systemd/system/solr.service) that defines critical paths. Let’s correct it:
- Open the script with a text editor (e.g.,
sudo nano /etc/init.d/solr). - Look for variables like
SOLR_INSTALL_DIRorCLASSPATH. EnsureSOLR_INSTALL_DIRpoints to your actual Solr installation folder (the one you found in Step 1). - If the script references
solr-cli.jar, double-check the path. It should look something like:CLASSPATH="$SOLR_INSTALL_DIR/server/lib/solr-cli.jar:$CLASSPATH"
Step 3: Resolve Version Mismatches
If you recently upgraded Solr, the service script might still be pointing to an old installation:
- Run
solr --versionto confirm your current Solr version. - Check if the service script uses the correct versioned directory (e.g.,
/opt/solr-9.4.0instead of/opt/solr-8.11.2). Update the paths in the script to match your current installation.
Step 4: Reinstall the Solr Service (If Needed)
If the service script is too broken to fix manually, use Solr’s official setup script to reconfigure the service:
- Navigate to your Solr installation directory, then run:
sudo ./bin/install_solr_service.sh
This will overwrite the existing service config with paths that match your current Solr version.
Step 5: Restart & Verify
After making changes, restart the service to apply them:
sudo service solr restart
Then run service solr status again—this should resolve the class not found error.
A quick side note for your Rails project: if you’re using the sunspot_solr gem, make sure its version is compatible with your installed Solr version. Mismatches here can cause odd behavior even when the Solr process is running.
内容的提问来源于stack exchange,提问作者Leonardo

