Faculty of Information Technology
Software Engineering Group

Source Code

STX:LIBJAVA Mercurial repository is located at https://swing.fit.cvut.cz/hg/stx.libjava.

Loading STX:LIBJAVA into Smalltalk/X

  • Set up Smalltalk/X to use Mercurial+ source code management for STX:LIBJAVA. packages. To do so, go to settings, select Source Code Management and add new per-package setting: stx:libjava/* and Mercurial+. Please note the star and plus!

You may want to read how to recompile your Smalltalk. You should regularly recompile your STX:LIBJAVA code to make sure it compiles cleanly.

Useful code snippets

Java initialization

Following code initializes the JVM under Smalltalk/X:

Java flushAllJavaResources.
Java release: JavaRelease openJDK6. "Tells which Java release to use"
JavaVM boot.                "Loads basic classes and performs java.lang.System#initSystemClass"

Debugging stx:libjava

Useful trace flags

"Trace .class file reading - useful when debugging built-in class reader"
JavaClassReader verbose:true.    
JavaClassReader verbose:false.

"Debugging exceptions - shows stack *before* unwinding to handler context"
JavaVM exceptionDebug: true.
JavaVM exceptionDebug: false.

The Ultimate Java Workspace

"/ Java =========================================="
Smalltalk loadPackage:'stx:libjava'.
Java flushAllJavaResources.
Java initialize.
JavaVM initializeVM.

JavaNativeMethod flushAllCachedNativeMethods.
Java initSystemClass.
Java classPath.

"/ Hello world"
Java addToClassPath: ((Smalltalk packageDirectoryForPackageId: 'stx:libjava') / 'java' / 'libjava-examples' / 'bin') pathName.
(Java classForName: 'stx.libjava.examples.HelloWorld') main:#().
(Java classForName: 'cvut.fit.dpo.arithmetic.Main') main:#().

"/ Build and add libjava-tests project"
UnixOperatingSystem executeCommand: ('ant -f ' , ((Smalltalk packageDirectoryForPackageId: 'stx:libjava') / 'java' / 'libjava-tests') pathName , '/build.xml').
Java addToClassPath: ((Smalltalk packageDirectoryForPackageId: 'stx:libjava') / 'java' / 'libjava-tests' / 'bin') pathName.

Java addToClassPath: '/usr/share/java/junit.jar'.
(Java classForName: 'stx.libjava.tests.junit.JUnit3Tests') main:#().

Java addToClassPath: '/usr/share/java/junit4.jar'.
(Java classForName: 'stx.libjava.tests.junit.JUnit4Tests') main:#().

Java addToClassPath: '/usr/share/java/junit4.jar'.
(Java classForName: 'stx.libjava.tests.regex.RegexTests') main:#().

Java addToClassPath: '/usr/share/java/junit4.jar'.
Java addToClassPath: '/usr/share/java/log4j-1.2.jar'.
(Java classForName: 'stx.libjava.tests.log4j.Log4JTests') main:#().

"/ Apache ant"
Java addToClassPath: '/usr/share/java/ant*.jar'.
(Java classForName:'org.apache.tools.ant.launch.Launcher') main:#().


  • javap - Java .class file decompiler shipped with JDK
  • Class Editor - GUI tool to inspect .class file - displays constant pool.
  • groovysh (aptitude install groovy) - interactive console for Java
Last modified 3 years ago Last modified on Aug 8, 2014, 12:09:47 PM

Attachments (1)

Download all attachments as: .zip