Search code examples
javaspring-roo

How to add fields to entities in the roo-shell?


I'd like to add fields to an already created entity in the roo-shell but I don't know which command puts an entity in the current context.

Which one does that?


Solution

  • You have to "focus" that class first to add or change fields on it

    roo> focus --class ~.LaserCannon
    ~.LaserCannon roo> field number --fieldName strength --type double
    Updated SRC_MAIN_JAVA/com/stackoverflow/LaserCannon.java
    Updated SRC_MAIN_JAVA/com/stackoverflow/LaserCannon_Roo_JavaBean.aj
    Updated SRC_MAIN_JAVA/com/stackoverflow/LaserCannon_Roo_ToString.aj
    

    Which added field "strength" to my class com.stackoverflow.LaserCannon (~ is evaluated by roo to your project's top-level-package)