[英]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 第一种方式
ProjectA
and export as jar file. ProjectA
并导出为jar文件。 ProjectB
, Goto Build path -> Configure build path -> Libraries ProjectB
,转到构建路径 - >配置构建路径 - >库 ProjectA
ProjectA
外部jar Second Way, 第二种方式,
ProjectB
, Goto Build path -> Configure build path -> Projects ProjectB
,转到构建路径 - >配置构建路径 - >项目 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.