简体   繁体   English

如何将我的代码分成两个应用程序?

[英]How do I divide my code into two applications?

I have a few java classes, holding my application's logic.我有几个 java 类,保存我的应用程序的逻辑。 Now I want to create two applications, one will be a SpringBoot web application and another one will be a desktop application.现在我想创建两个应用程序,一个是 SpringBoot web 应用程序,另一个是桌面应用程序。 Both of them will use logic, that I already wrote.他们都将使用我已经写过的逻辑。 I see only one way to do it: compiling logic classes into a .jar file and then putting it as a library into two Idea projects.我只看到一种方法:将逻辑类编译为.jar文件,然后将其作为库放入两个 Idea 项目中。 But if I update any of this code, I will have to recompile it into jar and then replace an old jar with a new one in both projects.但是,如果我更新任何此代码,我将不得不将其重新编译为 jar,然后在两个项目中用新的 jar 替换旧的 jar。

  1. Is there another, more simple way two divide my code into two projects?还有另一种更简单的方法将我的代码分成两个项目吗?
  2. What should I do with Git/GitHub?我应该用 Git/GitHub 做什么?

PS My project is in java, I use Intellij IDEA, GitHub. PS我的项目在java,我使用Intellij IDEA,GitHub。

Multi-module project多模块项目

As commented , you need a multi-module project.评论所述,您需要一个多模块项目。 The content for each module is compiled separately, producing separate JAR files.每个模块的内容单独编译,生成单独的 JAR 文件。

IntelliJ supports multi-module projects. IntelliJ 支持多模块项目。

I recommend using a common Java build management tool to assist.我推荐使用通用的Java构建管理工具来辅助。 Apache Maven is one such tool that supports multiple modules . Apache Maven就是这样一款支持多个模块的工具。


The word “module” used here in this context should not be confused for the Java Platform Module System .此处使用的“模块”一词不应与Java 平台模块系统混淆。 You may or may not choose to use Java modules in your project modules' code.您可以选择也可以不选择在项目模块的代码中使用 Java 模块。

I suggest rest web service interface to export the logic data..我建议rest web服务接口导出逻辑数据..

SpringBoot web application can consume the rest services SpringBoot web 应用程序可以使用 rest 服务
and the other a desktop application can consume the rest services另一个桌面应用程序可以使用 rest 服务

ONE REST SERVICE LAYER
--------------------------------------
 |                 |
Desktop app,     SpringBoot web application

this way to don't duplicate your code and bugs twice.这样就不会重复您的代码和错误两次。

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

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