First we concentrate on ease of development:
We want to work with frameworks that support an elegant, fast and productive development mode.
When J2EE application servers were invented it wasn't unusual that developers waited 10++ minutes
for redeployment to complete in order to see the effect of latest code changes.
Much has improved since, but there is still room for more. Here we describe several techniques to increase development
productivity:
When using Apache Tomcat we can 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).
In $tomcat/conf/server.xml add a context entry for your application within the Host element:
<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>
<Host>Context/@path is the path of the ServletContext within Tomcat, Context/@docBase is the web applications root directory
(containing the WEB-INF folder), Context/Loader/@virtualClasspath instructs Tomcat where to find your classes and libraries.
If you now start up Tomcat, it will serve your application without a deployment in its webapp folder.
manager-script role.
With that you can reload an application by sending its context path to the manager app:
http://localhost/manager/text/reload?path=/myapp
civassets/dev/reload-tomcat.js
in 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
.exclude and .include switches
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 org.civilian.classloader
to trace to analyze if classes are loaded correctly.
civilina.ini config, 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 /civadmin below
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 app.id).
civilian.jar declares 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
-eclipse
| also generates Eclipse project files |
-enc encoding
| use the encoding for the generated files (default is UTF-8) |
-locales list of locales
| comma separated list of supported locales (without spaces), default is simple en |
-libs list of jar files
| copy the jar files to the generated WEB-INF/lib directory |
-min
| create a minimal scaffold application |
-package
| use the package as application package, default is "com." + lowercase(class-prefix) |
-tomcat
| generates a snippet tomcat.server.xml which can be inserted into a Tomcat server.xml
to deploy the application from it project directory.
|
-text
| creates empty resource bundle files for all supported locales |
-v
| print verboses messages during scaffold |