In maven, you can use archetype:create-from-project to generate a project skeleton, but the package name is often a bit problematic.
The create-from-project command will look for a directory path containing all files as the base package.
For example, the following project skeleton:
Java code
src/main/java/
com.company.proid.dao
com.company.proid.service
com.company.proid.web
In this case, using the create-from-project command, the default base package will be com.company.proid
. For example, there is a file called baseDao.java under the com.company.proid.dao package. After the template is generated, the package will be It is
package ${package}; that is to say, all ${package} = com.company.proid. In
the generated template, src/main/java/ is directly under a dao folder, a service folder, a web folder.
This is fine when there is no need to sub-package, but if your project skeleton is like this:
Java code
src/main/java/
com.company.proid.moduels.sys
com.company.proid.moduels.sys.dao
com.company.proid.moduels.sys.service
com.company.proid.moduels.sys.web
That is to say, the model.sys package is a complete functional package that you have already written. If you want to put it in the skeleton, if you use the archetype:create-from-project command directly, the default basic package will become com. company.proid.moduels.sys.
That is, in the template, the modules and sys folders under src/main/java are gone.
The generated template header is as follows:
Java code
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.dao;
There is still a dao folder, a service folder, and a web folder under src/main/java/.
In this case, in fact, the actual project path we may want to generate is as follows:
Java code
src/main/java/
com.company.proid.moduels.user
com.company.proid.moduels.user.dao
com.company.proid.moduels.user.service
com.company.proid.moduels.user.web
com.company.proid.moduels.sys
com.company.proid.moduels.sys.dao
com.company.proid.moduels.sys.service
com.company.proid.moduels.sys.web
Of course, in actual use, it shouldn't matter. It's a big deal to build a package, build modules and sys, and then do it again, but it's not always perfect.
So you need to tell the create-from-project command what the base package of the project is.
Just use the packageName:
archetype:create-from-project -DpackageName=com.company.proid
tells it that we need to keep the moduels and sys folders.
After executing the command like this, the generated template is:
Java code
src/main/java/modules/sys
和dao,service.web文件夹
生成的文件包头如下:
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.modules.sys.dao;