0

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?

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.