能否从现有JHipster项目重新生成JDL文件并同步手动修改的实体?
Yes, you can regenerate a JDL file from your existing project and sync it with the current entity state, along with updating the .jhipster JSON files. Here's how to do it:
Step 1: Reverse-engineer your entities to JDL
JHipster supports reverse-engineering JPA entity classes or your database schema into a JDL file.
To generate JDL from your existing entity code:
Run the following command, replacing the package path with where your entity classes are located:jhipster jdl reverse --package-name com.yourproject.domainThis creates a
reverse-engineered.jdlfile reflecting your current entity structure.Alternatively, if your database matches your entity code, reverse-engineer directly from the database:
jhipster db reverseEnsure your database connection settings are correctly configured in
application.yml/application.propertiesfirst.
Step 2: Refine the generated JDL
The reverse-engineered JDL may miss JHipster-specific configurations (like relationship types, pagination, DTO settings, or filter options) that were set manually. Review the file and adjust these details to match your project's actual setup.
Step 3: Update .jhipster JSON files
Once your JDL is accurate, import it to sync the .jhipster JSON files (which JHipster uses to track entity state):
jhipster import-jdl reverse-engineered.jdl
This overwrites existing .jhipster files, so back them up before running the command.
Step 4: Verify consistency
After importing the JDL, confirm the generated .jhipster JSON files align with your entity code. You can now use standard JHipster commands (like jhipster entity <EntityName>) to modify entities, keeping your JDL, JSON files, and code in sync moving forward.
Important Notes
- Always back up your project before running these commands to avoid losing manual customizations.
- Reverse engineering won’t capture every custom change (like custom methods, non-standard annotations, or business logic), so retain those manually in your entity classes.
- If your entity code and database are out of sync, align them first before reverse-engineering.
内容的提问来源于stack exchange,提问作者Kevion

