[英]How can I create and Import Libraries in Netbeans - A Full Documented Q
It's me again. 又是我。 So here's the deal, I still don't really grasp if I am doing something wrong. 所以这是一笔交易,如果我做错了什么,我仍然不太了解。
I am trying to create my own Personal Library, in which I have certain string methods and so on. 我正在尝试创建自己的个人库,其中有某些字符串方法,等等。
I've started by creating a new Project as a Java library: 我首先创建了一个新的Project作为Java库:
Then I've added a package to that library: 然后,我向该库添加了一个包:
After that I've created a class in said package: 之后,我在上述包中创建了一个类:
Here the code of my class: 这是我班上的代码:
And cleaned and built that Class//Library. 并清理并构建了该Class // Library。 Run -> Clean and Build
And afterwards created the JavaDoc Run -> Generate JavaDoc(MyTestLibrary)
然后创建JavaDoc Run -> Generate JavaDoc(MyTestLibrary)
After doing this i decided to add my newly created Library to the Libraries under Tools - > Libraries
: 之后,我决定将我新创建的库添加到“ Tools - > Libraries
“库”下的“ Tools - > Libraries
:
After that I've added a new Library (bottom right) and named it TestLibrary: 之后,我添加了一个新的库(右下方)并将其命名为TestLibrary:
SO decided to add the .jar File first. 因此,决定先添加.jar文件。 I clicked on the “Add JAR/Folder... ” Option and searched for my Projekt Folder (from MyTestLibrary) and went in to the “dist” folder and selected the .jar file: 我单击“添加JAR /文件夹...”选项,并搜索我的Projekt文件夹(来自MyTestLibrary),然后进入“ dist”文件夹并选择.jar文件:
After that I've added the “src”-Folder in “Sources” and the “javadoc”-Folder in “Javadoc”. 之后,我在“ Sources”中添加了“ src”-文件夹,在“ Javadoc”中添加了“ javadoc”-文件夹。
After i was finished it was time to create a new Project, to be precise a new Java Application, and try to import my freshly created library. 完成后,是时候创建一个新项目,准确地说是一个新的Java应用程序,并尝试导入我新创建的库了。 I rightclicked on Libraries and clicked on “Add Library...”: 我右键单击库,然后单击“添加库...”:
And imported my Test Library and adding it: 并导入我的测试库并添加它:
Happy that I've added my Library to my application I decided to import it import TestPackage.TestClass;
很高兴我已经将自己的库添加到了我的应用程序中,所以我决定将其import TestPackage.TestClass;
. 。
If I try 如果我尝试
public static void main(String[] args)
{
TestClass.
}
The only suggestion is TestClass.class
and not TestClass.TestMethod
. 唯一的建议是TestClass.class
而不是TestClass.TestMethod
。
Why can't I access the methods of the “TestClass” directly? 为什么我不能直接访问“ TestClass”的方法?
How can I see them? 我怎么看到他们?
I've tried being as specific as possible. 我尝试过尽可能具体。 I hope this time I can fully understand what is going on and why I can't access them. 我希望这次我能完全理解发生了什么以及为什么我无法访问它们。
The solution was fairly simple and obvious. 解决方案非常简单和明显。
To access the methods without the need of creating an instance of the class i just had to declare them static
. 要访问这些方法而无需创建类的实例,我只需要将它们声明为static
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.