简体   繁体   English

Eclipse将带有jar的项目添加到新项目

[英]Eclipse adding a project with jars to a new project

So I want to have a 'utility project' with all the utility classes and the utility libraries in it (say apache commons libraries under a particular directory called libs in the utility project). 因此,我想拥有一个包含所有实用程序类实用程序库的“实用程序项目”(例如,在该实用程序项目中名为libs的特定目录下的apache commons库)。 So that I can add this 'utility project' to a new project and want to use its java classes and jars both. 这样我就可以将此“实用程序项目”添加到新项目中,并希望同时使用其Java类和jar I know when you add a project you can use its java classes but can't use the jars. 我知道添加项目时可以使用其Java类,但不能使用jar。 Anyway to do this? 无论如何要这样做?

You want to create a dependency relation between the two projects. 您要在两个项目之间创建依赖关系。 This is better than just adding external JARs as it will keep track of the actual libraries in the utility project even if you change its name or location. 这比仅添加外部JAR更好,因为即使您更改了实用程序项目的名称或位置,它也会跟踪实用程序项目中的实际库。 To achieve that you need to do two things (although, I believe only step (a) is new to you. If I understand correctly you actually have already carried out (b)). 要实现这一点,您需要做两件事(尽管我相信只有步骤(a)对您而言是新的。如果我正确理解,您实际上已经进行了(b))。

(a) Go to your utility project then do: Project -> Properties -> Java Build Path -> Order and Export (a)转到实用程序项目,然后执行以下操作:项目->属性-> Java构建路径->订购并导出

Check all the JARs that you'd like to make available to the other project. 选中您要对其他项目可用的所有JAR。

在此处输入图片说明

(b) Go to the other project (the one that uses the utility project): Project -> Properties -> Java Build Path -> Projects -> Add Check the "Utility Project" (b)转到另一个项目(使用实用程序项目的项目):Project-> Properties-> Java Build Path-> Projects-> Add检查“ Utility Project”

在此处输入图片说明

You should now see your utility project in the list of projects: 现在,您应该在项目列表中看到实用程序项目: 在此处输入图片说明

In the properties of the project (from Package Explorer > Right Click > Properties) browse to 'Java Build Path' > Libraries tab. 在项目的属性中(从Package Explorer>右键单击> Properties),浏览至“ Java Build Path”>“ Libraries”选项卡。

You can then select the 'Add External JARs' button and add the required jars. 然后,您可以选择“添加外部JAR”按钮并添加所需的jar。

right click on the project where you want to add jars and then select properties . right click要添加jar的项目,然后选择properties After that select Java Build Path and then click on Add External JARs . 之后,选择Java Build Path ,然后单击Add External JARs You should be able to add jars from here. 您应该可以从此处添加jar。 See following pic, for more info. 有关更多信息,请参见以下图片。

Note : You can add reference to projects by clicking on projects tab in same window. 注意 :您可以通过在同一窗口中单击“项目”选项卡来添加对项目的引用。

在此处输入图片说明

I would suggest you try creating a new "user library" in eclipse which you can use in your projects. 我建议您尝试在eclipse中创建一个新的“用户库”,您可以在项目中使用它。

An EclipseSW User Library can be used to represent a set of jarW files. EclipseSW用户库可用于表示一组jarW文件。 This user library can be added to a project's classpathW. 可以将该用户库添加到项目的classpathW中。 Thus, a user library can be a convenient way to add a set of jar files (rather than individual jar files) to a project's build path. 因此,用户库可能是将一组jar文件(而不是单个jar文件)添加到项目的构建路径的便捷方法。 Here, I'll create a user library for a set of TomcatSW jar files. 在这里,我将为一组TomcatSW jar文件创建一个用户库。

To create a user library, you can go to Window → Preferences and go to JavaSW → Build Path → User Libraries. 要创建用户库,可以转到窗口→首选项,然后转到JavaSW→构建路径→用户库。 I'll click the New button to create a new user library. 我将单击“新建”按钮来创建一个新的用户库。

More on user libraries at this link 有关此链接的更多用户库

http://www.avajava.com/tutorials/lessons/how-do-i-create-an-eclipse-user-library-for-the-tomcat-jar-files.html http://www.avajava.com/tutorials/lessons/how-do-i-create-an-eclipse-user-library-for-the-tomcat-jar-files.html

Other ways of doing this at the link below 在下面的链接中执行此操作的其他方法

http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java) http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)

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

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