简体   繁体   English

将依赖项目添加到类路径的更好方法?

[英]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

Step-by-step: 一步步:

  1. Right-click on the Java project ( SampleProject2 in this case) 右键单击Java项目(在这种情况下为SampleProject2
  2. choose Properties 选择Properties
  3. Within the properties, choose Java Build Path on the left hand side 在属性中,选择左侧的Java Build Path
  4. Select the Projects tab. 选择Projects选项卡。
  5. Press Add... Add...
  6. Select the dependent project ( SampleProject1 in this case) 选择相关项目(在这种情况下为SampleProject1
  7. Press OK until you have closed everything. OK直到关闭所有内容。
  8. It should now work for you. 现在它应该为您工作。

Here is a screenshot of your destination for the above: 这是上述目的地的屏幕截图:

Java构建路径

Example of it working 它工作的例子

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: 那应该使一切正常,您的工作区应如下所示:

DEPS

As you can see, no error markers. 如您所见,没有错误标记。

Things to keep in mind 注意事项

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.

相关问题 两个Eclipse项目之间的依赖性:如何将一个人的类路径添加到第二个人的类路径中? - Dependency between two Eclipse projects: how to add one's classpath into second's? gradle 项目是否有等效的“mvn 依赖项:build-classpath”? - Is there an equivalent `mvn dependency:build-classpath` for gradle projects? 使用 Gradle 将提供的依赖项添加到测试类路径 - Add provided dependency to test classpath using Gradle Eclipse 运行配置:如何添加已添加到 Classpath 的项目的 Maven 依赖项 - Eclipse Run Configurations: how to add Maven dependencies of projects added to Classpath 如何从 jasper 报告中的项目类路径中添加图像作为参数 - How to add image as parameter from projects classpath in jasper reports 将已安装的库添加到类路径的正确方法是什么? - What is the correct way to add installed libraries to classpath? 将类路径添加到build.xml的最佳方法 - Best way to add classpath to build.xml 在gradle中将类路径添加到ant任务的最佳方法 - best way to add classpath to ant task in gradle Gradle:是否有更好的方法将相同的依赖项分配给2种配置? - Gradle: Is there a better way to assign the same dependency to 2 configurations? JcaPEMKeyConverter 由 BouncyCastle 提供,这是一个可选依赖项。 要使用对 EC 密钥的支持,您必须显式地将依赖项添加到类路径 - JcaPEMKeyConverter is provided by BouncyCastle, an optional dependency. To use support for EC Keys you must explicitly add dependency to classpath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM