aspose file tools*
The moose likes Beginning Java and the fly likes Using a class from a Jar File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using a class from a Jar File" Watch "Using a class from a Jar File" New topic
Author

Using a class from a Jar File

Benjamin Thvedt
Ranch Hand

Joined: Jul 29, 2011
Posts: 31
I was working through the excercises in this website's cattle drive section but then I got to one where it said I have to dowload a jar file and use a class in there. So I found out how to extract files from a jar file using the -xf command, but I feel like I am missing something. Am I supposed to just extaract the files, find the class files I need, and put it in the same folder as the program I'm writing? Or is there a better way? I tried using a package statment, because all the class files are in a series of folders com/javaranch/common but it doesn't seem to be working.
Stefaan Dutry
Ranch Hand

Joined: Sep 17, 2010
Posts: 32

Hello, Benjamin.

When you are asked to use a class from a jar file, they want you to do the following:
  • download the jar file
  • add the jar to your classpath
  • use an import statement for the class


  • check the -classpath option of both the javac and the java command
  • javac command
  • java command


  • For how to use import statement, see the following :
  • import statements
  • Benjamin Thvedt
    Ranch Hand

    Joined: Jul 29, 2011
    Posts: 31
    Ah. Thanks a lot!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Using a class from a Jar File