You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ROR项目Solr状态查询报错:无法找到主类org.apache.solr.util.SolrCli

Troubleshooting the "could not find or load main class org.apache.solr.util.SolrCli" Error

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 solr to get the path to your Solr binary. The parent directory (e.g., /opt/solr or /usr/local/solr) is your main Solr installation folder.
  • Navigate to server/lib/ inside that directory and look for solr-cli.jar—this is where org.apache.solr.util.SolrCli lives. 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_DIR or CLASSPATH. Ensure SOLR_INSTALL_DIR points 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 --version to confirm your current Solr version.
  • Check if the service script uses the correct versioned directory (e.g., /opt/solr-9.4.0 instead 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:31:53