Stefan Carlson
Stefan Carlson

Reputation: 372

Calling a method from another jar file

I'm still kind of new to java, and one thing I haven't had to work with until now is calling a method from a class that is not in a package that is part of that particular project. I have two jars: ai.jar and functions.jar. Inside functions.jar I have a bunch of classes right inside, so they aren't in folders or anything. Inside ai.jar, I have a class that accesses a particular method inside ai.jar. I've tried to create a reference variable by using functions.jar/get.class and various other things like that, but I always get a classnotfoundexception. How do I do this? Thanks!

Upvotes: 1

Views: 12073

Answers (2)

Alex Goja
Alex Goja

Reputation: 548

I assume you want to import a jar into your project, for that the instructions are presented below:

  1. Step 1. Right click on your project
  2. Step 2. Select "Build Path"
  3. Step 3. Then select "Configure Build Path"
  4. Step 4. Select "Add external jar", then browse to the location of your desired jar.

Hope it helps.

Upvotes: 4

Suresh Atta
Suresh Atta

Reputation: 122026

You have to add them to your Build path of your project.

Then you just need to import that class.

Then create the instance of particular class if it is a instance method.

Other wise ClassnameInJar.method(); if it is a static class.

See examples with screen shots

Upvotes: 8

Related Questions