-1

在下面的代码中,我通过单击项目属性导入了 jsch jar,并通过添加“添加外部 jar 按钮”也已从以下链接添加外部 jar添加到 ant 全局路径中, 但是当我运行程序时,我仍然得到“java.lang.NoClassDefFoundError:com.jcraft.jsch.JSch”

 package android_jsch.com;


  import java.io.PrintStream;
  import java.util.ArrayList;
  import java.util.List;

  import android.app.Activity;
  import com.jcraft.jsch.*;
  import android.os.Bundle;
  import android.widget.EditText;

  public class Android_jschActivity extends Activity {
     EditText ip,username,password;
     @Override
      public void onCreate(Bundle savedInstanceState) {
        List<String> commands = new ArrayList<String>();
          commands.add("touch /tmp/test1.txt");
          commands.add("touch /tmp/test2.txt");
          commands.add("touch /tmp/test3.txt");
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
        rd);

          try {
              JSch jsch = new JSch();


              session.connect();

              Channel channel=session.openChannel("shell");//only shell
              channel.setOutputStream(System.out);
              PrintStream shellStream = new PrintStream(channel.getOutputStream());  // printStream for convenience
              channel.connect();
              for(String command: commands) {
                  shellStream.println(command);
                  shellStream.flush();
              }

              Thread.sleep(5000);

              channel.disconnect();
              session.disconnect();
          } catch (Exception e) {
              System.err.println("ERROR: Connecting via shell to "+ip.getText().toString());
              e.printStackTrace();
          }
      }


      private static void setUpHostKey(Session session) {
          java.util.Properties config = new java.util.Properties();
          config.put("StrictHostKeyChecking", "no");
          session.setConfig(config);
      }

     }
4

1 回答 1

0

您应该指定构建 apk 时必须导出 jar:在“Java Build Path”>“Order and Export”选项卡中,填写与您的 jar 对应的复选框。

于 2012-08-30T14:39:14.660 回答