wiki:Tutorials/DevelopingAndDeployingAnApplication

Version 10 (modified by patrik.svestka@…, 8 years ago) ( diff )

--

Developing and deploying an Application

...using Smalltalk/X jv-branch

This tutorial shows am (almost) complete development cycle for a hypothetical application helloworld_0. not the coolest name, I know. You should choose better for your app!

Step 1: Preparing Development Environment

First you need to make sure you're able to compile Smalltalk/X jv-branch as such. To do so, follow instructions described in section Building Smalltalk/X jv-branch. Especially make sure you have installed a C compiler toolchain and version control tools as they'll be needed.

Through this tutorial, let's assume all the files should go into directory demo0. So, start with checking out essential build scripts that will help to fetch core source and set up a working Smalltalk/X jv-branch build environment:

hg clone hg clone https://bitbucket.org/janvrany/stx-goodies-builder-rake demo0
cd demo0
rake

Step 2: Creating a Repository for Application Code

Let's assume, you're starting with a greenfield project. You need to store your sources in a version control. Smalltalk/X jv-branch comes with decent support for Mercurial so let's use it. You may also use CVS but, believe me, you don't want to use it especially if you may use Mercurial.

First, you need to decide to which (Smalltalk/X) package would code go. Let's say it should go to package named jv:demos/helloworld_0. So, go to demo0\build subdir and create a new repository for it:

mkdir build\jv\demos
hg init build\jv\demos\helloworld_0

That's it.

Step 3: Create Initial Application Code

Now it's time to write some code. Basically you need to create at least three classes:

  • jv_demos_helloworld_0 - so called project definition class. This class contains a metadata about the package. Think of it as setup.py in Python or .gemspec in Ruby.
  • HelloWorld0 - the main application class. This is where the real logic is.
  • HelloWorld0Start - the application entry point. When the application is compiled to a standalone executable, once the Smalltalk/X VM initialize itself, it transfer control to HelloWorld0Start>>main: passing command line arguments. Think of it as of int main(int artc, char **argv) in C. In this method you may process command line arguments and eventually fire the main application - HelloWorld0>>open.

Let's so it. Launch Smalltalk/X IDE:

cd build\stx\projects\smalltalk
smalltalk -I --quick

First to configure Mercurial:

*

Open a system browser, switch to package view (from menu pick ViewPackage). Then create a new package using menu pick PackageNew...:

This will create (almost) all the necessary code for you:

  • In the first dialog, choose GUI-Application as application type and fill in a package name - jv:demos/helloworld_0 and click Create. This would create an empty "application" package.
  • Then you'd be asked for an application class name. Fill in HelloWorld0. Once you click OK the wizard will create the class and generate some initial code. You may change the code later.
  • Then you'd be asked for a statup class name. Likewise, this will create an initial startup class and generate a default main: method that will open an application specified in previous step.

Although most of the code has been generated, one little tweak may be needed. When user closes main application window either by clicking to X button in titlebar or picking an exit menu item, we'd like the whole application to terminate. This is not done automatically but it's easy to fix. All we need to is in method HelloWorld0>>closeDownViews call Smalltalk exitIfStandalone: 0:

Do not call plain old Smalltalk exit:0. The problem with this is that if called from IDE (for example when debugging or testing the application) it would terminate the IDE which is likely something you don't want.

Step 4: Commiting Code

To commit the code to Mercurial repository, simply select the package in browser and pick PackageRepositoryCheckIn... menu. Fill in a commit message and click Commit:

Step 5: Compiling Standalone Application

By standalone application we mean an executable (.exe on Windows) and bunch of libraries (.so or .dll) which can be deployed at user machine.

First we need to update a working to the latest code:

cd build\jv\demos\helloworld_0
hg up

Use hg sum that correct revision is checked out. To compile the application, just do

bin\setenv.bat
cd build\jv\demos\helloworld_0
mingwmake

On Linux, just do

cd build\jv\demos\helloworld_0
make

If compilation succeeds, you should find helloworld_0.exe there. Just run it and your new application should come up:

Time for a beer!

Topics not (yet) covered

  • Creating installer
  • Configuring Jenkins job

Attachments (14)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.