From: <php...@li...> - 2007-04-17 05:33:15
|
Error information: java stack trace: java.lang.Exception: Invoke failed: [[c:MultiThreadedExample]]->doit. Cause: java.lang.ClassNotFoundException: Unresolved external reference: java.lang.NoClassDefFoundError: MultiThreadedExample$GetThread. -- Unable to call the method, see the README section "Java platform issues" for details. Responsible VM: 1.5.0@ http://java.sun.com/ at php.java.bridge.JavaBridge.getUnresolvedExternalReferenceException( JavaBridge.java:496) at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1135) at php.java.bridge.Request.handleRequest(Request.java:342) at php.java.bridge.Request.handleRequests(Request.java:388) at php.java.bridge.JavaBridge.run(JavaBridge.java:215) at php.java.bridge.BaseThreadPool$Delegate.run(BaseThreadPool.java :66) Caused by: java.lang.ClassNotFoundException: Unresolved external reference: java.lang.NoClassDefFoundError: MultiThreadedExample$GetThread. -- Unable to call the method, see the README section "Java platform issues" for details. ... 6 more Caused by: java.lang.NoClassDefFoundError: MultiThreadedExample$GetThread at MultiThreadedExample.doit(MultiThreadedExample.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1124) ... 4 more tm.php > <?php > $JAVA_LIB = 'file:/usr/solrapp/commons-logging-1.1.jar > ;file:/usr/solrapp/comm > try{ > java_require($JAVA_LIB); > $m = new JavaClass('MultiThreadedExample'); > $a = $m->doit(); > var_dump($a); > }catch (JavaException $ex){ > $trace = new Java("java.io.ByteArrayOutputStream"); > $ex->printStackTrace(new Java("java.io.PrintStream", > $trace)); > print "java stack trace: $trace\n"; > } > > ?> > MultiThreadedExample.java > import org.apache.commons.httpclient.HttpClient; > import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; > import org.apache.commons.httpclient.methods.GetMethod; > > /** > * An example that performs GETs from multiple threads. > * > * @author Michael Becke > */ > public class MultiThreadedExample { > > /** > * Constructor for MultiThreadedExample. > */ > public MultiThreadedExample() { > super(); > } > > public static void main(String[] args) { > > // Create an HttpClient with the > MultiThreadedHttpConnectionManager. > // This connection manager must be used if more than one thread > will > // be using the HttpClient. > > > } > > public static int[] doit(){ > int a[] = new int[50]; > HttpClient httpClient = new HttpClient(new > MultiThreadedHttpConnectionManager()); > // Set the default host/protocol for the methods to connect to. > // This value will only be used if the methods are not given an > absolute URI > httpClient.getHostConfiguration().setHost("jakarta.apache.org", > 80, "http"); > > // create an array of URIs to perform GETs on > String[] urisToGet = { > "/", > "/commons/", > "/commons/httpclient/", > "http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/ > " > }; > > // create a thread for each URI > GetThread[] threads = new GetThread[urisToGet.length]; > for (int i = 0; i < threads.length; i++) { > GetMethod get = new GetMethod(urisToGet[i]); > get.setFollowRedirects(true); > threads[i] = new GetThread(httpClient, get, i + 1); > } > > // start the threads > for (int j = 0; j < threads.length; j++) { > threads[j].start(); > a[j] = threads[j].getResult(); > > } > return a; > } > /** > * A thread that performs a GET. > */ > static class GetThread extends Thread { > > private HttpClient httpClient; > private GetMethod method; > private int id; > private int num; > > public GetThread(HttpClient httpClient, GetMethod method, int id) > { > this.httpClient = httpClient; > this.method = method; > this.id = id; > } > > /** > * Executes the GetMethod and prints some satus information. > */ > public void run() { > > try { > > System.out.println(id + " - about to get something from " > + method.getURI()); > // execute the method > httpClient.executeMethod(method); > > System.out.println(id + " - get executed"); > // get the response body as an array of bytes > byte[] bytes = method.getResponseBody(); > this.num = bytes.length; > //System.out.println(id + " - " + bytes.length + " bytes > read"); > > } catch (Exception e) { > System.out.println(id + " - error: " + e); > } finally { > // always release the connection after we're done > method.releaseConnection(); > System.out.println(id + " - connection released"); > } > } > > public int getResult(){ > return this.num; > } > > } > > } > jar cvf m.jar Multi*.class and i add these .jar file is in class_path. i use freebsd6.2 . -- regards jl |