简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM