Develop la J2EE by using .NET with the SnippetStore Project (Chapter I)
by Julien Brunet (

Chapter 1/3
Printed : 7 pages
Version 1.2-RAW

[WARNING] This is a fast rewrite of the rough Translation from the Google service. Please apologize the numerous mistakes, someone is actually reviewing this automated translation.


" The .NET Framework ? A rip off of J2EE! " How much time did you read or heard this sentence? It was the basic reaction of the Java specialists discovering the .NET platform for the first time. Well, everyone agrees on the fact that the .NET Framework has been largely inspired by the J2EE experience, by improving it and by simplifying it.

Thus, are you able to say exactly what the two platforms share in common ? This is what i propose to you to discover today, through a ludic and enthralling experiment: To make turn the code of origin Java PetStore, with the minimum of changes, on a .NET platform. Impossible ? ...are you sure ?


A new PetStore ?

Not exactly. Last year, .NET developers have read on the French DotNetGuru website the Yoopi.NET [1] project, which precisely consisted in treating servlets on a .NET basis, by using J#, the Microsoft "Java-like" language. It showed that it was completely possible to implement the J2EE specification on a .NET platform, with the proviso of rewriting the adequate container.

At this time the choice made by the DNG team was to convert an existing Java runtime: After a courageous test of conversion of Tomcat under .NET, they finally retained "shttp", an OpenSource java micro-kernel, to be compiled by J#. The experiment was painful, but finished on a success!

In order not to endure the same martyrdom, we propose this time to you a different approach: To re-use to the maximum the technologies of the .NET framework to emulate the different J2EE APIs, i.e. to implement the majority of the J2EE interfaces by excessively using the corresponding classes provided by the framework.

Thus, this project is not a "New PetStore" at all. It is not intended to be compared with another version (performance, architecture), because its only purpose is academic (and fun, incidentally)


How to read this article ?

This article is primarily technical. There will be sweat and camboui. We'll not debate on the great subjects of design patterns, refactoring, aspect programming and other cerebral-expensive theories of this world.

This article has four axes of reading:

Lab 0.

- The lab instructions are described this way. You'll have to enter the following line yourself.

C:\SnippetStore> command args

The J# remarks are
preceded by this pictogram.


Let's say to conclude that although this project has been fully developed under VisualStudio NET, building and testing it yourself will require only free tools: The .NET Framework v1.1, the J2SE/J2EE SDKs, MSDE, NAnt, Jad and ASP.NET Web Matrix. The project is under OpenSource license, but the binary are not provided for legal reasons (some sources being decompiled from Java). To run it you will have to assemble yourself the whole thing by following the instructions of the labs which start in chapter 2.

Hope you'll enjoy this reading!


The SnippetStore at a glance


General architecture

The SnippetStore framework is made of three parts :


About the J2EE architecture

A little review of the J2EE architecture for beginners.

PS: May the experts forgive me, i hope to be a good popularizer rather than a specialist :-)


Here is the general architecture schema of the J2EE APIs, as depicted in the Java PetStore blueprint. J2EE is made on numerous things, which contribute to his great reputation of a complete platform. Be quiet, we are not going to implement the whole specification, it would be a titan job ! We will focus on the following layers, used by Java Pet Store.

For information, the following layers are not implemented, or with very little support, because they are not involved in the Java PetStore application:


The SnippetStore architecture

For those who are .NET beginners, here is the translation of the concepts seen above.

To implement the various layers of J2EE, we'll use the following APIs of the framework:


The SnippetStore convert process

When you intend to deploy a J2EE application, copying files is not enough - Packaging and deployment are important parts of the J2EE specification.

With J2EE, most of the software elements are described using normalized XML manifests. EJBs, web applications and taglibs are such kind of elements, and Java PetStore use this convention.

When deploying a J2EE application, those manifests are parsed, and Java code is dynamically generated and compiled by the J2EE container. This dynamic code contains for instance RMI stubs/skeletons, or handling of the transactional functions of the EJBs...It's one of the first AOP processors, indeed!


The SnippetStore framework behaves exactly the same : XML manifests are "scanned" by the toolkit in order to automatically produce the adapted .NET wrappers (CodeDom fans, it's for you!), and the Web configuration is also modified (Web.Config)

Thus, the SnippetStore convert process is really simple, because it's automated, wether you have 10 or 300 EJBs, Servlets and TagLibs.

The JSP pages must also undergo final improvements to run using J # on ASP.NET. It is the role of another tool of the toolkit which we will see in chapter 2.

Note: The EJBs, TagLibs and Servlets wrappers are generated using C #, which is not a problem at all because the .NET platform is language-agnostic. The choice of C # will be justified in chapter 2.

In a previous version, the conversion process was made directly at run time (the same way that pages ASPx or JSP are dynamically compiled). Alas, this choice was abandoned since the migration is not 100% automatizable and that manual adjustments must be made to the original code. On the other hand, it is not inenvisageable with the future improvements of J# to design an automatic deploymeny tool (like the deploytool of Sun). Call to candidature...


Tools of implementation

For information, SnippetStore development started using a 1.0 framework.

If you do not know Ant/NAnt yet, I warmly recommend to you to study this relatively simple tool.



I now propose to you to build the SnippetStore framework by reading the chapter 2. It is a required step for you to be able to run the Java PetStore application under .NET in chapter 3.

Author : Julien Brunet

Copyright June 2003


SnippetStore official website :

[1] French Yoopi.NET project -

Download the sources and binaries

SnippetStore (Sources) : Snippetstore (zip File)

Lesser-GPL Licence

All files are provided under Lesser-GPL license.