my dog learned polymorphism*
The moose likes Beginning Java and the fly likes using jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using jar files" Watch "using jar files" New topic

using jar files

moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
I'm sorry for this basic question....
I built a jar file , and now I want to add it to another java project.
I'm using Eclipse. I added that jar to the project and added it to the class path.
How can I call it's methods from my new class in the new project ?
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36486
Simply import the classes you intend to use in the .jar.

When you are not using Eclipse, you will have to use the -cp options for the java tool, or add the classpath to the manifest file in a new jar file.
moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
I added to the folder of my project the file hasp.jar.
I added it to the class path (with eclipse)
I write import hasp and it does nothing.
Even my jar's main class name doesn't work.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Without knowing more about how you're doing this it'll be hard to help.

If the library is included in the project's path then importing a class and using it will work fine: could you include the relevant portions of source (the import, how you're trying to use the import) and the specific error you get?
moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
I added again the jar to the classpath and now it looks fine.
I don't know what is different...
Thanks anyways.
I agree. Here's the link:
subject: using jar files
Similar Threads
two equal jar's in the same eclipse project
jboss-ide ClassNotFoundException
help locating java.sql
How to make our own jar files and how to acess the methods in the jar
Error : class not found exception : com.mysql.jdbc.driver in eclipse Tool