WelcomeHTML welcome = (WelcomeHTML)comms.xmlcFactory.create(WelcomeHTML.class);
Server.LogToFile = EMERGENCY, ALERT, CRITICAL, ERROR, XMLC
Enhydra applications typically deploy as a single Java Archive File with all of the necessary classes. However, updating a jar file at runtime with new classes does not make sense, so the application's classes must be in a regular directory structure. The root directory is defined in with the directive Server.ClassPath = ./lib/classes in the app.conf file. The he HTML files must be in the same directories as the corresponding compiled java classes. The good news is that this is all handled for you by setting the option XMLC_AUTO_COMP=YES in config.mk . After compiling look for the directory app/output/lib/classes to make sure the XMLC_AUTO_COMP option generated the classes directory under output/lib.
WelcomeHTML welcome = new WelcomeHTML();or
WelcomeHTML welcome = (WelcomeHTML)comms.xmlcFactory.create(WelcomeHTML.class);However with autorecompilation, you must instantiate a page with the create method of xmlcFactory. The factory does the work of checking the timestamps on the files and recompiling an HTML page if it has changed. Note that the factory must work with interfaces not directly on Java classes. Taking the example above, Welcome.html must be compiled with an option so WelcomeHTML.class is an interface not a class. So Welcome.html has an interface WelcomeHTML.class, and an implementation of that interface in WelcomeHTMLImpl.class. The options to generate interfaces are described below. On a final note, it's a better programming practice to always use xmlcFactory to instantiate pages. By default, it simply does a new on the page, and using it gives you the option of turning on recompilation or other factory features at a later date.
Consider the following :
The options you specify in config.mk and app.conf reflect these two possibilities. To only reload classes invoke XMLC with the -generate both option. This generates both an interface and an implementation class. To reload from classes and HTML use the XMLC option -for-recomp. This option tells XMLC to generate an interface, an implmentation class, and an *.xmlc file. The *.xmlc file includes the options used to compile the page so the same options are called when it is dynamically recompiled.
There are also options set in app.conf to turn on reloading and recompilation at runtime. Specifiy Server.AutoReload = true to enable class reloading and Server.XMLC.AutoRecompilation = true to enable both class and page reloading.
Note that the autorecompilation capability comes at the cost of checking the timestamp on either the class file or the class and HTML files each time the page is instantiated at runtime.
By default, the application creates a new WelcomeHTML object using the xmlcFactory class. The option XMLC_HTML_OPTS += -generate both is set in the file config.mk. To use the old-style new operator, comment out the XMLC_HTML_OPTS line in testApp.conf and replace the xmlcFactory code with the new code in Welcome.java. Verify it works and run make clean.
To implement page recompilation, you may want to see the classes XMLC is using. Run xmlc on the command line with the -for-recomp option on Welcome.html with the following command:
xmlc -keep -class WelcomeHTML -for-recomp Welcome.htmlYou will see the following generated files:
To run the example do the following: