简体   繁体   English

Java:如何在多个应用程序之间共享通用应用程序/UI代码

[英]Java: How to share common application / UI code among several applications

I have several applications that differ mostly based on resources.我有几个主要基于资源不同的应用程序。 As of now, I'm copying the code around to each application.截至目前,我正在将代码复制到每个应用程序中。 This can be problematic.这可能是有问题的。 An example, fixing a bug in one, and forgetting to update to the others.一个例子,修复一个错误,忘记更新其他的。

I don't think creating a JAR is appropriate for this situation, as these are application specific UI classes, (actually android activity classes in specific) including the actual app start-up code.我认为创建 JAR 不适合这种情况,因为这些是特定于应用程序的 UI 类(实际上是 android 活动类),包括实际的应用程序启动代码。

It may be possible to include these source files into several packages, but then I have the problem that each file specifies a specific package name on the first line.可以将这些源文件包含到几个包中,但是我遇到的问题是每个文件在第一行指定一个特定的 package 名称。

Most of the code is related to the UI and Activity processing.大部分代码与 UI 和 Activity 处理有关。 (The actual common code is already in a library). (实际的通用代码已经在库中)。 A similar question is posted here . 此处发布了一个类似的问题。 Are there any elegant solutions to this situation?这种情况有什么优雅的解决方案吗?

A jar is absolutely appropriate for this situation. jar 绝对适合这种情况。 You should split your application into layers, separating the application-specific classes from the shared code.您应该将应用程序拆分为多个层,将特定于应用程序的类与共享代码分开。

I solved this by going with Android Library projects.我通过使用 Android 库项目解决了这个问题。 (Not sure of the details, perhaps they are ultimately jars) Check out details here , specifically the section 'Setting up a Library Project'. (不确定细节,也许它们最终是罐子) 在这里查看细节,特别是“设置图书馆项目”部分。 I basically put in all my activity classes (except for the start-up one) into the library.我基本上把我所有的活动课(除了启动课)都放进了图书馆。

For true non-UI bound code, JARs, do seem to be the way to go.对于真正的非 UI 绑定代码,JARs,似乎确实是通往 go 的方式。

I agree with artbristol.我同意艺术布里斯托尔。

I also recommend to use Maven and:我还建议使用 Maven 和:

  • release the common jars to a corporate Maven repository将通用 jars 发布到公司 Maven 存储库
  • declare a dependency with specific versions on these jar artifacts在这些 jar 工件上声明具有特定版本的依赖项

Like this you don't break applications if you do some incompatible changes.像这样,如果您进行一些不兼容的更改,您不会破坏应用程序。

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

相关问题 如何在多个Java应用程序之间共享连接池 - How to share connection pool among multiple Java applications 如何在多个活动之间共享公共代码? 拜托,这不是一个重复的问题 - How to share common code among multiple activities? Please, this is not a repeated question Java Servlet:如何在多个Servlet之间共享常见行为? - Java Servlets: How to share common behaviour among multiple servlets? 如何在 Java 中的多个线程之间共享公共日志文件 - How to share common log file among multiple threads in Java 如何在Java Web应用程序之间共享通用组件? - How can I share common components between Java web applications? 如何在多个应用程序之间共享业务逻辑 - How to share business logic among multiple applications 如何在Java中的多个项目之间共享公用文件 - How to share common files between several projects in Java 如何跨 Java 类共享通用代码 - How to share common code across Java classes 当两个不同的检票口应用程序共享通用功能时,我如何重用代码 - How can I reuse code when two different wicket applications share common functionality 如何在高性能Java Web服务应用程序中共享通用数据结构 - how to share a common data structure in high performance java web service applications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM