First we concentrate on ease of development.
We want to work with frameworks that support an elegant, fast and productive development mode.
Children would break out in tears if you would tell them about past J2EE application servers with 10++ minutes redeployment time just to see the effect of changing a single line of code.
Much has improved since, but there is still room for more. Here we describe several techniques to ease development. We especially describe Civilians class-reloading technique which can supercharge your development cycle.
Then we discuss how Civilian web applications can be tested, introduce the admin application and end with a topic which is at the very beginning of application development: Scaffold new applications.
When using Apache Tomcat (7.0.54+) we take the opposite approach: Instead of deploying the application into Tomcats webapp directory, we instruct Tomcat to pick up the application from our IDE project, using Tomcats VirtualWebappLoader. (In Tomcat 8 configuration seems to have changed).
$tomcat/conf/server.xml add a context entry for your application within the
<Host name="localhost" ...> ... <Context path="/myapp" docBase="c:\proj\myproj\web"> <Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath=" c:\proj\base\bin; c:\proj\base\lib\*.jar; c:\proj\myproj\lib\*.jar; c:\proj\myproj\bin"/> <!-- jars in c:\proj\myproj\web\WEB-IN\lib ate automatically included --> </Context>
Context/@pathis the path of the ServletContext within Tomcat,
Context/@docBaseis the web applications root directory (containing the
Context/Loader/@virtualClasspathinstructs Tomcat where to find your classes and libraries.
If you now start up Tomcat, it will serve your application without a deployment in its
With that you can reload an application by sending its context path to the manager app:
civassets/dev/reload-tomcat.jsin Civilians source how this can be implemented.
Now we can write and save code in our IDE, switch to the browser, click the reload button and immediately see the effect.
Note that this technique will reinitialize your application. If the application needs significant startup time, this will somewhat degrade the reload experience...
When class reloading is turned on, Civilian is using a new classloader for each request to load your controller class and all classes used by the controller. Therefore on the next request you will see code changes immediately since now the new controller version is loaded and used.
To turn class reloading on, you need to add these configuration entries to your
civilian.ini config file:
# turn on development mode
develop = true
# in your app config add this
app.myapp.dev.classreload = true
.includeswitches you can fine-tune what classes are reloadable:
app.myapp.dev.classreload.exclude = org.myapp.web.SessionUser,org.myapp.web.Constants
app.myapp.dev.classreload.include = org.myapp.util.*
Sometimes class reloading may not work as desired. In this case you can set the log level of
trace to analyze if classes are loaded correctly.
civilina.iniconfig, or explicitly add application objects to the TestServer.
The admin app uses Civilians ability to run multiple applications in a Civilian server.
When you start your application in development mode by default the admin app is also started and available under the path
your context path.
The admin app can be configured via
civilian.ini like your own applications.
(It just uses the key prefix
civ.admin instead of
civilian.jardeclares it as Main-class. It prints a detailed help message when run without any arguments. Scaffold expects
java -jar civilian.jar param* directory class-prefix
java -jar civilian.jar /proj/crm Crm
|also generates Eclipse project files|
|use the encoding for the generated files (default is UTF-8)|
|comma separated list of supported locales (without spaces), default is simple
|copy the jar files to the generated
|create a minimal scaffold application|
|use the package as application package, default is "com." + lowercase(class-prefix)|
|generates a snippet
|creates empty resource bundle files for all supported locales|
|print verboses messages during scaffold|