简体   繁体   English

如何在Java项目中使用* .jar文件?

[英]How to use *.jar file in a Java project?

I'm a complete novice to Java, and I'm stuck in trying to use an external jar library in a Java project I'm working on. 我是Java的新手,我一直试图在我正在研究的Java项目中使用外部jar库。

The library is Twitter4J ( http://twitter4j.org/ ), a complex group of files which I can't understand how to include. 该库是Twitter4J( http://twitter4j.org/ ),这是一组复杂的文件,我无法理解如何包含。 I'm using Eclipse on Windows. 我在Windows上使用Eclipse。 I understood the meaning of CLASSPATH enviroment variable (or well, I think I did), but I can't understand how to link it to the Eclipse enviroment. 我理解CLASSPATH环境变量的含义(或者,我认为我做过),但我无法理解如何将它链接到Eclipse环境。

This blog post seemed to be what I was looking for: http://jasperpeilee.wordpress.com/2012/01/25/how-to-set-up-twitter4j-quickly-in-your-java-project/ 这篇博文似乎是我一直在寻找的: http//jasperpeilee.wordpress.com/2012/01/25/how-to-set-up-twitter4j-quickly-in-your-java-project/

But: 但:

Add twitter4j-core-2.2.5.jar into project for general use.

1) Where should I copy the core file? 1)我应该在哪里复制core文件? In the /bin/ folder? /bin/文件夹中? Or in a completly unrelated /lib/ folder, as this question in SO stated? 或者在一个完全不相关的/lib/文件夹中,如SO中的这个问题所述?

Copy Twitter API property file into your project/bin directory.

2) What is the Twitter API property file? 2) 什么是Twitter API属性文件?

3) How can I include JavaDoc jar files too? 3) 如何包含JavaDoc jar文件? Is it possibile to get them into Elipse? 是否有可能让他们进入Elipse?

Any kind of help, even just a link, will be very appreciated! 任何形式的帮助,即使只是一个链接,将非常感谢!

You probably have a project folder for your Eclipse project. 您可能有一个Eclipse项目的项目文件夹。 Go ahead and make a lib folder inside of your project folder, in the same directory as src and bin . 继续在项目文件夹中创建一个lib文件夹,与srcbin位于同一目录中。 There's nothing special about the lib folder specifically, it's just a convenient name. lib文件夹没有什么特别的,它只是一个方便的名称。 Copy the .jar file into your newly created folder. 将.jar文件复制到新创建的文件夹中。 Back in Eclipse, right click your project and click Refresh . 回到Eclipse,右键单击您的项目,然后单击Refresh The lib folder should pop up, including your JAR! 应该弹出lib文件夹,包括你的JAR! Right click the JAR file and go to Build Path --> Add To Build Path. 右键单击JAR文件,然后转到Build Path - > Add To Build Path。 At this point, any class in the project should be able to use Twitter4J features. 此时,项目中的任何类都应该能够使用Twitter4J功能。

As for the What question, the Twitter API property file contains configuration that is necessary for the Twitter jar to function. 至于什么问题,Twitter API属性文件包含Twitter jar运行所必需的配置。 The file should probably be located on the classpath of your application. 该文件可能应位于应用程序的类路径中。

And the How question, you can attach the javadoc jar file of the Twitter jar to the Twitter jar's classpath entry in Eclipse. 如何的问题,你可以将Twitter的罐子在Eclipse Twitter的JAR的类路径条目的javadoc的jar文件。 Right-click your project and select Properties. 右键单击项目,然后选择“属性”。 Go to the Java Build Path entry and find the Twitter jar under the Libraries tab. 转到Java Build Path条目,在Libraries选项卡下找到Twitter jar。 If you expand the Twitter jar entry you will see 'JavaDoc location'. 如果展开Twitter jar条目,您将看到“JavaDoc位置”。 You can specify the javadoc jar there. 你可以在那里指定javadoc jar。

In Eclipse, right-click your project, select Properties. 在Eclipse中,右键单击项目,选择“属性”。 Now find the entry for Java Build Path and select it. 现在找到Java Build Path的条目并选择它。 Click the "Libraries" tab if it is not already selected. 如果尚未选中,请单击“库”选项卡。 Click the "Add external JARs..." button. 单击“添加外部JAR ...”按钮。 Follow the prompts. 按照提示操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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