Java - How do I use a class file?

You have to import by calling the name of source package . ie import hello.Car; . In your case you are trying to call import on JAR folder name which leads to an error "cannot find symbol" .

Let me try to give an example for better understandability

  • Consider this simple Vehicle application which has Car class and Test Car class alt text

  • Convert it into jar and add it into another project called ImportVehicleJar

    alt text http://i46.tinypic.com/qxmlxt.png

    • In order to instantiate the Car class in Main.Java file add the following as shown in figure alt text

    Hope this helps !!


In Netbeans (version 5.5.1), you can add a jar file to a project by right clicking the project name, and choosing Properties, then Libraries (from Categories), and there is an "Add JAR/Folder" button, which can be used for adding it to the compile-time and/or run-time classpath. Adding it to the Compile-time Libraries is well enough, because it will automatically added to the run-time through its "Classpath for Compiling Sources" entry.