From Spring
Jump to navigationJump to search
172px-Symbol comment vote.svg.png Warning! This page is outdated! The information displayed may no longer be valid, or has not been updated in a long time. Please refer to a different page for current information.

alpha 4 (spring SVN)
Mod Support
Supports All Mods
<- Back to List of AIs

Forum threads


This AI is DEPRECATED, see Java AI Interface instead.

JAI is a Java wrapper interface for the GlobalAI interface of Spring. It allows AIs to be written in Java. It is not an AI itself.

It is not recommended to use or even test this version, as it is based on the C++ AI interface still. Development is on hold, till the new C interface for AIs is released, after which JAI will be ported to use that interface, for greater simplicity and flexibility.

At the time of writing (May 2008), JAI only works with SVN builds of Spring, due to a necessary change in the way Spring handles AI loading. The current JAI package has been developed and tested using spring r5956.


  • - for testing JAI with the default Java AI implementation
  • - for implementing your own Java AI and for testing JAI deeper

How to use/test it

First of all, extract the contents of JAI-<version> to your /spring/ directory. Note that, unlike normal AI DLLs, the JAI.dll does NOT belong directly into /spring/AI/Bot-libs, but into the /JAI subdirectory.

Software you need to have installed to be able to run JAI:

Make sure your Env-Vars are set like this:

On Windows:
SET JAVA_HOME=C:/Program Files/Java/jre1.6.0_05
SET PATH=%JAVA_HOME%/bin;%JAVA_HOME%/bin/client;%PATH%

On Linux:
export JAVA_HOME=/usr/jre1.6.0_05
export PATH=$JAVA_HOME/bin:$JAVA_HOME/bin/client:$PATH

If your lobby of choice does not support adding Java AIs as bots yet (until May 2008 only supported by SpringLobby), you will have to manually edit the startup script for spring. A simple way to do this is the following:

1. Start TASClient
2. Host a new game
3. Set everything to your liking
4. Add one or more Bots using a normal AI DLL such as AAI.dll or KAIK.dll
5. Start the game and abort it using SHIFT+ESCAPE once it's loaded
6. Open script.txt (in the spring root directory)
7. Search for aidll=<whatever DLL you choose>
8. Replace it with aidll=AI/Bot-libs/tst.jar
9. Open a command line window, navigate to your spring directory
10. Start Spring using "spring.exe script.txt" on the command line

If the game crashes, See Bug Report below If it does not, and you're using the tst.jar, you can chat numbers from 1 to 7 to test the AI. This is how tst.jar should react to chat numbers:

1 List friendly units
2 Print start position
3 Listing selected units
4 Listing UnitDefs
5 Attack: sends all units to positions of currently visible ememies
6 Toggle global rally point: move units to random position after creation (default: false)
7 Attack cheat: sends all units to positions of enemies

Some of these commands may require you to switch your team to the AI's, and build some units first. Do "/cheat" and then "/team 1" to achieve this.

Bug Report

If the game crashes, check the various log files:

  • AI/Bot-libs/JAI/log/
  • AI/hoijuiAI/log/
  • infolog.txt (spring default log file)
  • hotspot.log (JVM log file)
  • hserror_pid*.log (indicates a fatal JVM crash)

Most likely, you will not have all of them. They will be reduced in number in future versions, sorry ;-) Please report any errors to hoijui in the forum or on the main lobby, thanks. Do not commit the error as a bug on mantis please.

Build from Source

(Hint: the whole procedure is currently a bit simpler on windows) There are two makefiles available:

  • windows (tested on XP)
  • linux (tested on Upuntu 7.10).

they both compile with mingw and for windows (so they can be used to create for the official release build of spring).

First off, you need the current spring svn version and the build environment set up for it, see Compiling Spring. Build spring (make sure that JAI is not yet in AI/Global, as building spring would fail then).

Software you need to have installed to be able to compile JAI:

Extract the to: spring_current_svn/AI/Global in the Makefile(s), you have to adjust the vars:

  • SPRING_CURRENT_WINDOWS (only change this if you use the unix makefile)

on unix, you can set SPRING_CURRENT_WINDOWS to a mount of an smb shared spring on a windows PC, which needs to contains the same build as the one on unix. if you dont do this, you have to manually copy the results to your test machine on windows. As the makefile only compiles for windows, you can not test JAI on linux yet, except you adjust the makefile yourself and get it to work.

Compile with either of the two:

makefile -f Makefile_unix jall

makefile -f Makefile_win32 jall

You should now have JAI ready to run, please see above.

Creating your own implementation

To create your own implementation, it is best to use hoijui's test implementaion at JAI-<version> or JAI-<version> as a start. It are minimal, sample implementations, which come with a netbeans project each. A Java GlobalAI consist of one implementation for each:


To compile, you also need JAI.jar (JAI-<version> in your classpath.

You can override methods from the superclass of or to implement AI behavior. Once you are done modifying, just export your classes to a jar, and use it as your Java AI as described above. Make sure to set your new jar in step 8.

If you need further Java libraries, put the jars into AI/Bot-libs/JAI/lib, and native libraries into AI/Bot-libs/JAI/lib aswell.


It is possible to debugg your Java AI while it runs in spring. To enable debugging, you need to save the following into file AI/Bot-libs/JAI/config.xml:

<?xml version="1.0" encoding="UTF-8" ?>




Run spring with a JAI implementation. Now you can connect with a java debugger to the machine running spring on port 7777.

How does it work

JAI utilizes the jvm.dll of the JRE/JDK through JNI, to create a virtual machine for the Java AI to run in. It uses the same C/C++ interface as the native AIs, and just translates calls from one langauge to the other, bidirectional. Most of the sourcecode is generated with SWIG. This has the advantage that it supports a lot of other languages. One side is always C/C++, but the other could be Java, Lua, C#, Phyton, Ruby, ...

See SWIG Home for further details. Supporting an other language is not as easy as just switching one variable from "Java" to "Ruby" eg, but if you are desperate, you might want to use JAI as a base to support your favourite language.

Used Libraries

  • JVM: ...cause we are doing Java
  • JarClassLoader: loading classes from jars at runntime (Java)
  • Apache Commons: logging and parsing XML (Java)
  • log4j: logging (Java)
  • javax.vecmath.Vector3f: backend for the Java version of float3 (Java)
  • TinyXML: parsing XML (C/C++)
  • CMetalMap: Krogothes Metal Spot finder (C/C++)


  • making it ready for release -> waiting for feedback

<- Back to AI page