简体   繁体   English

如何将文件从一个eclipse项目导入另一个

[英]how to import file from one eclipse project to another

I know this question must have been asked before and i have gone through the solution but that didnt seem to solve my question. 我知道这个问题之前一定是问过,我已经完成了解决方案,但这似乎没有解决我的问题。 Suppose I have 2 projects in eclipse .ProjectA and ProjectB and ProjectA has file named FileA in package PackageA and ProjectB has a file named FileB in PackageB.Suppose i want to use a function of FileA in projectB.Is there any import statement which will allow me to do so.I dont want to copy paste the entire fileA in projectB.I just want something like 假设我在eclipse中有2个项目.ProjectA和ProjectB和ProjectA在包PackageA中有一个名为FileA的文件,而ProjectB在PackageB中有一个名为FileB的文件。我希望在projectB中使用FileA的一个函数。是否有任何import语句允许我这样做。我不想复制粘贴在projectB中的整个fileA。我只想要类似的东西

import ProjectA.packageA.fileA
class fileB
{
//calling function from fileA
int somethingsomething = fileA.somefunction();
}

I have done things like go to project right click and click on import and import the file.But i dont want the file to be present in my filelist of ProjectB.Please ,Can someone help me with this problem.Is this even possible? 我做过像项目右键单击并单击导入并导入文件。但我不希望文件出现在我的ProjectB文件列表中。请问有人可以帮我解决这个问题。这甚至可能吗?

First way 第一种方式

  1. Right click on ProjectA and export as jar file. 右键单击ProjectA并导出为jar文件。
  2. Right click on ProjectB , Goto Build path -> Configure build path -> Libraries 右键单击ProjectB ,转到构建路径 - >配置构建路径 - >库
  3. Add external jar of ProjectA 添加ProjectA外部jar

Second Way, 第二种方式,

  1. Right click on ProjectB , Goto Build path -> Configure build path -> Projects 右键单击ProjectB ,转到构建路径 - >配置构建路径 - >项目
  2. Click on Add, select ProjectA from list. 单击“添加”,从列表中选择“ ProjectA

After this, you will be able to import classes in ProjectB which are defined in ProjectA by, 在此之后,你就可以导入类ProjectB ,其定义在ProjectA的,

import packageA.fileA

Read more at : Java build path 阅读更多: Java构建路径

Well your Project B needs the code of File A to execute it. 那么你的Project B需要文件A的代码来执行它。 You can either copy the file, or a .jar, or you copy the relevant code into the new project. 您可以复制文件或.jar,也可以将相关代码复制到新项目中。 You cannot just reference a piece of code but not add it to your Project in some way. 您不能只引用一段代码,而不能以某种方式将其添加到您的项目中。 When building your project to a .jar for example, this piece of information must be present and accessible for the program. 例如,当您将项目构建到.jar时,此信息必须存在并且可供程序访问。

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

相关问题 如何将一个Eclipse项目作为库导入另一个? - How to import one Eclipse project as a library into another? 从eclipse中的另一个java项目导入 - import from another java project in eclipse 如何将工件从一个子项目导入到多模块项目中的另一个子项目中? - How to import artifact from one subproject into another in multimodule project? 如何将 JUnit 测试从一个 Maven 项目导入到另一个项目? - How to import JUnit tests from one Maven project into another? 如何在一个Eclipse项目中为另一个Eclipse项目中的类编写测试? - How can I write tests in one Eclipse project for classes from another Eclipse project? Eclipse如何将jar文件导入为Maven项目 - Eclipse how to import a jar file as a maven project 在java中,如何将一个项目导入另一个项目而不将它们放在同一个(Eclipse)工作区中? - In java, how do you import one project into another without having them in the same (Eclipse) workspace? 如何将一个 eclipse 项目的方法/变量调用到另一个 eclipse 项目? - How to call method/variable of one eclipse project to another eclipse project? 将@Configuration类从一个项目导入到另一个项目 - Import @Configuration class from one project to another springboot 将类从一个项目导入到另一个项目 - springboot import classes from one project to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM