user2256790
user2256790

Reputation: 111

How do I use same method in different Java projects

I use method A in several different Java projects. Is there a way to write the method just once and then call it as required from different Java projects?

Upvotes: 0

Views: 115

Answers (2)

AmitG
AmitG

Reputation: 10553

Yes. Define public class and define at least public or protected method. Then import that class in your new project's class and use it.
default classes with public or protected methods are not accessible in different projects/packages even if default class' methods are public/protected.
So use public class and public or protected methods and at last create a jar with this file and add this jar file in your project to use.

Upvotes: 0

Sudhanshu Umalkar
Sudhanshu Umalkar

Reputation: 4202

Create a class with that method. Create a jar for this class. Use this jar in all your projects.

Upvotes: 6

Related Questions