Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a class from a Jar File

 
Benjamin Thvedt
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ah. Thanks a lot!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic