You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by "Pavel G. Sozonovsky" <pa...@alee.com> on 2002/07/17 11:12:16 UTC

Re[2]: Using Xindice inside own code

Hi Catie,

Thank you for your help.

I've tried to use a bit modified code:

String xindicePath = xindiceDir.getCanonicalPath();
String classpath = System.getProperties().getProperty("java.class.path");
String javaHome = System.getProperties().getProperty("java.home");

String startCommand = javaHome + "\\bin\\java.exe -Xms16m -Xmx128m -Dxindice.home=" +
                      xindicePath+" -classpath " + classpath +
                      " org.apache.xindice.server.Xindice " +
                      xindicePath + "\\config\\system.xml";

Process _serverProcess = Runtime.getRuntime().exec(startCommand, new String[0], xindiceDir);
// ...

But I get another error:

LINE IS:
LINE IS: Xindice 1.0 (Birthday)
LINE IS:
LINE IS: Database: 'db' initializing
LINE IS: Script: 'GET' added to script storage
LINE IS: Service: 'db' started
ERROR LINE IS: java.lang.NullPointerException
ERROR LINE IS:   at org.apache.xindice.server.services.SocketServer.createServerSocket(SocketServer.java:242)
ERROR LINE IS:   at org.apache.xindice.server.services.HTTPServer.run(HTTPServer.java:180)
ERROR LINE IS:   at java.lang.Thread.run(Thread.java:484)


Don't you know what is a problem?
Do I anything wrong?

Thanks again.

Pavel
mailto:pavel@alee.com

> We start Xindice by using Runtime.exec() and sending the Xindice command
> with config parameters for the JVM and for Xindice. We detect whether
> it's running by waiting for an output message of "Server Running" (there
> is probably a better way to do this, but I don't know what it is!).

> The code is below - maybe it will help you...
> Cheers,
> Catie

> /**
>    * Runs the system command to start the DBServer
>    * @todo: make bulletproof, handle errors & exceptions, etc
>    */
>   protected void startCommand()
>   {

>     File execDir = new File( XindiceUtil.getInstance().getXindiceHome()
> );
>     try
>     {
>       _serverProcess = Runtime.getRuntime().exec(START_COMMAND, ENV,
> execDir);
>       InputStream inputStream = _serverProcess.getInputStream();
>       BufferedReader reader = new BufferedReader ( new
> InputStreamReader(inputStream) );

>       InputStream error = _serverProcess.getErrorStream();
>       BufferedReader errRead = new BufferedReader ( new
> InputStreamReader(error) );

>       try
>       {
>         String line = null;
>         boolean serverStarted = false;
>         while ( !serverStarted )
>         {
>             while (errRead.ready())
>             {
>               line = errRead.readLine();
>               System.out.println(line);
>               System.out.println("ERROR LINE IS: " + line);
>             }
>             while(reader.ready())
>             {
>               line = reader.readLine();
>               System.out.println("LINE IS: " + line);
>             }
>             if (line != null && line.indexOf("Server Running") != -1 )
>             {
>                serverStarted = true;
>                setStarted(true);
>             }
>         }
>       }
>       catch (IOException e)
>       {
>         e.printStackTrace();
>         throw new RuntimeException(e.getMessage());
>       }
>     }
>     catch (Exception e)
>     {
>       e.printStackTrace();
>       throw new RuntimeException();
>     }
>   }