简体   繁体   English

如何包含另一个项目中的Java包

[英]How to include java packages from another project

I might be thinking of this incorrectly, I'm coming from a visual studio background. 我可能是错误地想到了这一点,因为我来自视觉工作室。 Here is the problem I have. 这是我的问题。 I have 3 projects, ProgramA, ProgramB, and ProgramBase. 我有3个项目,ProgramA,ProgramB和ProgramBase。 Each exist in a separate Java project, ProgramBase contains common functionality that I want both ProgramA and ProgramB to use. 每个都存在于一个单独的Java项目中,ProgramBase包含我希望ProgramA和ProgramB都使用的通用功能。 How do I achieve this? 我该如何实现? All I can find are examples of all three being packages within the same project. 我所能找到的都是同一个项目中所有三个包的示例。 what happens if ProgramA is developed for one company, and ProgramB is another company, and ProgramBase is some common code I've developed? 如果ProgramA是为一家公司开发的,而ProgramB是另一家公司的,而ProgramBase是我开发的一些通用代码,会发生什么情况呢? Surely I don't have to have ProgramA and ProgramB in the same project to be able to access the package(s) of ProgramBase? 当然,我不必在同一项目中拥有ProgramA和ProgramB就能访问ProgramBase的程序包吗?

If I were doing this in visual studio, ProgramA would be one solution, ProgramB would be another solution, and ProgramBase would be a project which is included into each solution. 如果我在Visual Studio中进行此操作,则ProgramA将是一个解决方案,ProgramB将是另一个解决方案,而ProgramBase将是一个包含在每个解决方案中的项目。 If I do this in java, because the package has to be under to src directory, I don't know how both projects can include it? 如果我在Java中执行此操作,因为该程序包必须位于src目录下,所以我不知道两个项目都可以包含它吗?

Thank you for any help or resources. 感谢您的帮助或资源。

If you are using eclipse ide, you can do something like go to ProgramA -> right click Properties -> Java Build Path -> Project -> Add 如果您使用的是eclipse ide,则可以执行以下操作:转到ProgramA -> right click Properties -> Java Build Path -> Project -> Add

在此处输入图片说明

If you using command line to compile , just do javac -classpath <location of your ProgramBase Jar file . 如果使用命令行进行编译,则只需执行javac -classpath <location of your ProgramBase Jar file

您可以创建一个ProgramA和ProgramB都可以包含的jar文件。

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

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