在IntelliJ中的模块之间共享Java包? [英] Sharing Java packages between modules in IntelliJ?

查看:823
本文介绍了在IntelliJ中的模块之间共享Java包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何在一个IntelliJ项目中共享两个模块之间的包,而我似乎无法找到正确的方法来实现它。我知道它可以在Eclipse中完成,但我不是很精通它。简而言之,我正在尝试重现由AppEngine连接的Android项目创建的相同类型的项目环境。

I'm trying to figure out how can I share packages between two modules in a single IntelliJ project, and I can't seem to find the right way to do it. I know it can be done in Eclipse, but I'm not very well-versed with it. In a nutshell, I'm trying to reproduce the same kind of project environment created by AppEngine-connected Android projects.

这是最好的问题我可以放置它out

Here's the "problem" as best I can lay it out

项目A。


  • 模块1; AppEngine + GWT +其他任何

  • 模块2; Android

每个模块在项目主目录中都有自己的源目录:

Each module has its own source directory within the Project's main directory:


  • / ProjectA / Module1 / src

  • / ProjectA / Module2 / src

我为两个模块创建包,并编写每个模块所需的各种类。大多数类对于模块/平台是唯一的,并且被打包到它们自己的命名空间中

I create packages for both modules, and write the various classes needed for each. Most classes are unique to the module / platform, and are packaged into their own namespace

模块1


  • com.example.myproject.server

  • com.example.myproject.server.domain

  • com.example.myproject。 server.services

  • ...

  • com.example.myproject.server
  • com.example.myproject.server.domain
  • com.example.myproject.server.services
  • ...

模块2


  • com.example.myproject.client

  • com.example.myproject.client.activities

  • com.example.myproject.client.fragments

  • ...

  • com.example.myproject.client
  • com.example.myproject.client.activities
  • com.example.myproject.client.fragments
  • ...

但是,我在两个模块中都使用了一些相同的接口和枚举:现在我想将所有相同的代码放在两者之间共享的单个包中,因此每次更改时我都不必在包之间复制源代码周围的东西。

However, there are some identical Interfaces and Enums that I use within both modules: Now I'd like to have all my identical code in a single package shared between the two, so I don't have to copy the source between packages every time I change something around.


  • com.example.myproject.shared

  • com.example.myproject.shared .interfaces

  • ...

我知道IntelliJ会让您配置多个内容根作为模块配置的一部分。但是,如果它们属于同一个IntelliJ项目,那么两个模块似乎并不共享相同的内容根目录......?有没有更好的方法来配置我的项目?或者我错过了什么..?

I know IntelliJ will allow you to configure multiple content Roots as part of a module's configuration. But it doesn't seem that two modules care share the same content root if their part of the same IntelliJ Project...? Is there a better way to configure my project? Or am I missing something..?

推荐答案

您可以将共享代码移动到另一个具有自己内容根的模块中,例如:

You could move shared code into another module that has its own content root, say:

/ProjectA/Module3/src

然后将Module3上的模块依赖项添加到Module1和Module2。

and then add a module dependency on Module3 to both Module1 and Module2.

这篇关于在IntelliJ中的模块之间共享Java包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆