Tutorial 2

INSTALLATION

This chapter explain how to compile and run GTGE game.
Objective : Understand how to install GTGE library.
collapse/expand

GTGE is a pack of Java functions for making 2D game. In order to use those functions, technically GTGE must be installed first. In Java context, it means insert GTGE library into the game classpath.

There are 2 steps to run a GTGE game :

  1. Compile : convert the game source code (.java) into bytecode (.class).
  2. Run : run the bytecode (.class).
In these 2 steps GTGE library should be inside the game classpath.

compile and run diagram

Compile

Tutorial2_1.bat

The first step is converting the game source code (.java) into bytecode (.class) by using Java compiler (java_path\bin\javac.exe) that included in Java SDK (see previous chapter).
Because we have set the system path to this Java compiler in previous chapter, this compiler (javac.exe) can be used within any directory.

How to compile the game source code :

file :: javac.exe

Syntax:
   javac -classpath %CLASSPATH%;.;[GTGE_dir]/golden_x_x_x.jar [game_source_code]

whereas :
%CLASSPATH%         = system classpath (we have set this on autoexec.bat in previous chapter)
.                   = current directory (where the game source code is located)
[GTGE_dir]          = where GTGE library is located (golden_x_x_x.jar)
[game_source_code]  = the game source code (.java)


For example:
compile YourGame.java with GTGE v0.2.0 - C:\GTGE\golden_0_2_0.jar

   javac -classpath %CLASSPATH%;.;C:/GTGE/golden_0_2_0.jar YourGame.java
In this example, YourGame.java is compiled into YourGame.class.

Execute/Run

Tutorial2_2.bat

The next step is running the compiled source code (bytecode) by using Java launcher (java_path\bin\java.exe), also included in Java SDK.

How to run the game bytecode :

file :: java.exe

Syntax:
   java -classpath %CLASSPATH%;.;[GTGE_dir]/golden_x_x_x.jar [game_byte_code]

whereas :
%CLASSPATH%       = system classpath (we have set this on autoexec.bat in previous chapter)
.                 = current directory (where the class file is located)
[GTGE_dir]        = where GTGE library is located (golden_x_x_x.jar)
[game_byte_code]  = the game bytecode (.class), omit the .class


For example:
run YourGame.class with GTGE v0.2.0 - C:\GTGE\golden_0_2_0.jar

   java -classpath %CLASSPATH%;.;C:/GTGE/golden_0_2_0.jar YourGame
In this example, the game YourGame.class will be executed.

For practice, try to compile and run this tutorial source code (located at [src] directory).

Having trouble with compiling/running the game? Post the problem in GTGE message board.


Summary :

  • There are two steps to run GTGE game, compile by using javac.exe and run by using java.exe.
  • In these two steps GTGE library should be inside the game classpath.

Reference : Java Compiler Documentation (javac.exe), Java Launcher Documentation (java.exe), Setting Classpath

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id
Page 2 of 12