按 build.xml 依赖项拆分 Java 项目

发布于 2024-11-07 23:30:43 字数 908 浏览 0 评论 0原文

我正在处理一个 Java 项目,它实际上应该被编码为 2 个独立的项目。因此,我试图找到一种好方法将每个子项目的代码拆分到自己的新项目中。有 2 个构建文件用于构建和打包每个子项目。因此,是否有一种好方法可以检索每个构建文件所需的所有资源和文件的列表,从而分离出我的项目?

编辑:

我找到了与每个构建文件关联的Manifest*.MF 文件,其中指定了Main-ClassClass-Path。从Class-Path,我可以确定每个新项目需要哪些 JAR 文件。这些都是仅运行各自主类的应用程序,因此如果我确定主类的依赖类,我就确定了新项目中需要的类。

以下是我目前的计划:

  1. 将旧项目复制到新项目中
  2. 删除未使用的构建文件、MANIFEST*.MF 文件以及基于清单的未使用的 JAR 基于清单
  3. 删除未使用的主文件
  4. 使用 IntelliJ 的内置功能手动检查文件和方法以检查它们是否在任何地方被引用,如果没有则将其一一删除。

我猜第 4 步可以改进...

更新:

我现在已经完成了项目的分离。我最终使用了 IntelliJ 的“分析依赖关系...”(在 10.0.3 中它位于“分析”菜单下)。对于那些拥有该工具的人来说,默认情况下它仅搜索 1 深度的依赖项,因此请注意这一点并根据需要设置更大的深度。然后,您可以突出显示核心类,它将显示这些类依赖于您指定的深度的所有文件。就我而言,一个子项目的主文件之一引用了另一个子项目的主文件,因此通过删除该依赖项,我能够消除 65 个以上的文件作为依赖项。

上述解决方案对我来说效果很好,但我不喜欢说“你必须购买这个工具才能做你想做的事......”因此,我保持这个问题开放,希望有一个开源解决方案。

I am working with a Java project that really should have been coded as 2 separate projects. Thus, I'm trying to find a good way to split out the code of each sub-project into its own new project. There are 2 build files that build and package each sub-project. Thus, is there a good way that I can retrieve a list of all the resources and files needed for each build file, and thus separate out my projects?

EDIT:

I have found Manifest*.MF files associated with each build file, which specify both the Main-Class and the Class-Path. From the Class-Path, I can determine which JAR files are needed for each new project. These are both applications that only run off their respective main classes, so if I determine the dependent classes of the main class, I determine the classes I need in the new project.

Here is my current plan for this:

  1. Copy the old project into a new project
  2. Remove the unused build files, MANIFEST*.MF files, and unused JARs based on the manifest
  3. Remove the unused Main files based on the manifest
  4. Use IntelliJ's built-in functionality to manually go through files and methods to check if they are referenced anywhere and remove them 1-by-1 if they are not.

I'm guessing step 4 can be improved on...

UPDATE:

I've now completed separating out my projects. I ended up using IntelliJ's "Analyze Dependencies..." (in 10.0.3 it is under the "Analyze" menu). For those of you that have that tool, it only searches dependencies 1 deep by default, so be aware of this and set a greater depth as needed. You can then highlight the core classes and it will show you all the files that those classes depend on to your specified depth. In my case, one of the main files of one sub-project referenced the main file of another sub-project, so by removing that one dependency I was able to eliminate 65+ files as dependencies.

The above solution worked well for me, but I don't like saying "you have to buy this tool to do what you want..." Thus, I'm keeping this question open in the hopes of an open-source solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-11-14 23:30:43
  • 依赖关系:
    您可以创建 2 个项目,两个项目都引用原始项目的所有原始 jar(依赖项)。此时,您指的是两个项目中一些不必要的 jar。然后您可以使用此处建议的工具来检测这些不必要的jar并在每个项目中删除它们。

  • 资源(如 xml 配置文件):
    也许有一些工具,但我不知道。希望您没有那么多配置文件等,如果有的话,手动复制可能是最快的方法。

  • Dependencies:
    You could create 2 projects, both referring all of the original jars (dependencies) of the original project. At this point you are referring to some unnecessary jars in both projects. Then you can use tools suggested here to detect these unnecessary jars and remove these in each project.

  • Resources (like xml config files):
    Maybe there are some tools out there, but I don't know. Hopefully you don't have that many config files etc., and if so manual copy is probably the fastest way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文