File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 37958
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.
jQuery in Action, 2nd edition
subject: using jar files
Similar Threads
Error : class not found exception : com.mysql.jdbc.driver in eclipse Tool
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