用于导入JAR文件的Java代码 [英] Java code to import JAR file
问题描述
我创建了一个JAR文件,然后将其添加到我项目的构建路径中。现在我如何将它导入我的班级,以便我可以使用它?到目前为止我只尝试 import java-class.jar;
。
I created a JAR file and then added it to my project's build path. Now how do I import it to my class so I can use it? I've only tried import java-class.jar;
so far.
推荐答案
您在Java源代码中导入类,而不是jar文件。
You import classes, not jar files, in your Java source code.
假设您有 someJar.jar
,其中包含3个类的类定义, FirstClass .class
, SecondClass.class
和 ThirdClass.class
,所有这些都在包中 org.somepackage
。
Lets assume you have someJar.jar
which contains class definitions for 3 classes, FirstClass.class
, SecondClass.class
and ThirdClass.class
, all of which are in package org.somepackage
.
鉴于上述情况,您需要添加
Given the above, you would add
import org.somepackage.FirstClass
at the导入名为 FirstClass
的类的源文件的顶部。
at the top of a source file to import the class called FirstClass
.
这篇关于用于导入JAR文件的Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!