[C: SUSE] Visual Studio .NET IDE for SUSE Linux!
We all know and love the Visual Studio .NET® IDE, but did you know
that you can use it to build server applications that run on SUSE
Linux®? Discover how with Visual MainWin® for J2EETM, Developer
Edition (a.k.a Grasshopper) from Mainsoft.
Figure 1:Your ASP.NET application running on Linux.
Take a look at Figure 1. It’s clearly an ASP.NET application, and it’s
clearly running on SUSE Linux. That’s easy, you might think, you can
build an ASP.NET application, run it on Microsoft® Windows® under
Internet Information Services (IIS) and browse to it using a browser
such as Firefox on a Linux client. You’d be right, but look again. In
the screen shot, your ASPX is running on localhost, the Linux box
itself. With Grasshopper, you can do this easily, without changing your
existing .NET code.
Therefore, you can say that Visual Studio .NET + Grasshopper = Visual Studio .NET for SUSE Linux!
Extending your skill sets to Linux
Consider this – many companies have Linux on their radar for some form of inclusion in their strategy, be it on the desktop or in the data center. To build applications for Linux, you would probably have to learn a new skill set such as GTK or Java. For server side or hosted applications, the logical candidate is usually J2EE, due to its cross-platform nature and its well-known security, manageability, performance and scalability characteristics. However, to develop J2EE applications, you need to learn the Java language, Java Servlets, Java Server Pages, JDBC for database connection and even Enterprise Java Beans for distributed applications.
What if, as an alternative, you could broaden the reach of your skills to Linux and other Java-enabled platforms, and as a result, extend yourself (and your resume) in a new and exciting area? What if you could do this without rewriting most of your code, and instead re-use your existing C# code? Not only that, but would you like to contribute to the Mono project – the creation of an open source .NET Framework for Linux? Well you can, and you can do it today, with Grasshopper, a freely available download from Mainsoft.
What you can do with Visual MainWin for J2EE: A brief overview
Starting or converting projects
As you know, when you compile an application in Visual Studio .NET, it generates Microsoft Intermediate Language (MS IL), which executes on the Microsoft Common Language Runtime (CLR). Grasshopper is a plug-in to Visual Studio .NET, which takes this MS IL and converts it into Java bytecode, which executes on a Java Virtual Machine. Grasshopper also includes J2EE implementations of ASP.NET, ADO.NET and the most common .NET namespaces, so the required dependencies are available on your J2EE platform.
You’ll get your first indication that something new is available in Visual Studio .NET when you launch it after installing Grasshopper. This demonstrates how tightly the Visual MainWin tools are integrated within the Visual Studio .NET development environment.
Figure 2. Starting a new project in the Visual Studio .NET environment with Grasshopper installed.
After installing Grasshopper, launch Visual Studio, and then choose File > New to open the New Project dialog.
Notice there are two new Project Type folders here – Visual MainWin C# for J2EE Projects and Visual MainWin for VB for J2EE Projects.
In fact, there are two ways you can develop your J2EE applications for Linux using Grasshopper – either by creating a project directly from here and building it in C# or VB.NET, or by taking your existing .NET Framework based project and generating a J2EE project from the .NET project using the Generate J2EE Project Wizard. You will see a little more on this later.
When you install Grasshopper, you also get a copy of Tomcat, saving you the time and trouble of installing and configuring an application server yourself. You can start or stop Tomcat via the Visual MainWin for J2EE group on the Start menu. Tomcat must be running for you to create any new projects, or to convert your existing .NET Framework based projects to J2EE projects. By default, Tomcat runs on port 8080, which is why the New Project dialog (Figure 2) shows the default root for your Web application or Web service as localhost:8080. If you are not familiar with Tomcat, it is a cut-down J2EE application server that is used for the official reference implementation of the Java Servlet and Java Server Pages technologies.
If you have an existing .NET project that you want to convert to J2EE, it’s easy too. Simply right-click your project in the Solution Explorer and select Generate J2EE Project. Grasshopper creates a new project for you, sets it up for Java, and associates your source files with this project. You can then edit, compile, deploy and debug this code on your J2EE server. You can also choose to have the original project and the converted project in the same solution and then implement a single source strategy, building your source code for both .NET and J2EE from one single Visual Studio .NET instance.
Tomcat is also available for Linux, so the applications you build on Tomcat using Grasshopper will run perfectly happily on Linux too. Tomcat is the only application server that is supported by Grasshopper, so if you want to use WebLogic, WebSphere or JBoss, you can with the Enterprise Edition of Visual MainWin for J2EE. A free 30-day evaluation of Visual MainWin for J2EE, Enterprise Edition, is available for download from here. [http://dev.mainsoft.com/Default.aspx?tabid=196&ENT=1]
To create a deployment Java Web Archive file (WAR), all you have to do is right-click on your project in the Solution Explorer, select Deployment Packager, choose the directory that you want to deploy to, and click OK. Visual MainWin then compiles your code and dependencies into a WAR file. To install the WAR file on your Linux-based Tomcat server, simply browse to the Tomcat Manager Console at http://linuxboxaddress/manager/html and install it from there. Tomcat uploads and deploys the WAR file for you.
Figure 3. Debugging an application running on the Java platform.
One of the challenges you would expect to meet when developing an application of the .NET Framework using Visual Studio .NET tools and deploying to a Java runtime, is debugging. Surely debugging cannot work when you cross compile? Well it does! In fact, it works transparently, so that you still believe you are debugging your application as if it were running on the .NET Framework! Take a look at Figure 3 for an example of this. You can try this yourself: Create a new Web application (using the Visual MainWin C# for J2EE projects folder), add a button to it, and enter some form behind the button event handler as shown. Don’t forget to put a breakpoint in the code. Once done, click Debug > Start or press F5. Your application will be compiled and deployed to Tomcat, and a browser will launch directing you to the ASPX page.
Click the button on the page, and you will be taken back to Visual Studio .NET, which has stopped at the breakpoint, as shown in Figure 3. As you can see, all the tools you are used to for debugging – Watches, the call stack and so on – are still available. You can still step through the code and watch it execute, and if you look at the call stack, you can see which classes are running and where. It is particularly interesting to see how Grasshopper links the .NET Framework and the Java specifications, though it doesn’t affect the execution of your program! In addition, you can track bugs wherever they arise, even in production servers, by connecting from Visual Studio .NET to the server, regardless of its operating system, and debug any problems from your preferred development environment!
Interfacing with existing Java or J2EE assets
Many companies – and yours probably isn’t an exception – have assets already implemented in Java, and you will need to interface with these existing Java assets. You may also need to use a third party add-on within your applications to implement some functionality. A good example of this is reporting, where most companies would use an add-on such as Crystal Reports to do the charting. In the Linux world, these would be implemented in Java, and available as Java Archive (JAR) files for you to include in your application. Native Java developers can use these easily by including them when they compile their code, but what about when you are building from C#?
Using Grasshopper, you are not left out. You can add references to the JAR files, and manipulate them in your code as you see fit. It’s analogous to adding references to third party assemblies. To do this, you simply right-click the References folder in your Solution Explorer, and you’ll see two new options above the existing Add Reference and Add Web Reference options:
Add Java Reference, which allows you to find a JAR file and create a reference to it that you can write code to. Java References are fully integrated with your development environment, so the Object Browser, the Intellisense on the code editor and the compilers all recognize the Java classes and their members in exactly the same way they recognize regular .NET ones. This allows you to code against them with the same level of productivity that you have when using the .NET Framework class libraries.
Add EJB Reference (available in the Enterprise Edition only), which allows you to find an Enterprise Java Bean (EJB) using JNDI lookups. JNDI is a directory service used to locate your EJBs and interface to them. This is not supported on Tomcat, because Tomcat does not support EJBs. If you are using Visual MainWin for J2EE Enterprise Edition to build applications for EJB-enabled servers such as JBoss, WebLogic or WebSphere, you can find your EJBs using their JNDI entry, create references to them and consume them like any other object. If you need to consume EJBs, your J2EE developer who built them can give you this information.
Database access with the System.Data namespace
It is easy to access data through ADO.NET using Grasshopper. This is because Visual MainWin provides an implementation of the System.Data namespace that is built on top of JDBC. You can therefore use the System.Data classes as you have always done without worrying about how JDBC handles it. The System.Data classes have been tested with leading Enterprise databases, including Microsoft SQL Server, Oracle, IBM DB2, Sybase, PostgreSQL and MySQL. The drivers for SQL Server and PostgreSQL are included with the platform, and are automatically installed for you on your application server.
In this article, you took a whirlwind tour of some of the features of the Visual MainWin for J2EE toolkit and what they allow you to do. You have seen how you can use your existing C# or VB.NET skills to build applications in a whole new arena – for SUSE Linux! And you can do all this without learning a new language, a new dependency structure or a new IDE. Imagine taking what you have today, and showing your boss how you ported it to Linux in just a few minutes!