OpenWrt Forum Archive

Topic: JamVM + GNU Classpath on Kamikaze (+ Wiki question)

The content of this topic has been archived on 28 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

OK. I've started this a new thread because it's now working and I figured the information might be useful to some. This probably belongs in the Wiki somewhere, but I don't have the time right now to add it and ensure that it's formatted. If someone does, then feel free, if not I'll try and add it a little later this week. At the minute it's specific to the WRT54G series, but should work with any Kamikaze (Or possibly White Russian) router. As such, I don't know if it should reside in a WRT54G specific page, or as a generic page with router-specific sections. A big thank you to Robert Lougher for creating JamVM and for his help in getting it to run on my PC, which taught me what the problems were with getting it to run on the router.

Background:
Sable-mini doesn't contain anything particularly useful for running "real" Java applications, and the full SableVM installation is too big to be installed on a WRT54G series router. In addition Sable appears to be largely unsupported, while JamVM is a live project with a good track record and support. However the JamVM package only contains the Jam-specific classes and requires the GNU classpath. This has native code which needs to be cross-compiled for the router platform.

Instructions (Assuming a working Kamikaze installation):

1. Download the Kamikaze "source" from SVN or the site. Decompress and run make menuconfig. I believe that the SDK is all that's required, but a full build will result in a working cross-compiler toolchain (You can set one up yourself, but there's no point re-inventing the wheel!)
2. Download the GNU Classpath (http://www.gnu.org/software/classpath/). Decompress somewhere.
3. Add the toolchain/bin directory (In the Kamikaze staging area, it's the one that contains the architecture specific GCC and friends) to PATH. If you don't do this, the classpath configure will silently default to building code for the build machine and noth the target.
4. Change to the Classpath directory. Create a new sub-directory ("mipsel" was a good name for me, but it doesn't matter what you use). Change to that new directory.
5. Run configure as follows:
../configure --host=mipsel-linux --prefix=/usr --disable-gtk-peer --disable-gconf-peer --disable-plugin --disable-qt-peer
The entry for host should match the prefix of the cross-compilation toolchain made by Kamikaze.
--prefix=/usr is necessary because the default is /usr/local which doesn't tie in nicely to the Kamikaze directory structure.
-disable-* These are essential to avoid attempting to link in to libraries which are not available on Kamikaze (Basically this loses you the accelerated AWT... I figure that the WRT54G's are not devices on which you want to run a framework-based windowing system.
Watch the messages from configure to check that it has found the Kamikaze toolchain.
6. Run "make". This should build the GNU classpath.
7. Create another subdirectory ("inst_temp" is as good as any). We're going to install into this directory.
8. Run:
make DESTDIR=/full/path/to/new/directory install
9. We now have a Classpath... celebrate with a beer for the time it takes to realise how much bigger this is than the available space on the router!

Paring down the Classpath. - Your methods and requirements may vary, but this worked for me.
------------------------------------
10. Create a new directory parallel to the "inst_temp" we created earlier ("staging" might be a good name). This is where we will assemble the real installation set.
11. Change to the new directory.
12. Copy usr/lib and usr/share/classpath from the original into it.
13. Change to the usr/share/classpath directory
14. Delete the examples directory and tools.zip.
15. Create a new temp directory. We're going to unzip the class files here and start "trimming". Change to the new directory and run "unzip ../glibj.zip"
16. We now have a set of directories containing the classpath itself ("java", "gnu", "sun" etc"). At this point we need to prune stuff from the tree that we don't need. This depends on your requirements. Personally, I got rid of all of javax, java.awt, java.rmi and some others. Don't forgot to track down the helper classes in "gnu" that are related to the java classes.
17. Trimming complete. From the "temp" directory, run
zip -r -9 ../glibj-sm.zip *
18. Change back to the "staging" directory and verify the size of your "small" glibj. I got mine down to around 4MB

Installing the Classpath
-------------------------------
19. There isn't enough room on the JFFS to install this "properly", so we're going to install into /tmp and use symlinks to put stuff where we need it. Building a bootstrap to download the files on startup is left as an exercise for the reader. ;-) You want to copy (scp) the whole of the lib directory and our glibj-sm.zip file. Be aware that scp will copy the targets of symlinks and not the links themselves. You will have to re-create the .so and .so.0 symlinks on the router.
20. ssh to the router.
21. Run "mkdir -pv /usr/local/classpath/lib"
22. cd /usr/local/classpath/lib
23. In this directory we need to symlink the contents of /tmp/lib. To save having to build all the symlinks every time the router is booted, I would suggest making the "classpath" directory a real directory and linking the files individually.
24. At this point in /usr/local/classpath/lib, you should have "classpath" and "security" directories and a file "logging.properties".

Running JamVM
----------------------

25. Run
jamvm -verbose -Xmx5M -Xbootclasspath/a:/tmp/glibj-sm.zip ClassToRun

-verbose is a good one to have to check that it's all running OK. It'll list the classes as they are found and linked in.
-XMx5M sets the heap to a maximum of 5M. The default for JamVM is 16M which isn't going to work on a router with 8M of available memory (After tmp has taken 8M of that!).
-Xbootclasspath/a appends our Classpath to the internal classpath. This ensures that the VM-specific classes in classes.zip are used instead of any duplicates in our Classpath.

You should find that your code runs. I've tested this with a simple Hello World application and will be porting something more complex later today. I would suggest that you install JamVM and the GNU Classpath on your PC as well, and create a similarly trimmed Classpath. That way you can test code on a host machine without having to install it to the router every time.

That's all folks!

Thanks, worked for me on wl500g premium (mipsel, jamvm seems to compile fine although by default packgae not compiled on mipsel).

Misha

Btw, if people want a simple package for jamvm 1.5.1 and classpath which work together, I found a patch that works well:

http://lists.openwrt.org/pipermail/open … 01769.html

here is my diff from trunk:

Index: lang/classpath/Makefile
===================================================================
--- lang/classpath/Makefile    (revision 0)
+++ lang/classpath/Makefile    (revision 0)
@@ -0,0 +1,57 @@
+#
+# Copyright (C) 2006 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# $Id$
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=classpath
+PKG_VERSION:=0.97.1
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=ftp://ftp.gnu.org/gnu/classpath/
+PKG_MD5SUM:=35e81f0e0055a8b8a7a879077cf2b3c6
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/classpath
+  SUBMENU:=Java
+  SECTION:=lang
+  CATEGORY:=Languages
+  TITLE:=GNU Classpath
+  URL:=http://www.gnu.org/software/classpath/
+#  MAINTAINER:=Roberto Riggio (roberto.riggio at create-net.org)
+endef
+
+define Package/classpath/Description 
+    GNU Classpath, Essential Libraries for Java, is a GNU project 
+    to create free core class libraries for use with virtual 
+    machines and compilers for the java programming language.
+endef 
+
+CONFIGURE_ARGS+= \
+        --with-javac \
+        --enable-jni \
+        --disable-gtk-peer \
+        --disable-gconf-peer \
+        --disable-plugin \
+
+define Build/Compile   
+    $(MAKE) -C $(PKG_BUILD_DIR) DESTDIR="$(PKG_INSTALL_DIR)" \
+        CPPFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
+        all install
+endef
+
+define Package/classpath/install
+    $(INSTALL_DIR) $(1)/usr/lib/classpath
+    $(INSTALL_DIR) $(1)/usr/share/classpath
+    $(CP) $(PKG_INSTALL_DIR)/usr/lib/classpath/* $(1)/usr/lib/classpath
+    $(CP) $(PKG_INSTALL_DIR)/usr/share/classpath/glibj.zip $(1)/usr/share/classpath
+endef
+
+$(eval $(call BuildPackage,classpath))
+
Index: lang/jamvm/patches/001-heap_size.patch
===================================================================
--- lang/jamvm/patches/001-heap_size.patch    (revision 0)
+++ lang/jamvm/patches/001-heap_size.patch    (revision 0)
@@ -0,0 +1,12 @@
+--- jamvm-1.5.1-old/src/jam.h   2008-02-22 02:57:22.000000000 +0100
++++ jamvm-1.5.1-new/src/jam.h   2008-03-12 12:21:31.000000000 +0100
+@@ -676,7 +676,7 @@
+ 
+ /* default maximum size of object heap */
+ #ifndef DEFAULT_MAX_HEAP
+-#define DEFAULT_MAX_HEAP 128*MB
++#define DEFAULT_MAX_HEAP 64*MB
+ #endif
+ 
+ /* default size of the Java stack */
+
Index: lang/jamvm/Makefile
===================================================================
--- lang/jamvm/Makefile    (revision 12652)
+++ lang/jamvm/Makefile    (working copy)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=jamvm
-PKG_VERSION:=1.5.0
+PKG_VERSION:=1.5.1
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@SF/jamvm
-PKG_MD5SUM:=a965452442cdbfc94caba57d0dd25a8f
+PKG_MD5SUM:=5a82751b50391eb092c906ce64f3b6bf
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -24,7 +24,8 @@
   CATEGORY:=Languages
   TITLE:=A compact Java Virtual Machine
   URL:=http://sourceforge.net/projects/jamvm
-  DEPENDS:=+libffi-sable @!mips @!mipsel
+  MAINTAINER:=Roberto Riggio (roberto.riggio at create-net.org)
+  DEPENDS:=+libffi-sable +libpthread +zlib +classpath @!mips
 endef
 
 define Package/jamvm/description
@@ -38,6 +39,7 @@
 
 CONFIGURE_ARGS+= \
     --enable-ffi \
+        --with-classpath-install-dir=/usr \
     --disable-int-threading \
 
 define Build/Compile

Save somewhere, e.g., using gedit (you need a text editor that won't wrap or change tabs to spaces, not to mention a browser). Now do:

scripts/feeds update -a
cd feeds/packages
patch -p0 < pathtomysavedpatch

I think then you will need to script/feeds update -a again and do make menuconfig then make

Oh yeah I have a flash drive on my Asus wl-500g premium that is root directory so no need for me to compress (this is _not_ the compressed/shrunk version of classpath but full I believe).

Misha

(Last edited by misha680 on 24 Sep 2008, 03:23)

Hey!

I would like to run a HelloWorld with jamvm. I installed it with opkg, but it doesn't work.

root@OpenWrt:~# jamvm /home/kukodajanos/Download/HelloWorld
Exception occurred while VM initialising.
java/lang/NoClassDefFoundError: java/lang/Class

Do i need glibj.zip to run the program? How can i install it? I am a newbie in OpenWRT.

Regards, János

Sorry I don't use OpenWRT anymore these days sad

I looking for  glibj.zip  working with jamVM on mipsel 47xx architecture.
I try cross-compile gnu class path but I have some problems.
Thanks in advance for help.

sylwos  at  gmail  dot   com

General Discussion:]

Hey guys I'm writing this because I want to tell/explain you something in case you didn't realize.
I have found a lot of players who complain because three players with the max level are teamed up. First of all, I'm not repeating another topic, I know there are other topics about the teams, but what I want to say is something a bit different, but it has a lot to do with teaming or buying weapons.

They always say: ''No fair teams''. First of all what does ''fair'' mean? Easy; free from bias, dishonesty, or injustice (as said in the pocket dictionary I use to translate English to my first language, which also fits with the definition for ''fair'' in my language).

Then we can realize, it's totally fair when a player in the maximum level and with all the weapon packs plays versus a new player without bought weapons in the level one. Why? Because reaching the max. level and getting weapons is not against the rules, is not cheating and everything is earned just as Donkin brothers wanted.

Everybody is able to buy weapons, having or not having the money to buy hasn't anything to do with being fair.

PS. It's like if you say: ''Grim has only a GameBoy and Tifany has an Xbox360 and a PS3, she is being unfair''. Senseless.

Its like saying "I know someone is going to say this so I'm getting in this topic before he/she does"

or something like that I suppose.

Don't use it much myself. 




Java Training Courses

The discussion might have continued from here.