Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default running program on sftp server not working

    Hi. I have a java project in Eclipse and I want to be able to run it on an SFTP server. It has 3 class files and 2 external jars, but you start it by running 1 of the class files (Program.class). So I copied the folder of the project onto the server and used terminal to ssh the server and run the class file. in terminal I typed:
    Java Code:
    java Program
    It started to run but when the code tries to use a method from a different class file, I get the error:

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Store
    	at Program.main(Program.java:44)
    Caused by: java.lang.ClassNotFoundException: javax.mail.Store
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    	... 1 more
    How do I fix this?

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Are the class files in a package? Because, if so, java requires you launch the class file from outside the package like so:
    java packageName/MyApp

    Also, you might need to specify a classpath on launch. Take a look at the java man page.

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by hardcorebadger View Post
    It has 3 class files and 2 external jars
    Are you damn sure all these things are in place?
    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Store
    	at Program.main(Program.java:44)
    Caused by: java.lang.ClassNotFoundException: javax.mail.Store
    This exception above is highly pointing to a possibility that you have not placed your mail.jar file where its supposed to be, as compiler cant see it.

    Keep it in the right place Or mention -cp [or -classpath] while running your program and pass the proper class path where these files can be seen.

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  4. #4
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    K so the class files and stuff r in a folder like so

    (folder)Project
    |
    (folder)bin, (folder)src, (folder)lib
    | | |
    Project.class Project.java mail.jar
    Mailer.class Mailer.java activation.jar
    Read/Write.class Read/Write.java


    I am running "Project.class" i dont know if the .jars have to be in the same path as the classes???
    hope this helps

  5. #5
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    sorry that last folder is actually "libs"

  6. #6
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    that didn't print out the way I typed it.
    just to clarify, the jars are in libs, the .class's are in bin and the .java's are in src

  7. #7
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Here are the links that would surely help you understand how to use command line options when running your code through prompt.

    For command java : java

    For command javac: javac

    Have a look at them and figure out how you can use the -cp or -classpath to provide the path where your jar files reside. This would teach you some good things.

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  8. #8
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    I've decided the problem here is the classpath. So to make it simpler, I have the 2 jars in a folder with the 3 class files. So heres what I typed in terminal:

    java -cp .;(path to the folder) Project

    but I still have the same error. Am I doing this wrong?

  9. #9
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    Quote Originally Posted by hardcorebadger View Post
    java -cp .;(path to the folder) Project
    When you are referring to the jar files, you need to make sure that you have mentioned them at the end and not simply the path till the directory.

    So your actual command should be like,

    Java Code:
    java -cp .;(path_to_the_folder)\"name_of_jar".jar class_name

    If you are having multiple jar files to refer, then you can use the wildcard operator of java. In case, if all of your jar files are in say, D:\libs folder, then you can refer to them by using,

    Java Code:
    java -cp "D:\libs\*" class_name
    The command above will refer to all the jar files inside libs folder. Make sure to have your class path inside the double quotes; like "classpath". You will need Java 6 for usage of wildcard operator * to refer to multiple jar files.

    Hope thats clear to you now,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  10. #10
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    Ok so I do know that the problem is with classpath, because I was having the same problem on my computer so I put the jars in System/Library/Java/Extensions and now it works. But the server doesn't have something like that, so I need to set the classpath on launch. heres my command

    java -cp /home/server/(folder that classes and jars are in)/* (class name)

    but now the error is that it can't find the class itself rather than just a class in the jar files. I also tried

    export CLASSPATH=/home/server/(folder that classes and jars are in)/*
    java (class name)

    but the same error about not even fining the class file. this leads me to believe i'm still not setting the classpath correctly.

Similar Threads

  1. Replies: 4
    Last Post: 03-26-2010, 09:16 AM
  2. how to keep server running
    By Harris68 in forum Networking
    Replies: 4
    Last Post: 12-22-2009, 11:11 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 07:53 PM
  4. running multiple server
    By amitnayak1 in forum Advanced Java
    Replies: 3
    Last Post: 06-05-2008, 05:14 AM
  5. Replies: 0
    Last Post: 04-04-2008, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •