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:
- Copy the old project into a new project
- Remove the unused build files, MANIFEST*.MF files, and unused JARs based on the manifest
- Remove the unused Main files based on the manifest
- 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.
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.
精彩评论