Skip to content
Advertisement

IntelliJ IDEA File Templates – Customize directory/package for Multiple Files Template

I’m using IntelliJ IDEA to develop a Java app.

Let’s suppose I have a Multiple File Template that creates a Model Entity, Service and a Controller.

When I use that template, 3 files are created in the same location. Assume that the Entity name is Car, then the files would be:

  • Car
  • CarService
  • CarController

Assuming the following structure…

--+ app
  +-- model
  +-- service
  +-- controller

How can I define the location where each files gets created, so the result would be like:

--+ app
  +--+ model
     +-- Car
  +--+ service
     +-- CarService
  +--+ controller
     +-- CarController

Advertisement

Answer

You can specify folders in the file name of the template. For example your main template can have the file name model/${NAME} and below it you can define two child templates with file names service/${NAME}Service and controller/${NAME}Controller. When the template is used this will create the folders if necessary, or use existing folders if they are already present.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement