You are browsing the archive for Sebastian.

Developing Tomcat servlets with Oxygene for Java

December 15, 2011 in Elements, Java, Platforms, RemObjects, Tools, Visual Studio

Since Java is strong not only on mobile devices but also on the server, we want to show how easy it is to get started with developing server-based applications with Oxygene for Java. For creating web sites as well as background infrastructure like web services, the Java servlets are the right thing to choose, and those need to be hosted within an application server. One of the most known open source Java application servers is Tomcat from the Apache Foundation. This article is about developing Tomcat servlets with Oxygene for Java.

This is an introduction, so we start from the very beginning. To be able to work with Tomcat, we need to install it. So grab your copy from the official Tomcat web site. In this walkthrough we use Windows to be able to develop and test directly on the same system, but of course the Oxygene for Java .jar files also run on any other platform that runs Java, and our servlet will run everywhere you have a Tomcat set up.

Note: You don’t need to use the official installer, as there are many projects out there that will also set you up with a complete Tomcat environment, like BitNami, but for this article we just go for the simple requirements and install Tomcat from the official installer.

We download the setup package and start it. As a first thing we change the installation type to full. This will install the Tomcat server and additionally the host manager (a web interface to manage the server) and examples, and will also start the Tomcat service when the computer starts to make things easy. On the next page we stick to the default ports but in the lower part we enter a user name and a password for a management user. I’ll go with ‘tomcat’ and ‘tomcat’ for both user name and password in my development environment.

This creates an administration user in all necessary roles to be able to manage our tomcat installation from a web browser. At the end of the installation process the installer will ask you to start the service, and we want to.

Launch a web browser and point it to http://localhost:8080/ (or, if you changed the port information in the installer, to the port you entered there). You should see a web page telling you which version of Tomcat is installed, like this:

For me (on a x64 system) the installer put Tomcat into the directory %ProgramFiles(x86)%\Apache Software Foundation\Tomcat 7.0\, but for Jim (who used BitNami to install his Tomcat) the location was %ProgramFiles%\Apache Software Foundation\Tomcat 7.0\. When you have a x86 system it will be the latter too, so don’t be confused when the path is slighlty different for you. Please locate the folder on your system because we need stuff from there. All following paths in this article will be given relative to this directory.

We are interested in two folders within the ‘Tomcat 7.0’ folder: The first is the /lib directory that should contain a file called ‘servlet-api.jar’. This is the library we need to reference later on when developing against Tomcat.

The second one is the ‘webapps’ folder, where we need to create a new folder hierarchy for our test. We create a directory that names our web application. For this sample we start with ‘Cooper’. In this folder we create a new one called ‘WEB-INF’ and in there a folder called ‘lib’.

So the directory where we want to deploy our test application to is \Tomcat 7.0\webapps\Cooper\WEB-INF\lib.

The following image will show you the locations:
This image shows the paths we need

Note: This is actually a bad thing to do on UAC protected or production systems, because you should avoid writing in the program files directory, but since we don’t want to focus on Tomcat configuration in this post here and concentrate on the actual development with Oxygene for Java, we can live with that for now.

We go back to our browser and start the ‘Manager App’ from the links on the right. We are asked to login with our administration account (tomcat/tomcat) and now we see a ‘Tomcat Web Application Manager’ that should show an application ‘/Cooper’ in the list of applications besides the root application ‘/’ and others like ‘/docs’ and ‘examples’. Just by the way, the latter is a good starting point to see what’s possible with servlets and how to do certain stuff. On the right side there are a few buttons, including one labeled ‘reload’. This is the one we need to hit after every build of our application to have Tomcat reload it.

No we start up the Visual Studio IDE. If your system is UAC protected make sure you fire it up with elevated privileges, because it will require write permissions for the Tomcat folder. Then we create a new project: The template we use is ‘Oxygene for Java’ -> ‘General’ -> ‘Class Library’ to start from scratch.

In the new solution we expand our project and then right-click on references, go ‘Add’ and select the file …\Tomcat 7.0\lib\servlet-api.jar to add this to the referenced libraries. Then we right-click on the project itself and select properties.

We change the Output path of both debug and release configuration to point to the location …\Tomcat 7.0\webapps\Cooper\WEB-INF\lib\ to be able to recompile, reload the app in the manager interface and test without the need to copy around the resulting .jar file to the Tomcat installation after every build.

Now we go to the generated Class1. We add these packages to the uses clause:


These are the Java namespaces we’re going to use in our first application. The namespace javax.servlet.http contains the base class for our servlet, javax.servlet contains the classes we’re using for reading the input (the request sent to Tomcat) and writing to the output (the response we’re building to send back to the client). In javax.servlet.annotations we will find the required annotations (the attributes we know from .NET and Delphi) to configure our servlet.

Then we change the name of the class to something better, like ‘MyFirstServlet’ and, while we’re at it, derive it from javax.servlet.http.HttpServlet. In the next step we need to tell Tomcat that this class will be our Servlet and where it should configure it. We can do this declaratively using an attribute (or annotation).

This is what we need to put on top of our class:

[WebServlet(name := "MyFirstServlet", urlPatterns := ["/"])]

With this we tell the servlet what its name is (MyFirstServlet) and that it should listen on the root URL of our web application (which we put in the folder Cooper, so the URL will be http://localhost:8080/Cooper/). And now it is time to tell our servlet what it should do, so let’s go in the real code.

For this we override a method on the base class called doGet. This method will be called from the Tomcat infrastructure whenever an HTTP GET request is received and matches a URL that should be handled from our servlet. For POST requests there is another method called doPost from which we can then access the POST data of the request, but we will stick to the doGet for now. The declaration of this public method and the implementation are quite easy for the very first test:

// declaration in our class:
method doGet(req: HttpServletRequest; resp: HttpServletResponse); override;
// implementation
method MyFirstServlet.doGet(req: HttpServletRequest; resp: HttpServletResponse);
  resp.getWriter().println('Hello World');

The method will be called from Tomcat whenever there is an HTTP GET request to handle, and it gives the request and a prepared response object to the method on which we do our work. In this case we simply take the response object, get the writer from it (to write directly to the stream that goes back to the browser) and print the string ‘Hello World’ to it. We compile that class library and check that a .jar file is written into our Tomcat Cooper/WEB-INF/lib folder.

We go to the management page, and in the line for our Cooper application we click on reload. No we are ready to test our application. We point a browser to http://localhost:8080/Cooper and should see ‘Hello World’.

Now, answering a request with static content like this is not hard, and we could have achieved this by simply delivering a normal .html file. Now it is time for us to do something with input, so we react on parameters that are passed to our servlet in the URL. For reference I will include the full source of this sample:

namespace TomcatServlet;
  [WebServlet(name := "MyFirstServlet", urlPatterns := ["/"]]
  MyFirstServlet = public class (HttpServlet)
    method doGet(req: HttpServletRequest; resp: HttpServletResponse); override;
method MyFirstServlet.doGet(req: HttpServletRequest; resp: HttpServletResponse);
  var output: PrintWriter := resp.getWriter();
  var value := if req.ParameterMap.containsKey('test')
    then req.ParameterMap['test'][0]
    else 'No value';
    <H1>Hello Java!</H1>
    <p>This is a Oxygene for Java Tomcat Servlet</p>
    <p>" + value + "</p>

This will display the value of the parameter ‘test’ when we call it with this URL http://localhost:8080/cooper/?test=hi, just like this:

I hope this article will give you a starting point for servlet development with Oxygene for Java.

Of course you can (and should) use any Java libraries and frameworks you like in addition to the servlet API, for example the Java Spring MVC framework or the Hibernate ORM tooling, that will make creation of web applications based on Tomcat (or JBoss as an alternative application server) easier and faster.

2 days of Delphi Prism training in Mainz, Germany

March 5, 2011 in .NET, Elements, Events, iOS, Mac, MonoDevelop, MonoTouch, Oxygene, Platforms, RemObjects, Tools, Visual Studio, Windows

Delphi Code Camp logo RemObjects will be presenting at the next german Delphi Code Camp. As every year, the Entwickler-Akademie hosts the event. This time it will take place from May 2nd to 5th in Mainz, Germany. Each day presents a full-day power-workshop, and on two of them I will give hands-on experience on Delphi Prism. One full day will be a general introduction in .NET and development with Windows Forms, the next day we will concentrate on Mac- and iOS development.

The agenda in short:
Monday, May the 2nd: Daniel Wischnewski on patterns and practices with Delphi.
Tuesday, May the 3rd: Bernd Ua on Multithreading with Delphi.
Wednesday, May the 4th: Sebastian on Windows Forms development with Delphi Prism.
Thursday, May the 5th: Sebastian on Mac- and iOS development with Delphi Prism.

Hope to see you in Mainz.

Short summary in german:
Vom 02. bis 05. Mai 2011 findet in Intercity-Hotel Mainz das diesjährige Delphi Code Camp mit Daniel Wischnewski (Mo.: Patterns), Bernd Ua (Di.: Multithreading) und meiner Wenigkeit (Mi.: Delphi Prism: Windows Forms und Do.: Mac- sowie iOS-Entwicklung) statt.

EKON 14 Recap

September 29, 2010 in Delphi, Mono, MonoDevelop, Oxygene

Right now I’m on my way back home from the Entwickler-Konferenz (EKON) 14 in Darmstadt, Germany. Jim is still there, but I have other duties so I left a day before the conference ends officially.

I had two sessions, the first yesterday was about Delphi Prism language specialties where I talked about cool features like class contracts and also interface delegation. Today I talked about multi platform development with Delphi Prism, concentrating on the apple platforms, both the Mac and iOS using Mono and MonoTouch for the iPhone/iPad.

I also sneaked into other sessions. There was a ‘how do I hack VCL programs’ session that really showed some interesting debugging, dumping and assembler-modification to crack a dongle protected native Delphi application as well as Holger Klemt talking about his personal experience with guys cracking is IBExpert software and what he did against that. Also Ray Konopka had a very interesting session about the Ribbon UI in general.

I especially enjoyed Max Kleiners talk about our PascalScript. Until today I didn’t knew he had built sort of a little IDE for it, called maxBox. It’s a scripting toolbox with a *lot* of scripatble functionality. He showed (beside other things) how to download a (free) mp3 file from the internet and directly played it from a little script – it was awesome (the demo, that is. Not the music, actually ;) ). maxBox, just like PascalScript that powers the IDE, is open source and you can get the sources from sourceforge. You can find more information about it here: . So go and check it out, it also brings script debugging and syntax highlighting with it and really is a good start for a little scripting with pascal script. At this point I really like to say thanks to Max. Doing that for the purpose of teaching programming and open sourcing the tool is a nice gesture.

Next speaking opportunity for me is at the Embarcadero CodeRage 5 online conference where I have two sessions on Thursday next week. One is about LINQ with Delphi Prism and the other about Hydra, so join me there if you like to. It’s totally online, so no shoes? No shirt? No problem! ;)

Delphi Prism on the iPhone

September 9, 2010 in .NET, Elements, iOS, Mono, MonoDevelop, MonoTouch, Oxygene, short, Tools

If you wanted to develop iOS applications with Delphi Prism (or Monotouch in general), there was this potential licencing problem, as long as you wanted to sell your app through the Apple AppStore (i.e. not using Enterprise deployment).

Here’s the good News: This is now history!
Today Apple announced to “relax all restrictions on the development tools used to create iOS apps, as long as the resulting apps do not download any code”.

This is a big relief for all those that wanted to write mono-based Applications for iOS but didn’t want to take risk that Apple’s going to decline the App for that reason. Additionally, Apple is going to publish their review guidelines, so that you know what’s allowed and what isn’t in detail before writing your software.

So, now you’re officially allowed to have fun and earn money with Delphi Prism on iOS. Enjoy it :)

Singing *My bags are packed… i’m ready to go…*

August 10, 2010 in Elements, Hydra, Music, non-tech, RemObjects, short

The title lines are from “Leaving on a Jet Plane”, originally by John Denver. The cover version by Aerosmith Chantal Kreviazuk got famous through the (awesome) Armageddon movie score. That awseome is for the soundtrack, not necessarily the movie *g*

In fact my bags are not yet packed, but I’m going to do so soon. Right now I’m still preparing the last things for the Delphi Live! conference which takes place from August 23 – 26th in San Jose, CA.

RemObjects will be represented at Delphi Live by Marc, Jim and myself. So if you have any questions look out for the guy with the hat, the unmistakable voice of Jim or, well, the Obelix look-alike (me :).

Jim is going to show you some Silverlight stuff with Delphi Prism and how to program Unreal Tournament bots, while my sessions cover the Oxygene language in Delphi Prism and it’s nice features that go [far?] beyond what C# is capable of as well as Hydra.

I’m really looking forward to see you in California in about two weeks and I’m happy to be able to meet up with you again. See you at Delphi Live!

Join us at Data Rage 2

May 15, 2010 in .NET, Cocoa, Delphi, Mac, Relativity, RemObjects, Tools, Visual Studio, Windows, Xcode

RemObjects will present Data Abstract in a vendor showcase session at the Embarcadero DataRage 2 online conference, that will take place May 25-27, 2010.

Currently our session “n-Tier in a Box: Data Abstract in Action” is scheduled on Thursday, May 27th from 06:00 to 06:45 PDT.

In this session you will see how easy it is to create a Data Abstract server in Delphi, access that from a Delphi Client and we additionally show you how to create a Relativity-hosted DA server, access this via REST from a browser and at the same time from a native Mac application written with DA/OS X.

I like to invite you to the online conference and I’m excited to see (well, rather read or hear ;-) ) you at Data Rage 2.

Delphi Prism in MonoDevelop at a glance

March 29, 2010 in .NET, Elements, Linux, Mac, Mono, MonoDevelop, Oxygene, Platforms, RemObjects, Tools, Windows

Our beta users (marc already did mention you can apply for the Prism beta here, didn’t he?) are already playing around with this for some time now, and we are going to ship it with the upcoming release: the Delphi Prism MonoDevelop integration. Marc already mentioned this some time ago and a lot has happened since then. This article should give you a ‘what is it and how could I start?’ introduction into Delphi Prism in MonoDevelop.

MonoDevelop LogoMonoDevelop is a free and open source .NET IDE. and has its roots in the also free and open-source SharpDevelop .NET IDE. With SharpDevelop still being a Windows-only IDE using Windows Forms, MonoDevelop (or in short MD, as we call it internally) was ported to Gtk# and massively extended in regards to cross-platform compatibility. It is now able to work smoothly on Linux, Mac OS X and, of course, Windows. You can use your solutions from Visual Studio with MD and vice versa, so you are able to have a single source solution for different platforms.

With the Delphi Prism MonoDevelop integration we target mainly the Mac and then Windows. For Windows we have the Visual Studio integration and we ship the Visual Studio Shell which is, in fact and to be honest, a far more comfortable and powerful IDE. That said: Of course we want to make sure that MonoDevelop on Windows (MD/Win) also works like a charm, but MD/Mac is of a higher priority because you don’t have an alternative IDE there.

The MD/Mac flavor of our MonoDevelop integration comes in form of a complete Mac application. It looks like it’s the original MonoDevelop, but additionally contains our Delphi Prism plug-in. That means you will have to install the MonoDevelop prerequisite by yourself (which is Mono >= 2.4). You can grab it here.

After startup, the Delphi Prism will tell you that it is not licensed and ask you to register your license (if you don’t have a Delphi Prism license yet you can get your copy and a 30-day trial key from the Delphi Prism download page).

When selecting “Start a new Solution” you have several options: The first one is a Console application, but you also have the choice to work with ASP.NET projects, create iPhone or iPod touch applications (be sure to have the iPhone SDK and at least the Trial of MonoTouch ( installed for this) and you can build Moonlight applications (the Mono alternative to Silverlight).

For this article we’re going for an iPhone application. Not because we want you to go and buy you into the iPhone Developer Program and additionally buy MonoTouch from Novell, but just because it’s a neat thing to show ;)

In this dialog you see the options I set for the Hello world iPhone application. Be sure to meet the requirements (MD prereqs, iPhone SDK and MonoTouch) if you want to follow this article in code yourself. The next thing you’ll see is the MD editor with the project opened and ready to start.

We’re not going too deep into the MVC approach of the iPhone development, which is also the key to general Cocoa development, but you need to know that the UI is separated from your code. Unlike in Delphi or Windows forms where controls dropped on the form are automatically properties of your form class, you need to define which controls and events (called Actions) are visible to your code using defined classes.

The first thing we’re creating is the GUI. No demo without a ‘Hello World’, so we simply want to display the text entered in a text box on a label when the user presses a button. In the ‘Solution’ part of the MonoDevelop IDE to your left we expand the project and double-click on the ‘MainWindow.xib’ file. This should launch a program called ‘Interface Builder’ which belongs to the iPhone SDK. The .xib file is somewhat compareable to .dfm files you know from Delphi or like .Designer.pas files which define the layout of a Windows Forms form. The following part of designing the GUI and connecting the outlets and signals is in fact the most difficult if you never worked with interface builder. Because of that I also created a short video of this walk-through so that you have the chance to actually see what I’m going to describe now.


On the ‘Library’ window you select the ‘Objects’ part on top and use the search box on the bottom to search for a ‘Toolbar’. Take it and drop it on the window and let it dock on the top. Then do the same for a ‘Text Field’ and a ‘Label’. You can drag them to the width that pleases you. Now that all controls are in place it’s time to make them accessible. In the ‘Library’ Windows please select ‘Classes’ on top and type ‘App’ in the search box. Then you can select the ‘AppDelegate’ class which is the interface between our application code and the GUI. Still in the library window select ‘Outlets’ in the lower half. We’re going to define accessors to the text field and the label now by clicking on the ‘+’ below the listed outlets and enter text and repeat that for label. Now we’re going to make our click event accessible by selecting ‘Actions’ instead of outlets and add the action ‘onClick:’ (mind the colon!) to the AppDelegate class.

The next task is to connect our outlets and the action to the controls. To do this, you simply select the toolbar button (labeled ‘Item’) in the window. In the property window you select the connections (white arrow on blue circle). There is an area called ‘Sent actions’ with an entry for ‘Selector’. Use the mouse and click in the circle to the right and drag this on the yellow ‘App Delegate’ box in the ‘MainWindow.xib’ window. On dropping you are able to select the action you want to link with the sent ‘selector’ action of the item. For both the text field and the label drag the ‘New referencing outlet’ circle on the App delegate and link them to the text and label outlets we defined before. Now you can press Apple+S to save the MainWindow.xib file.

MonoDevelop generates the code behind for us automatically. Please open the ‘MainWindow.xib.designer.pas’ file (expand the ‘MainWindow.xib’ node in your solution to find it) to have a loot at the generated code. Locate the

method onClick(sender: MonoTouch.UIKit.UIBarButtonItem); partial; empty;

line and copy it (withouth the empty;). Pase that in the ‘private’ section of the ‘AppDelegate’ class in the Program.pas file and double check that the empty; part did not get pasted too. This is the method that get’s called when the event (sorry, Signal ;-) ) fires from the GUI. In the implementation part complete the partial method and fill in it’s body:

method AppDelegate.onClick(sender: UIBarButtonItem);
  label.Text := textbox.Text;

In fact that’s all. Compile the project using the building blocks icon in the toolbar of MD (or by pressing Apple-B). Your code will be compiled into an assembly and the assemblies then will automatically be compiled in to native code for the iPhone by the MonoTouch compiler. When clicking on ‘Run’ or ‘Debug’ the iPhone simulator application should pop up and run our Hello world application:


As you can see building an application for the iPhone using Delphi Prism is not only working, but you can make use of the full Cocoa API the iPhone SDK is offering you. Of course this only works if you have the iPhone SDK and MonoTouch, but to develop for the simulator as we just did, the free version of both is enough. You would only need to pay for the Apple developer program membership and for the MonoTouch licence if you’re going to deploy your programs on a physical device. In other words: Unless you want to start selling your application and earn money in return, you can work for free.

Here you can watch a little video that shows how the application was build:

Download this Video: as mp4 or in open ogg format.

This was a first feature preview of Delphi Prism in MonoDevelop and we hope you like it and stay tuned for more.


Hi, my name is…

January 16, 2010 in non-tech, Personal

Sebastian, and I am the freshman at RemObjects. So please allow me a few lines to introduce myself.

Image of Sebastian P.R. Gingter

I am a 30 years young software developer from germany (and you don’t know how glad I am to publish this post today and not tomorrow ;-). I got my first computer when I was eight years old and started programming in Basic when I was twelve. At the age of 14 I sold my first commercial application (written in GW-Basic) to a doctor and later in school I learned Delphi (it was version 2 then). After a short hanky-panky with Borland C++ back in the summer of ’96 I returned to Delphi and stayed there for some years until .NET came up. Since then I program desktop apps mostly with Delphi and web applications exclusively with .NET. My secret passion is everything that has to do with SciFi: I love cool series like Star Trek, Sliders, Stargate or Babylon 5 and, if I find some time for gaming, play EVE online.

Some of you (especially when you’re from Germany too) may already know me from my volunteering work as a moderator at the Delphi community Delphi-PRAXiS as well as the Delphi-Tage community events (the german Delphi-days). Maybe you have seen and heard some of my sessions at previous Basta! Spring and EKON conferences or you possibly could have read one of my articles in some magazine.

Before joining RemObjects I worked as a freelancer and helped my customers design and develop professional, reliable Delphi and .NET applications. Besides that I always liked to share my knowledge, so I wrote some articles for magazines and went to conferences to speak about all the cool the technology stuff I learned and worked as a trainer for Delphi and Delphi Prism. Learning new things is cool, and talking about cool new stuff even more so. ;-)

Since I had my first contact with the predecessor of Oxygene respectively Delphi Prism, I was impressed how the guys here at RemObjects are getting those things done so well. Now I can see and live that in our day to day work and I must say I’m even more impressed right now. My business here at RemObjects will be mainly boosting the developer relations and do some evangelism stuff. Actually, that means I want to
a) talk to you
b) even more important listen to you, and
c) care about your possible itches & whishes.

That is, of course, besides d) a little bit coding with our products, playing around, creating samples, showing off some cool new technology and telling you what I love about the work that is done here in the secret labs at RemObjects

If you have any questions, remarks, whishes, itches or just want to say hello – please feel free to email me here at RemObjects dot com, putting sebastiang right in front of the (at).

Yours Sincerly,

Sebastian P.R. Gingter