Stefan Carlson Stefan Carlson - 7 months ago 48
Java Question

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

and various other things like that, but I always get a classnotfoundexception. How do I do this? Thanks!


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