string arg []导致java.lang.NoClassDefFoundError

时间:2012-03-06 11:44:47

标签: java

所以我有一个脚本文件,我们正在内部进行测试。我想使用脚本在互联网上进行测试,但是当我给它一个url而不是ip地址时,它会抛出一个java.lang.NoClassDefFoundError,

为什么这是我可以做些什么来解决它

这是脚本文件:

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection; 

public class SOAPClient4XG
{
  public static void main(String[] paramArrayOfString)
    throws Exception
  {
    if (paramArrayOfString.length < 2) {
      System.err.println("Usage:  java SOAPClient4XG http://soapURL soapEnvelopefile.xml [SOAPAction]");


      System.err.println("SOAPAction is optional.");
      System.exit(1);
    } 

    String str1 = paramArrayOfString[0];
    String str2 = paramArrayOfString[1];

    String str3 = "";
    if (paramArrayOfString.length > 2) {
      str3 = paramArrayOfString[2];
    } 

    URL localURL = new URL(str1);
    URLConnection localURLConnection = localURL.openConnection();
    HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURLConnection;


    FileInputStream localFileInputStream = new FileInputStream(str2);

    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();


    copy(localFileInputStream, localByteArrayOutputStream);
    localFileInputStream.close();

    byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();


    localHttpURLConnection.setRequestProperty("Content-Length", String.valueOf(arrayOfByte.length));

    localHttpURLConnection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    localHttpURLConnection.setRequestProperty("SOAPAction", str3);
    localHttpURLConnection.setRequestMethod("POST");
    localHttpURLConnection.setDoOutput(true);
    localHttpURLConnection.setDoInput(true);


    OutputStream localOutputStream = localHttpURLConnection.getOutputStream();
    localOutputStream.write(arrayOfByte);
    localOutputStream.close();



    InputStreamReader localInputStreamReader = new InputStreamReader(localHttpURLConnection.getInputStream());

    BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);

    String str4;

    while ((str4 = localBufferedReader.readLine()) != null) {
      System.out.println(str4);
    } 
    localBufferedReader.close();
  } 


  public static void copy(InputStream paramInputStream, OutputStream paramOutputStream)
    throws IOException
  {
    synchronized ()
    {
      synchronized (paramOutputStream)
      {
        byte[] arrayOfByte = new byte['Ā'];
        for (;;) {
          int i = paramInputStream.read(arrayOfByte);
          if (i == -1) break; 
          paramOutputStream.write(arrayOfByte, 0, i);
        } 
      } 
    } 
  } 
} 

用于运行它的bat文件是:

echo Check in inquiry sending:
java -cp .SOAPClient4XG http://foobar/gotdns/com:8080/axis2/services/HTNGListener checkininquiry.sms http://htng.org/1.1/Listener.Wsdl#ReceiveMessageAsync

这是堆栈跟踪:

C:\Documents and Settings\accounting\Desktop\springer_miller_docs>java -cp .SOAP
Client4XG http://foobar.gotdns.com:8080/axis2/services/HTNGListener checkinin
quiry.sms http://htng.org/1.1/Listener.Wsdl#ReceiveMessageAsync
Exception in thread "main" java.lang.NoClassDefFoundError: http://foobar/gotd
ns/com:8080/axis2/services/HTNGListener

2 个答案:

答案 0 :(得分:1)

您的问题与您的代码无关,但与您的执行方式无关。

您的命令行说将主文件放在类路径上,然后在名为第一个URL的类中执行main。

离开-cp,你应该没事(至少从这个堆栈跟踪)。

供参考:http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html

答案 1 :(得分:0)

这行代码

URL localURL = new URL(str1);

会为您提供的参数抛出java.net.MalformedURLException: no protocol: 192.168.0.127

URL是协议感知的,您应该给它类似http://soapURL(由您的程序本身建议),而不是普通的IP地址。

修改

更改问题后,

无关紧要。