How Can jBilling Help You?
Who’s Using jBilling?

“jBilling has a very solid architecture and an elegant design.”
Jean-François Farjon
Guardian Mobility Corp.
See all testimonials >

DONE - Build: precompilation of JSP files

Current situation:
The JSPs are converted to .java files and then .class files at runtime in an on-demand basis (by the jasper component of Tomcat). This is not ideal for the developers, but the impact on the users and the installation of jbilling is not acceptable, because is requires to have the Java SDK instad of the runting (JRE).

Desired situtation:
Have a ant task in the build that does all the precompilation (JSP -> Java) and compilations (Java -> class). Test in a fresh box that installing jbilling from scratch (plus the additional .class files) does not require the SDK but only the JRE.

Changes to be made in this file:
build.xml

This item is now completed. See the results here

 
bhowe wrote 5 years 38 weeks ago

Update - Package image

Ok, Im missing something simple here.

First, let me say that if i manually copy the .class files to the jbilling\work\jboss.web\localhost\billing folder everything works perfectly.

When i run my packageImage task it deploys three files jbilling\deploy directory. These files are billing.war, jbilling.jar and betty.wsr. The compiled classes are in the billing.war along with the .jsp pages. I start jboss and go to the login page it ignores the class files and attempts to compile.

There might be something in the configuration files. Going to look into this a little further.

Blake

 
bhowe wrote 5 years 37 weeks ago

2 options

There are two options in using packageImage to deploy the generated class files.

Option 1. Have the .class files packaged in WEB-INF/classes folder of billing.war. If we do it this way the servlet mappings have to be added to the web.xml and the war target will have to slightly modified. The mapping are generated by the jspc so that isnt a big deal.

The steps to deploy would be:

A. Run the jspc target that would copy the class files to build\classes
B. Run the build script. This builds your war file with with the classes included.
C. Add the servlet mappings to web.xml. The file generated by jspc could be included in the web.xml.

Option 2. Just plain and simple update packageImage to put the classes in the work directory.

Just wanted to get opinions. I'm inclined just just to update packageImage but both ways have been tested without the jdk.

Blake

econde wrote 5 years 37 weeks ago

I agree with you Blake, I

I agree with you Blake, I think that option two is the best. I will be testing/reviewing this when I get back from my trip.

In any case, good job! This will simplify quite a good deal jbilling installation for the next release.

Emiliano Conde
Lead Developer - jbilling

Emiliano Conde
Lead Developer - jBilling

 
bhowe wrote 5 years 39 weeks ago

Task Update

Hello everyone. Just wanted to give an update on this task. At this point it compiles from .jsp -> .java -> .class. There are still a few minor issues which im going to list.

Here is the target for reference excuse the horrible formating:

<target name="jspc">

<taskdef classname="org.apache.jasper.JspC" name="jasper2">

<classpath refid="compile.classpath"/>
<classpath id="jspc.classpath">

<!-- Classpath for extra jars -->
<fileset dir="..\server\jbilling\deploy\jbossweb tomcat50.sar">
<include name="jsp-api.jar" />
<include name="commons-el.jar" />
<include name="jasper-compiler.jar" />
<include name="jasper-runtime.jar" />
</fileset>

<!-- Directory for taglibs -->
<dirset dir="${source.dir}\build\classes">
</dirset>

</classpath>

</taskdef>

<!-- Copy the view to the build directory -->
<copy todir="${build.dir}\view">
<fileset dir="${source.dir}\view">
<include name="**/*.jsp"/>
</fileset>
</copy>

<!-- Create the temp directories-->
<mkdir dir="${source.dir}\jsp-java"/>
<mkdir dir="${source.dir}\jsp-classes"/>

<!-- Compile the jsp to .java files -->
<jasper2
validateXml="false"
package = "view"
uriroot = "${source.dir}\build\"
outputDir = "${source.dir}\jsp-java"/>

<!-- Compile the intermediate .java files-->
<javac srcdir="${source.dir}\jsp-java\view\" destdir="${source.dir}\jsp-classes" >

<classpath refid="jspc.classpath" />
<classpath refid="compile.classpath" />

</javac>

<!-- Copy the to the compiled classes to the view for deployment-->
<copy todir="${source.dir}\">
<fileset dir="${source.dir}\jsp-classes\view">
<include name="**/*"/>
</fileset>
</copy>

</target>

Issues:

1. The view directory has to be copied to the build directory. The Jasper compiler uses the uriroot option and looks for the \WEB-INF folder for your web.xml and .tld's in that path.

2. When compiling from .jsp -> .java files the jasper compiler gives this warning:

[jasper2] log4j:WARN No appenders could be found for logger (org.apache.jasper
compiler.JspRuntimeContext).
[jasper2] log4j:WARN Please initialize the log4j system properly.

I can get rid of this warning by explictly listing the jars needed instead of using compile.classpath

3. When compiling from .java -> .class files it gives serveral warnings. (100) Here is a snippit you can get the full text by compiling with the -xlint option
C:\jbilling\src\tmp\org\apache\jsp\view\item\editTypeBody_jsp.java:16: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector
[javac] _jspx_dependants.add("/WEB-INF/struts-html.tld");
[javac] ^
[javac] Note: Some input files additionally use unchecked or unsafe operations.
[javac] 100 warnings

Ill look at this since all 100 warnings seem to be the same.

4. The target itself needs to be optimized.

One it should rely on the compile target instead of excuting javac again. Right now its actually compiling the .java files twice.

The other thing is when it is compiling the .java files they should go directly into the view directory instead of compiling to a temp directory then copying them over.

5. Needs to be integrated into the build cleanly.

I believe the easiest way will be to have the .class files in the view directory before the war is packaged.

I'll get to work on these issues tommorow. Let me know if anyone can see anything I didnt consider and need to address.

Blake

 
yangsun wrote 5 years 39 weeks ago

For the third point, I think

For the third point, I think they are complains from jdk 1.5 compiler. You know, in JDK 1.5 (Tiger), Sun introduces many advanced features. One of them is the collection prototype. With this feature, instead of putting all your customed objects into the collection as objects and cast them to your customed type when you get out them, you can just claim your collection like this:
List<MyCustomObject> myList = new LinkedList<MyCustomObject>();
With this kind of definition, you can only put the MyCustomObject type of objects into the list...
It is a great feature java developers expecting. But the drawback is, the jave compiler will complain when it mets the code which does not use that feature.

There are many features in the jdk 1.5, such as autoboxing, annotation...

That's the background of the problem. And I believe the ant task has some switches to switch the compiler level to jdk1.4 or before, or it can suppress this kind of warnings.

Anyway, it is no harm for the compilation.

Regards,
Yang Sun

econde wrote 5 years 39 weeks ago

Hi Blake,

Hi Blake,

First of all, good job, it look like you've got the task pretty much cooked. Keep in mind that the main goal is to provide a better distribution for the end users, so they don't need to have the java SDK installed and don't get the false impresion that jbilling is slow because the first time the hit a jsp page it has to be compiled. This means that you don't need to worry to include the jspc task withing the normal compilation tasks. As a developer, I don't mind much to complie the jsp pages on demand, but I'll mind if the compile task takes longer because it is checking/compiling jsp pages.
So let's focus on the users. The task that you want to integrate with the new jspc task is 'packageImage'. That's the one that get the zip file to be uploaded in sourceforge. To get packageImage working you'll need to update the property 'image.source.dir' to point to whereever you have unpacked the binary version of jbilling.

Actually, the current version of this task takes care of deleting any java/class file generated by jasper. It was done this way to reduce the size of the zip file. You'll have to update this task so there is no deletion.

I'll go over your points:

1) That's fine. We'll run 'packageImage' once every couple of months to make a release, so it's ok if it's slow.
2) You can add the jasper package in the log4j.xml file so it stops complaining about not knowing what to do with it, but really, this warning is not a big deal.
3) Don't know about this one, but I wouldn't be too worry about it.
4) This is addessed by the fact that jspc won't be part of the normal compilation ('compile' target), only part of the packaging of a release ('packageImage' target).

So, the unit test for this task would look like:
- download/install jbilling just like a normal user would
- run ant jspc: this should copy the classes to the jbilling directory
- update your PATH to make sure that if you type 'javac' from the command line, you get an error (just like a user without the JDK would).
- startup JBoss and see how things work. Clicking around should be fast, since there's no need for jsp->java->class compilations.

Last but not least, don't forget to fax the contributor's agrement, see step 5 of the 'How to contribute' guide.

This is good stuff Blake!
Cheers,

Emiliano Conde
Lead Developer - jbilling

Emiliano Conde
Lead Developer - jBilling

 
yangsun wrote 5 years 42 weeks ago

A good reading

Hi,

I just find a good reading(http://codinginparadise.org/weblog/2005/01/tomcat-jsp-precompilation-is-slow.html) on this topic. And I also do a quick search and find that ant's task for jsp compilation is jspc which is an optional task.

Wish it will be some help for developers who like to take this task.

Regards

 
bhowe wrote 5 years 41 weeks ago

Task

ill take this one looks like a good one to become more familar with the build file.

Blake

econde wrote 5 years 40 weeks ago

About tags, you know that we

About tags, you know that we have some custom tags (those that start with 'jbilling' in the jsp pages). The source for these tags are all in subdirectories of 'client' and are named *Tag.java, an example: http://svn.sourceforge.net/viewcvs.cgi/jbilling/trunk/classes/com/sapienter/jbilling/client/user/GetUserTag.java?view=log
As part of the build process, these classes are compiled and the *.class files left in the build directory. You will need this directory in the class path of your new task.

It'll help if you show us an error message or log, do it in the forums so it is easier to learn from past experiences.

Cheers,

Emiliano Conde
Lead Developer - jbilling

Emiliano Conde
Lead Developer - jBilling

 
yangsun wrote 5 years 41 weeks ago

That's good. Welcome to join

That's good. Welcome to join jbilling development!

Emil is really a good lead. Feel free to ask any questions you have!

Regards

Please register or login to post a comment.