[英]Better way to add the dependency projects to the classpath?
I am developing a java application using Eclipse IDE, I have two projects SampleProject1 and SampleProject2, SampleProject2 depends on the SampleProject1. 我正在使用Eclipse IDE开发Java应用程序,我有两个项目SampleProject1和SampleProject2,SampleProject2取决于SampleProject1。 I found the two ways to add the dependency project.
我发现了添加依赖项项目的两种方法。 1) Make a jar of SampleProject1 and include it in the SampleProject2 libs with the following classpath entry.
1)制作一个Jar SampleProject1,并将其包含在带有以下类路径条目的SampleProject2库中。 2) Export the source of SampleProject1 like below Please let me know if my understanding is not correct?
2)像下面那样导出SampleProject1的源代码如果我的理解不正确,请告诉我?
Queries: 1) Which is the best to add dependency project? 查询:1)最好添加依赖项项目? 2) in the second approach, what is meant by "combineaccessrules="false"? Is it really required?
2)在第二种方法中,“ combineaccessrules =“ false”是什么意思?
To tell Eclipse about the dependency, you can set the Java Build Path
in SampleProject2
to require the SampleProject1
. 要告诉Eclipse依赖关系,可以在
SampleProject2
中将Java Build Path
设置为需要SampleProject1
。
SampleProject2
in this case) SampleProject2
) Properties
Properties
Java Build Path
on the left hand side Java Build Path
Projects
tab. Projects
选项卡。 Add...
Add...
SampleProject1
in this case) SampleProject1
) OK
until you have closed everything. OK
直到关闭所有内容。 Here is a screenshot of your destination for the above: 这是上述目的地的屏幕截图:
Take two projects named as you have them. 以您拥有的两个项目命名。 Here is what I have on disk (excluding non java and .project files):
这是磁盘上的内容(非Java和.project文件除外):
$ find * -name *.java -o -name .project
RemoteSystemsTempFiles/.project
SampleProject1/.project
SampleProject1/src/com/example/sampleproject1/UsefulClassNeededElsewhere.java
SampleProject2/.project
SampleProject2/src/com/example/sampleproject2/ClassThatNeedsSomethingUseful.java
ClassThatNeedsSomethingUseful: ClassThatNeedsSomethingUseful:
package com.example.sampleproject2;
import com.example.sampleproject1.UsefulClassNeededElsewhere;
public class ClassThatNeedsSomethingUseful {
private UsefulClassNeededElsewhere useful = new UsefulClassNeededElsewhere();
public UsefulClassNeededElsewhere getUseful() {
return useful;
}
}
UsefulClassNeededElsewhere: UsefulClassNeededElsewhere:
package com.example.sampleproject1;
public class UsefulClassNeededElsewhere {
}
And finally the dependency set up as described above. 最后如上所述建立依赖关系。 That should make everything work, and your workspace should look like this:
那应该使一切正常,您的工作区应如下所示:
As you can see, no error markers. 如您所见,没有错误标记。
You still need your build system to know about this dependency. 您仍然需要构建系统来了解这种依赖性。 ie your Ant file or other will need to know.
即您的Ant文件或其他文件将需要知道。 Some build systems have excellent tooling in Eclipse, so that the dependencies will be calculated from the build system instead of manually replicated in the settings.
一些构建系统在Eclipse中具有出色的工具,因此依赖项将从构建系统中计算出来,而不是在设置中手动复制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.