简体   繁体   English

如何在 Eclipse 中引用不同的 Java 项目

[英]How to reference a different Java project in Eclipse

I have Project1 and Project2.我有项目 1 和项目 2。 Project1 is dependent of Project2. Project1 依赖于 Project2。 I am sort of tired that every time I make some code changes in Project2, I have to Export Project2 JAR file, and copy it into lib folder of Project1.我有点累,每次我在 Project2 中进行一些代码更改时,我都必须导出 Project2 JAR 文件,并将其复制到 Project1 的 lib 文件夹中。

Is there a way to achieve this automatically?有没有办法自动实现这一目标? Or, is there any other way to let know Project1 that Project2 had some changes?或者,是否有任何其他方式让 Project1 知道 Project2 发生了一些变化?

In Build Path of the project, there is a way to specify references to other projects in Workspace, but this doesn't seem to do anything?在项目的Build Path中,有一种方法可以指定对Workspace中其他项目的引用,但这似乎没有任何作用? What does it actually do?它实际上做了什么?

I was reading somewhere that I can use Deployment Properties to automatize this process, but I can't find it.我在某个地方读到我可以使用部署属性来自动化这个过程,但我找不到它。

UPDATE: Uh, I am C# developer and have some experience in Java development (mostly Android development), I might ask stupid questions, so please bear with me...更新:呃,我是C#开发者,有一些Java开发经验(主要是Android开发),我可能会问一些愚蠢的问题,所以请耐心等待...

Project1 is standard Java Project (Run on client's machine, uses swing, etc..). Project1 是标准的 Java 项目(在客户端机器上运行,使用 swing 等)。 Project2 is Dynamic Web Project (for to me unknown reason). Project2 是 Dynamic Web Project(我不知道原因)。 The only thing it does is calling webservice (third project I don't need to worry about) and passing result back to Project1.它唯一做的就是调用 webservice(我不需要担心的第三个项目)并将结果传回 Project1。 Project2 contains those Axis2 webserviceStub.java files... Every know and then, I have to recreate these stub files then I have to export JAR file and move it to Project1. Project2 包含那些 Axis2 webserviceStub.java 文件......众所周知,我必须重新创建这些存根文件,然后我必须导出 JAR 文件并将其移动到 Project1。 Project2, even though it is Web Project, it is actually code that runs on client. Project2,虽然是Web Project,但实际上是在客户端运行的代码。

Just simple project referencing in Build Path doesn't work for me.仅在构建路径中引用简单的项目对我不起作用。

Thanks谢谢

Right click on Project1 , then click on Properties .右键单击Project1 ,然后单击属性 In the dialog that comes up, select Java Build Path , and then click on the Projects tab.在出现的对话框中, select Java Build Path ,然后单击Projects选项卡。 There, add Project2 to the build path.在那里,将 Project2 添加到构建路径。

If Project1 is a web app, you need to make sure your Deployment Assembly (same Properties UI) has Project2 there as well.如果Project1是一个 web 应用程序,您需要确保您的部署程序集(相同的属性UI)也有Project2

In Eclipse, when a Java project is built, every .java file from source folders is compiled and the .class file is saved into an output folder.在 Eclipse 中,当构建 Java 项目时,编译源文件夹中的每个.java文件,并将.class文件保存到 output 文件夹中。 The non-java files from the source folder are copied unchanged to the corresponding folder hierarchy in the output folder.源文件夹中的非 java 文件将原封不动地复制到 output 文件夹中的相应文件夹层次结构中。

When adding "referenced projects" within a workspace in Eclipse via Java Build Path , ie adding Project2 to Project1 's build path, what you are actually doing is telling the project builder to use the output folder of Project2 when building Project1 (NOTE: not only the output folder, but also exported libraries).当通过Java Build Path在 Eclipse 的工作区中添加“引用项目”时,即将Project2添加到Project1的构建路径时,您实际做的是告诉项目构建器在构建Project1时使用Project2的 output 文件夹(注意:不是只有 output 文件夹,但也导出库)。

So if the answer from kozyr does not work for you, check the "output folder" configuration of Project2 .因此,如果kozyr的答案对您不起作用,请检查Project2的“输出文件夹”配置。

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

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