Results 1 to 12 of 12
  1. #1
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Question Adding jar to classpath.

    I want to add a .jar file to the classpath, but I don't know how.

    "
    SimpleFTP is a Java FTP client package that lets you connect to FTP servers and upload files.

    Download simpleftp.jar
    Using SimpleFTP in your Java programs

    To use SimpleFTP, simply add simpleftp.jar to your classpath and import the package in whichever classes will use it.

    import org.jibble.simpleftp.*;

    "

    So I downloaded it, but now what? In what folder should I put it?
    Because if I do
    import org.jibble.simpleftp.*;
    now, when compiling it to a class file it says it cannot find the
    import org.jibble.simpleftp.*;
    ..


    DudeJonne

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    765
    Rep Power
    6

    Default

    Do u want in windows or Linux/unix?
    Ramya:cool:

  3. #3
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    Just in windows.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    If you are using an IDE then add the jar file to your project's build path. (More details for this are supplied in your IDE's help files).

    If you are compiling from the command line then add the -classpath flag to javac and supply the path to the jar file including the jar file's name. More details of this can be obtained by typing javac -help on the command prompt.

  5. #5
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    Okay I typed:
    javac -classpath C:\simpleftp.jar

    And got this error:
    C:\>javac -classpath C:\simpleftp.jar
    javac: no source files
    Usage: javac <options> <source files>
    use -help for a list of possible options

    I don't really get it, since -classpath is the option and C:\simpleftp.jar are the files..

  6. #6
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    No one who knows?

  7. #7
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    javac -classpath C:\simpleftp.jar
    You mostly had it, for running javac, specify the classpath like that, but we still need to specify the java file to be compiled
    Java Code:
    javac -classpath c:\simpleftp.jar *.java
    (such as in your java sources folder).
    another option, if you ar using eclipse, or other IDE, and have our sources in a project, create a folder (e.g. lib) and place the jar file in there, and have the jar file added to the project's classpath.

    you will also need to have the jar file in the classpath when running your compiled code.

    Java Code:
    java -classpath c:\simpleftp.jar;. mypackage.mycode
    where assuming you un java from the folder that contains your package and your class file.

    If you in turn bundle your code into a jar file, then the classpath would reference both jar files.
    Java Code:
    java -classpath c:\simpleftp.jar;c:\myproject\myjar.jar mycode
    If you have constructed your jar file to be executable, such as set the Main-Class attribute in the manifest file when building the jar file, then just java -jar myfile.jar would also work.

  8. #8
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    but then how would I import that package?

  9. #9
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    well, from the first description it looks like this simpleftp.jar is more of an API, and not a full functional self-contained program, as when it sais to import its classes,
    import org.jibble.simpleftp.*;
    this likely means you would create a myclient.java file, with this in the imports

    Java Code:
    import org.jibble.simpleftp.*;
    
    public class myFtpClient {
      //TODO; methods where you would invoke their FTP thingie.
    }

  10. #10
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    Never mind, I just worked, thanks

  11. #11
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    Its just too bad I keep getting errors, I never know what they mean, like this when I run the image.class:

    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jibbl
    e/simpleftp/SimpleFTP

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dudejonne View Post
    Okay I typed:
    javac -classpath C:\simpleftp.jar

    And got this error:
    C:\>javac -classpath C:\simpleftp.jar
    javac: no source files
    Usage: javac <options> <source files>
    use -help for a list of possible options

    I don't really get it, since -classpath is the option and C:\simpleftp.jar are the files..
    You should read javac's error diagnostic message: it doesn't have anything to do because you didn't supply it at least one source file to compile, i.e. you have set it all up by supplying a classpath but no .java source file.

    kind regards,

    Jos

Similar Threads

  1. help me to set classpath
    By srinivaspuvvala in forum Java Servlet
    Replies: 3
    Last Post: 01-18-2009, 07:13 PM
  2. Classpath
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 06-20-2008, 09:00 AM
  3. GNU Classpath 0.96.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-01-2007, 04:14 PM
  4. GNU Classpath 0.96
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-16-2007, 06:35 PM
  5. Adding JARs to the classpath at runtime?
    By johann_p in forum Advanced Java
    Replies: 1
    Last Post: 06-26-2007, 10:42 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
  •