There is something really interesting going on when I try to start
Solr and then connect to it in the same process. I get a "connection
refused" error. The code I try to use is found below. If I start solr
with runtime.exec("java -jar start.jar") it works fine to connect to
it afterwards, but if I start solr with runtime.exec("java
-Dcom.sun.management.jmxremote -jar start.jar") I can't connect to
solr. It is possible to connect with the web browser however, or any
other program, even with the same code that fails when it's in the
same process.

I just can't figure out why I can't connect to solr. Anyone have any hints?

/Tim


import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.SolrQuery;
import java.net.URL;
import java.net.URLConnection;
import java.io.File;

class StartSolr {

   public static void main(String[] args) {
      try {
          String cmd = "java -Dcom.sun.management.jmxremote -jar start.jar";
          String cmd2 = "java -jar start.jar";  // works
          File workingDir = new File("/some/path/apache-1.4.0/example");
          Runtime.getRuntime().exec(cmd2, null, workingDir);
          Thread.sleep(5*1000);

          URL url = new URL("http://localhost:8983/solr";);
          URLConnection connection = url.openConnection();
          Object content = connection.getContent();
          System.out.println(content);
          System.out.println("Success");
      }
      catch (Exception e) {
          e.printStackTrace();
      }
   }
}

Reply via email to