|
If you’re not yet ready to start installing, administering and configuring a full-blown
Linux® distro there’s a new alternative called Linux Inside Windows
(LIW), and it's available for download
from the Grasshopper Web site. LIW will allow you to check out how your
Grasshopper applications can run on Linux, while still using your Windows®
system.
|
|
 |
|
|
Figure 1. Running Linux Inside Windows.
|
LIW is an application based on the QEMU project, which is an open source processor emulator
that can be used to run a virtual Linux machine. LIW has taken the QEMU project
and added a Debian GNU/Linux system
to it, along with Tomcat and PostgreSQL. LIW can happily run applications that you
build using Grasshopper. This article describes how to download and install LIW,
and then build and run your first J2EE™ application on Linux Inside Windows!
Step 1. Download, install and run
The installer is available here.
The single installation executable is about 100 MB in size. Once downloaded, you
can run it and accept all the default settings of the setup wizard. The wizard installs
LIW and adds additional icons to the Visual MainWin® program group on
your Start menu. These icons are used to start up LIW, and to browse to the Tomcat
Manager within your LIW distribution.
After installing LIW, go ahead and start it up. A window similar to that shown in
Figure 1 will open.
|
|
 |
|
 |
|
|
Figure 2. Accessing the Tomcat Manager on the embedded Linux.
|
|
Figure 3. Using the embedded PostgreSQL in Linux Inside Windows
|
LIW also does the clever trick of doing a network address translation between the
host machine and the virtual machine. This means that it forwards everything that
is requested on port 8090 on the host computer to port 8080 on the virtual machine.
Therefore, if you want to access Tomcat, you can do this by calling the host machine’s
IP address on port 8090, and you will in fact access the virtual machine. You can
see this in action in Figure 2. Note that the address localhost is used to
access the server, even though it's running on a separate, virtual machine.
LIW also comes preconfigured with PostgreSQL. Attaching to PostgreSQL and using
it is very straightforward. Using a tool such as pgAdmin III (Figure 3), you can
configure and administer your database. pgAdmin III is installed as part of the
Windows PostgreSQL installaiton. To launch pgAdmin III, click Start > PostgreSQL
8.0 > pgAdmin III. Simply use port 55432 to connect to the embedded one.
PostgreSQL is preconfigured with the username postgres and the password
postgres.
Step 2. Create an application to run on Linux Inside Windows
Creating an application is very simple. First, make sure that Tomcat is running.
Launch Microsoft Visual Studio .NET® and create a new Visual MainWin
C# Web application, and make sure that its location is set to localhost:8080.
This creates a new Web application for you, with the familiar settings and default
blank Web form called WebForm1.aspx.
|
|
 |
|
|
Figure 4. Running a simple Web form application on your local Tomcat.
|
The sample shown in Figure 4 contains a simple Web form that handles temperature
conversion between Fahrenheit and Centigrade. You can use this sample (download
here), or build any
simple Web form before going to the next step.
If you want to learn more about creating applications with the Visual Studio .NET
IDE to run on Linux, check out the 10 minute guide.
Step 3. Deploy your application on Linux Inside Windows
To deploy the application on LIW, you first need to create a Java™ Web Archive (WAR)
file.
This is basically a ZIP file containing all the runtime files and dependencies,
which are structured in a way that Tomcat understands. Grasshopper automatically
creates the WAR file for you.
|
|
 |
|
 |
|
|
Figure 5. Running the Deployment Packager.
|
|
Figure 6. Using the Tomcat Application Manager to deploy the WAR
|
All you have to do is right-click the project in the
Visual Studio .NET Solution Explorer and select Deployment Packager (see
Figure 5).
The Deployment Packager wizard opens. For now, simply accept all the defaults, but
remember the location of the WAR file, because you will need it in the next step.
Step 4. Run your application on Linux Inside Windows
Earlier on, you looked at the Tomcat Application Manager that was running on your
LIW installation. Launch it again, either by using the http://localhost:8090/manager/html
URL, or the icon on the LIW folder on your Start menu.
Scroll down to find the entry WAR File To Deploy, where you can select the
WAR file by clicking the Browse… button. This is shown in Figure 6.
Select the WAR file that you created in the previous step, then click Deploy.
If the WAR deployment succeeds, the Web page refreshes with a message similar to
the following:
OK Deployed application path at context /LIW
In this case, the project and WAR files are called LIW, so the context path is set
to LIW.
You can now run the application, by calling the appropriate URL. You will see your
ASP.NET application running on Linux Inside Windows! Figure 7 shows a running application.
Note that it is running on port 8090.
|
|
 |
|
|
Figure 7. The application running on Linux Inside Windows
|
Conclusion
Linux Inside Windows gives you a very useful option if you want to start getting
your feet wet developing ASP.NET applications for Linux without getting into all
the details of setting up and administering a full-blown Linux box. In this article,
you saw how to set up and configure an LIW virtual machine, and then how to develop
and deploy your first application to LIW. This should give you a good indication
of how simple it is using Grasshopper to develop and deploy ASP.NET applications
to Linux.
|