Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我做了这个非常简单的java文件:
public class LibTest { public int mySum(int a, int b){ return a + b; } }
然后我将它导出为 jar 文件(使用 Eclipse 向导)。
然后我想在不同的Java项目中导入这个jar并使用方法mySum。
mySum
我将该 jar 导入为Referenced Library,但我不知道如何从我的代码中调用该方法。
Referenced Library
我能怎么做?
首先导入类:
import mypackage.LibTest;
然后实例化它并调用方法:
public static void main(String[] args) { LibTest libTest = new LibTest(); System.out.println(libTest.mySum(1,1)); }
在您的 java 类中添加一个 import 语句,然后使用该类。例如:导入 com.mypackage.MyClass;