#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Executing sh script in remote server


    Hi,

    I am trying to execute a sh script which is there in the remote server. Below is the code.

    Code:
    import net.neoremind.sshxcute.core.ConnBean;
    import net.neoremind.sshxcute.core.IOptionName;
    import net.neoremind.sshxcute.core.Result;
    import net.neoremind.sshxcute.core.SSHExec;
    import net.neoremind.sshxcute.exception.TaskExecFailException;
    import net.neoremind.sshxcute.task.CustomTask;
    import net.neoremind.sshxcute.task.impl.ExecCommand;
    import net.neoremind.sshxcute.task.impl.ExecShellScript;
    
    public class RemSer {
    
            public static void main(String[] args) {
                    SSHExec ssh = null;
                    try {
                            SSHExec.setOption(IOptionName.HALT_ON_FAILURE, false);
                            ConnBean cb = new ConnBean("10.23.227.80", "oracle","oracle123");
                            ssh = SSHExec.getInstance(cb);
                            CustomTask task4 = new ExecShellScript("/home/oracle","./test.sh","hello world");
                            ssh.connect();
                            Result res = ssh.exec(task4);
                            System.out.println("All tasks finished");
                    } catch (TaskExecFailException e) {
                            System.out.println(e.getMessage());
                            e.printStackTrace();
                    } catch (Exception e) {
                            System.out.println(e.getMessage());
                            e.printStackTrace();
                    } finally {
                            ssh.disconnect();
                    }
            }
    };
    I have defined the jar file path in CLASSPATH
    It is getting compiled but when i execute that using the command java -classpath . RemSer then im getting the below error

    Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: net/neoremind/sshxcute/exception/TaskExecFailException
    Caused by: java.lang.ClassNotFoundException: net.neoremind.sshxcute.exception.TaskExecFailException
            at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
    Could not find the main class: RemSer. Program will exit.
    Can anybody pls tell whats the problem with the code.
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    The -classpath option overrides the environment variable. Include your Jar file as part of the -classpath option.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    @stdunbar

    Thank u very much sir

IMN logo majestic logo threadwatch logo seochat tools logo