如何在不同的 Eclipse 项目之间共享资源,以避免重复?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3342818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I share resources between the different Eclipse projects, so as to avoid duplication?
提问by user77115
I have 2 android applications that share 95% of their resources, layouts, strings etc. only a few jpg's are different.
我有 2 个 android 应用程序,它们共享 95% 的资源、布局、字符串等。只有少数 jpg 是不同的。
How can I share resources between the different Eclipse Android projects, so as to avoid resource duplication ?
如何在不同的 Eclipse Android 项目之间共享资源,以避免资源重复?
采纳答案by Akash Kava
Eclipse provides 2 ways to do it,
Eclipse 提供了两种方法来做到这一点,
- Create a library project and include this library projects in two application projects
- Create a Shared Source Folder, goto your project properties and in Source tab, you can link a folder which may be in any other project and include all files of those folder as a link, without duplicating them.
- 创建一个库项目并将这个库项目包含在两个应用项目中
- 创建一个共享源文件夹,转到您的项目属性,然后在“源”选项卡中,您可以链接一个文件夹,该文件夹可能位于任何其他项目中,并将这些文件夹的所有文件作为链接包含在内,而无需复制它们。
回答by ericsoco
I was having trouble figuring this out as well, and these answers didn't provide enough info for me to get code shared across projects (I'm running Eclipse Indigo SR2), so here's what I did:
我也无法弄清楚这一点,这些答案没有提供足够的信息让我在项目之间共享代码(我正在运行 Eclipse Indigo SR2),所以这就是我所做的:
Create a Java Project to consume the shared resources, say SharedConsumer
Create a Java Project that contains the shared resources, say SharedResources
Open Project Properties for SharedConsumer
, navigate to Java Build Path, Projects tab
Click Add... and select SharedResources
.
创建一个 Java 项目来使用共享资源,比如SharedConsumer
创建一个包含共享资源的 Java 项目,比如SharedResources
打开项目属性SharedConsumer
,导航到 Java 构建路径,项目选项卡单击添加...并选择SharedResources
。
Resources within SharedResources
are now all accessible to SharedConsumer
as if they were within SharedConsumer
.
里面的资源SharedResources
现在都可以访问了,SharedConsumer
就好像它们在里面一样SharedConsumer
。
回答by Adrian Regan
Put all your common resources into a separate jar and use this in your separate projects.
将所有公共资源放入单独的 jar 中,并在单独的项目中使用它。