OpenWrt Forum Archive

Topic: Java Environment on OpenWrt (OXNAS)

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

Hi guys,

after days of hard work with lots of try&error i finally managed to build firmware from snapshots for oxnas. to my big disappointment i noticed that till today noone managed to get a working java environment on that devices? how it comes? i tried to get rid of crappy medion firmware to switch to an better supported one, but with ffp i was at least able to run embedded java from oracle on my medion nas... its the last part of my puzzle for running minimserver on my nas with an way better firmware. there seems to be no packages of embedded java (oracle, phoneme, jamvm, etc) or any instructions how to compile one on my nas. can anyone plz help me out or explain why java isn't supported? it seems even arch or debian would come with java support on that device - but i prefer openwrt with luci as my knowledge still seems to be quite basic! wink

thx i.a. alex

Sorry to be slightly OT: While I do not have an answer regarding Java, I would be interested if you installed OpenWrt into the flash memory of your oxnas device. Does it use squashfs and overlayfs, so that you can always revert to a "known good" OpenWrt installation?

Yes i did. Thx to UART i always can stop boot process, run boot_rescue and flash new firmware. Back to Java! wink

JamVM is available in oldpackages. It should build without errors for trunk.


it seems even arch or debian would come with java support on that device

Arch or Debian probably have more developers and maintainers.
You can submit and maintain JamVM to the github packages repo via pull request.

Since GNU Linux is Free Software you can check the cross platform patches that are used in other distributions for Java.
- debian: https://packages.debian.org/sid/openjdk-8-jdk
- fedora: http://pkgs.fedoraproject.org/cgit/java … enjdk.git/

Most OpenWrt targets can support Java only with extroot - less interesting for most developers.
(Not to mention the constant security fixes you have to track when using java
(afaik latest sidechannel in JSSE - https://www.youtube.com/watch?v=c4tNU5BjvLM )

Watching with interest. I have a half-mind about running a minecraft server on my router. smile

thx zloop, oldpackages was a very good hint. now i managed to create firmware with jamvm 1.6 included (after installing openjdk on build machine). "jamvm -version" is showing a running java vm now and i need to figure out how to set paths for running with minimserver! i fear as jamvm 1.6 is based on java 1.5 it wont work anyways, as minimserver requires java 7 at least. jamvm 2.0 seems to support the latest java versions, but is not available yet for openwrt. guess next weeks would be fiddling around how to get jamvm 2.0 for openwrt... anyone? big_smile

life isn't easy for a windows guy... wink

(Last edited by aschuetze on 1 Jan 2015, 16:13)

aschuetze wrote:

thx zloop, oldpackages was a very good hint. now i managed to create firmware with jamvm 1.6 included (after installing openjdk on build machine). "jamvm -version" is showing a running java vm now and i need to figure out how to set paths for running with minimserver! i fear as jamvm 1.6 is based on java 1.5 it wont work anyways, as minimserver requires java 7 at least. jamvm 2.0 seems to support the latest java versions, but is not available yet for openwrt. guess next weeks would be fiddling around how to get jamvm 2.0 for openwrt... anyone? big_smile

life isn't easy for a windows guy... wink

I have a development environment set for ramips, I'll give it a shot to compiling jamvm 2.0... wish me luck (it's not exactly easy for this Linux guy either, don't feel bad)

big THX for giving it a try, your help is much appreciated! smile i already got:

root@NAS-Server:/usr/bin# /usr/share/minimserver/bin/startc
MinimServer: Java 7 or later is required: current version is 1.5.0
java.lang.reflect.InvocationTargetException
   at java.lang.reflect.VMMethod.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:327)
   at jamvm.java.lang.JarLauncher.main(JarLauncher.java:50)
Caused by: java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
   at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:607)
   at javax.swing.plaf.basic.BasicLookAndFeel.initialize(BasicLookAndFeel.java:1720)
   at javax.swing.UIManager.setLookAndFeel(UIManager.java:912)
   at javax.swing.UIManager.<clinit>(UIManager.java:245)
   at org.jminim.launch.Launcher.reportErrorUC(Launcher.java:427)
   at org.jminim.launch.Launcher.launch(Launcher.java:118)
   at com.minimserver.launch.LaunchServer.main(LaunchServer.java:30)
   at java.lang.reflect.VMMethod.invoke(Native Method)
   ...2 more
Caused by: java.lang.UnsatisfiedLinkError: Native library `gtkpeer' not found (as file `libgtkpeer.so') in gnu.classpath.boot.library.path and java.library.path
   at java.lang.Runtime.loadLibrary(Runtime.java:763)
   at java.lang.System.loadLibrary(System.java:670)
   at gnu.java.awt.peer.gtk.GtkToolkit.<clinit>(GtkToolkit.java:177)
   at java.lang.VMClass.forName(Native Method)
   at java.lang.Class.forName(Class.java:233)
   at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:583)
   ...9 more

so it seems just a question of newer version! smile would your ramips build easily become part of trunk, so i can compile for arm (oxnas)? sorry, stupid question i guess, but i got info overflow over the last week - never openwrt'ed before and am more than proud already building own firmwares... big_smile

aschuetze wrote:

big THX for giving it a try, your help is much appreciated! smile i already got:


so it seems just a question of newer version! smile would your ramips build easily become part of trunk, so i can compile for arm (oxnas)? sorry, stupid question i guess, but i got info overflow over the last week - never openwrt'ed before and am more than proud already building own firmwares... big_smile

I am not a developer, just an end-user like you (built my first firmware less than a month ago). smile Can't commit anything to trunk. I'll try to  get it compiled for my architecture, then if it works I may give it a try for oxnas and see if I can package it and make it available for download. Compiling may take a long time as I'm doing this on a laptop.

(and no this is not completely disinterested - as I said I may have a use for java myself)

(Last edited by stamasd on 1 Jan 2015, 20:02)

smile take your time! maybe someone else can step in and help us out here. i was quite surprised that noone seems to be in need for java on openwrt devices!? :-O at least the net doesnt come up with very helpful information for guys like me. wink feeling quite close now achieving my goal and all the hours since xmas may pay off somehow! smile

TBH, java is in general quite a resource hog, and most devices that run openwrt are fairly short on cpu cycles and memory. Not really surprising that java doesn't have high demand here.

smile i already got that point, but isnt that the beauty of having an modular os? Seeing openwrt as a real alternative for lot of nas devices with the nice to handle luci, i assume more and more java based apps may get used on openwrt.

I'm running JamVM 2.0.0 + classpath 0.99 on Barrier Breaker / Carambola2 - obviously happy to provide the patches you'll need:

- classpath has a serious bug where conversion of doubles/floats to strings leaks memory. The patch for that is in the associated bug report (easily found with google) and easy to apply.

- classpath glibj.zip is compressed with standard jar (zip) compression. It gets *larger* when incorporated into squashfs. So you will want to patch the generation of glibj.zip or re-compress it with -0 compression. While you'll find glibj.zip is now 20MB, the resulting firmware image will be 700K smaller in the end. Really.

- A complete OpenWRT firmware build including JamVM 2.0.0 and full classpath0.99 is ~9MB for a Carambola2 and runs with a reasonable memory footprint.

- If you use the -verbose:class option of jamvm, you can collect information on which classes you really need and substantially reduce the size of classpath glibj.zip.

(Last edited by danak6jq on 2 Jan 2015, 00:58)

I was able to compile jamvm 2.0 for ramips; the stripped binary is 388kB.
To compile it for oxnas though I will have to build a whole new toolchain. smile

Here is jamvm-2.0.0 compiled for oxnas. It is not a opkg package but simply a package that you can unarchive in / to get the binaries in their proper places. I can't check if it works since I don't have an ARM device with OpenWRT installed. I did not attempt to compile classpath, that would be a separate exercise of larger scope.

Download here: http://www.filedropper.com/jamvm200oxnastar

Wow, that was fast progress. Will try asap and get back to you guys. Thx again.

@danak6jq: you gave new riddles to solve, will google+read+google+read... big_smile

It would be nice if you could make an OpenWrt Makefile out of it, so that we can build it for other platforms as well. Thanks!

after creating ln -s /usr/bin/jamvm /usr/bin/java i'm getting:

root@OpenWrt:/# java -version
java version "1.5.0"
JamVM version 2.0.0
Copyright (C) 2003-2014 Robert Lougher <rob@jamvm.org.uk>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Build information:

Execution Engine: inline-threaded interpreter with stack-caching
Compiled with: gcc 4.8.3

Boot Library Path: /usr/local/classpath/lib/classpath
Boot Class Path: /home/silviu/openwrt/jamvm200oxnas-install/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip

which means jamvm 2.0 seems to run succesfully! smile when starting minimserver now i'm getting:

root@OpenWrt:/# /usr/share/minimserver/bin/startc
Exception occurred while VM initialising.
java/lang/NoClassDefFoundError: jamvm/java/lang/VMClassLoaderData

at least its not starting with java 7 required message, but it seems that class path and library path are compiled into jamvm and dont match the folder structure of my device. guess i need somehow compile it myself - any recommended guides? till yet i used the openwrt feeds to get required components into my firmware. compiling classpath and jamvm 2.0 in my chain seems to be the key.

(Last edited by aschuetze on 2 Jan 2015, 14:06)

probono wrote:

It would be nice if you could make an OpenWrt Makefile out of it, so that we can build it for other platforms as well. Thanks!

I can try (never done that before, but it doesn't look too complicated). But that would make an unmaintained and unsupported package, since I don't have any time to dedicate on a regular or even irregular basis to maintaining it.

aschuetze wrote:

after creating ln -s /usr/bin/jamvm /usr/bin/java i'm getting:

root@OpenWrt:/# java -version
java version "1.5.0"
JamVM version 2.0.0
Copyright (C) 2003-2014 Robert Lougher <rob@jamvm.org.uk>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Build information:

Execution Engine: inline-threaded interpreter with stack-caching
Compiled with: gcc 4.8.3

Boot Library Path: /usr/local/classpath/lib/classpath
Boot Class Path: /home/silviu/openwrt/jamvm200oxnas-install/share/jamvm/classes.zip:/usr/local/classpath/share/classpath/glibj.zip

which means jamvm 2.0 seems to run succesfully! smile when starting minimserver now i'm getting:

root@OpenWrt:/# /usr/share/minimserver/bin/startc
Exception occurred while VM initialising.
java/lang/NoClassDefFoundError: jamvm/java/lang/VMClassLoaderData

at least its not starting with java 7 required message, but it seems that class path and library path are compiled into jamvm and dont match the folder structure of my device. guess i need somehow compile it myself - any recommended guides? till yet i used the openwrt feeds to get required components into my firmware. compiling classpath and jamvm 2.0 in my chain seems to be the key.

Looks like the java interpreter is looking for its classes in 2 locations, both of which don't exist on your machine. The first one is its own built-in classes, but it's prefixed with my install path which doesn't exist on your machine. The other one is probably the default inslall location for the GNU classpath, which also doesn't exist there.

Here are the steps that I took.
First I installed a fresh copy of the OpenWRT repository in a separate directory - not to have any stuff contaminated with some of my ramips experiments. I built the toolchain for oxnas there (~/openwrt/git-oxnas/oxnas)
Downloaded jamvm http://downloads.sourceforge.net/projec … 0.0.tar.gz
Configured jamvm with the following:

PATH=$PATH:/home/user/openwrt/git-oxnas/openwrt/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin
export PATH
STAGING_DIR=/home/user/openwrt/git-oxnas/openwrt/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/
export STAGING_DIR
./configure --build=x86_64-unknown-linux-gnu --host=arm-openwrt-linux --prefix=/home/silviu/openwrt/jamvm200oxnas-install
make
make install

then simply compressed the contents of the install directory to make the package.

One small problem I ran into for the configuration is that cross-compiled zlib is required; I got around it by enabling zlib to be built when I do "make menuconfig" then just fish the binaries and headers from build_dir/target and copy them into staging_dir/toolchain/{lib and include}. Then configure finishes without a glitch.

(Last edited by stamasd on 2 Jan 2015, 14:30)

big THX, will try next! smile

stamasd wrote:

Here are the steps that I took.
First I installed a fresh copy of the OpenWRT repository in a separate directory - not to have any stuff contaminated with some of my ramips experiments. I built the toolchain for oxnas there (~/openwrt/git-oxnas/oxnas)
Downloaded jamvm http://downloads.sourceforge.net/projec … 0.0.tar.gz
Configured jamvm with the following:

PATH=$PATH:/home/user/openwrt/git-oxnas/openwrt/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin
export PATH
STAGING_DIR=/home/user/openwrt/git-oxnas/openwrt/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/
export STAGING_DIR
./configure --build=x86_64-unknown-linux-gnu --host=arm-openwrt-linux --prefix=/home/silviu/openwrt/jamvm200oxnas-install
make
make install

then simply compressed the contents of the install directory to make the package.

One small problem I ran into for the configuration is that cross-compiled zlib is required; I got around it by enabling zlib to be built when I do "make menuconfig" then just fish the binaries and headers from build_dir/target and copy them into staging_dir/toolchain/{lib and include}. Then configure finishes without a glitch.

I wanted a turn-key build. So I took the existing jamvm Makefile: feeds/oldpackages/lang/jamvm/Makefile and updated it to pull down and build JamVM 2.0.0, then placed that Makefile in my own (local) custom feed as jamvm2. After configuring my feeds.conf.default to include the local feed and the usual ./scripts/feeds update -a / install -a, I ran 'make menuconfig', selected jamvm2 under Languages/Java and ran 'make'

This takes care of the dependency on GNU classpath automatically - that's the problem with just cross-compiling jamvm and bundling up the install directory, you won't inherently get the dependencies.

Specifically, this line in jamvm/Makefile is worth paying attention to:

  DEPENDS:=+zlib +libpthread +librt +classpath @!avr32

For classpath, I needed to include the floating point string-coversion patches, and I modified the classpath/Makefile to pick up classpath-0.99.  Hence, I get turn-key builds and package creation with the OpenWRT buildroot bits. I don't think there's any reason the patches involved won't work for any OpenWRT platform supported by jamvm.

It is worth learning how to create your own local feed; it isn't difficult and makes life easier.

Anyone care to suggest a place to stash an archive of the patches I used?

danak6jq wrote:

Anyone care to suggest a place to stash an archive of the patches I used?

https://github.com/openwrt/packages smile

If you aren't interested in maintaining it, making a git repository on Github that people could add to their feeds would probably be welcome too. But having Buildbot do the work is as turn-key as it gets.

makro wrote:
danak6jq wrote:

Anyone care to suggest a place to stash an archive of the patches I used?

https://github.com/openwrt/packages smile

If you aren't interested in maintaining it, making a git repository on Github that people could add to their feeds would probably be welcome too. But having Buildbot do the work is as turn-key as it gets.

I suppose I asked for it, right? :-)  OK, I'll have to figure out how to submit my changes, never been to that particular rodeo before. Of course I much prefer having changes that I want integrated up-stream so I never have to worry about them.

There's probably an FAQ for package maintainers... will look when I have time later.

great to see we are all in some kind of school now, different classes of course! wink

The discussion might have continued from here.