Solution to “Error starting modern compiler”
April 21st, 2009
Right. So then I had the chance to open a old project in in eclipse today. From an old workspace. Tests still ran, code looked just as bad as badass as before.
Running the clean-build target through ant produced a message I haven’t seen before, though.
C:\Users\tormod.haugen\workspace\PROJECT\build.xml:38: Error starting modern compiler
Luckily Google was just a browser away, and I discovered through pitr’s blog that I needed to update the JVM used by Eclipse to the same as pointed at by JAVA_HOME.
I guess there can be more to it, and I guess you could override JAVA_HOME for that build, but this worked. Thanks.
Java plugin in Firefox under Ubuntu 9.04
April 15th, 2009
I needed to install a Java plugin for Firefox under Ubuntu 9.04 (beta). This didn’t happen by itself when I installed sun-java6-plugin, but a quick search showed me what Eirik Hoem found out a year ago.
Or, as Karl Trygve said in a comment; messing about in /usr is usually not a good idea
- the link could be made in /usr/lib/firefox-3.0/plugins, and the plugin would then be available for all users on the computer.
Linking the java plugin to Firefox (paths might vary a bit, depending on Java versions):
cd ~/.mozilla/firefox/.default/plugins
sudo ln -s /usr/lib/jvm/java-6-sun/jre/plugin/i386/ns7/libjavaplugin_oji.so
I didn’t have Icedtea installed, but I do use OpenJDK for development. Works now, at least.
Executing native processes from Java
September 17th, 2008
This is kind of a coincidence. Today I got contacted by a friend, wondering how to run a native Windows program from within Java. I said as I usually do: Google it
. Not liking to get that served myself, I did follow up with some real information. I don’t like being a RTFM slinging jerk, but it is fun to sting people you know.
Googling turned up a useful guide to how you can do this, both using Runtime.getRuntime().exec(”command”);
and with 1.5’s ProcessBuilder
.
Then comes the coincidence; just as I’m about to leave for home, I scan my feeds - at the top of my Programming
folder, Patrick Kua has the following entry: Executing native processes in Java on Windows.
Managing Memory in Java
September 4th, 2008
Getting memory management to play along in Java is a whole other chapter than it was in C and C++. And by that I mean simpler and better. Though a few people would still like to allocate and deallocate memory themselves, most agree that garbage collectors are a step forward (afaik). Whatever your stance on the case, GC is in Java, that’s the way it is. There are tweaks, and even replacement collectors, to get the garbage collecting to be done in tune with your code.
I’ll have a look on simpler aspects of managing memory in Java. For one - adding more available (heap) memory for your application. You’ll usually have need of this if you are writing big, memory hungry programs. Anything gathering and working on large amounts of data. Your hint will come from a thrown exception blaming java.lang.OutOfMemoryError: Java heap space
.
Assigning more memory to Java is as easy as supplying one or two parameters to java when starting your program. There is -Xmx=
for maximum heap size in bytes, and -Xms=
for initial heap size. Since increasing the heap take some resources, it is suggested setting the initial size at something that should be enough for use, and maximum to something that should be enough - period.
These values are specified in bytes, but you could do it in kB or MB by adding a suffix, like this: java -Xms=64m -Xmx=256m MyProgram
.
A crash citing the JVM out of memory could also easily be a (dire) warning about you having a memory leak or two in your code. Java isn’t invulnerable to those, though they are harder to get by accident. One usual suspect are Listeners, setting up a listener and then forgetting about it when the work is done could spell an early end to the session. Misbehaving (self-coded) collections are also a common way of stopping the garbage collectors from doing their work.
Detecting memory leaks are not that easy in Java. Since your program runs in a JVM, task managers in your OS will not report on your program, but on the virtual machine it is running in. To have a look at how your memory consumption is, you are in need of a Java profiler of some kind. An easy alternative is to fire up your program with java -Dcom.sun.management.jmxremote MyProgram
, and then running the tool Sun supplies with Java (from 1.5 up): jconsole. This program is located where you have the JDK installed - usually C:\Program Files\Java\jdk[version]\bin
on Windows.
Happy hunting.
Specifying what to get, or post
April 1st, 2008
I’ve noticed that I generally don’t post too much on this blog/journal/whatever. This partly comes from the fact that I suspect everyone to already know what I do, or find out. Thus I avoid public ridicule if I don’t write anything.
Well, as I really know that everybody can’t possibly know everything, I’ll try and just post stuff as I come across it, even if it does look simple from time to time. I found out yesterday that I do know simple stuff that others don’t - so here goes.
Whenever you just want to do a HTTP GET method to fetch something in Java, it might not be the easiest thing to do. Or perhaps it is? You could screw around with java.net.URLConnection
, opening connections, fighting error handling, writing to the connection’s stream in case of POST calls… or you could get Apache’s HttpClient. The call would then be:
GetMethod getMethod = new GetMethod("http://www.google.com/search");
NameValuePair[] parameters = {
New NameValuePair("q","searchstring")
};
getMethod.setQueryString(parameters);
Post requests works the same way, just create a PostMethod and instead do a:
postMethod.setRequestBody(parameters);
Java 7 tidbits
February 26th, 2008
Yesterday I spent some time listening to the presentation Chet Haase on Java FX, Update N and JDK 7. This contains quite a lot of promises, promising promises and tentative promises. It left me rather excited at the future (and current position) of Java.
Chet Haase is, in his own words, … [spending] most of his time working on graphics and performance issues and futures.
for Sun.
Java Resources
February 1st, 2008
A couple of my co-workers attending Heinz Kabutz’ Java course in Oslo this week. After they came back, talk drifted in on resources for a minute. Parsing my feeds (Google Reader, hint, hint) brought forth Kabutz’ newsletter and Sun’s Core Java tech tips. Other sources mentioned were Java examples by topic and Resources for Java server-side developers. Thanks Arve.
I’m currently dabbling in making small utils for myself… on my phone. The resources I’ve found for programming with Java ME are Sony Ericsson’s Developer World, Sun’s Wireless Toolkit, the Eclipse J2ME Plugin, Sun’s wireless tutorial paths and data storage tutorial. As all my other private projects, this will most likely suffer from fleeting motivation syndrome.
No promises though
Generating Class-Path in Jar Manifest with Ant
August 19th, 2007
I’ve recently started to touch Ant. Well, I’ve used it before, but only on the ant clean all
level. Now I wanted to write a small build script for a tiny project. Which went off easily enough with the help of Apache Ant User Manual. Well, until I wanted to deploy to a executable Jar file.
This didn’t look like it was easily done. Googling around I found that this had been answered before, by Dominique Devienne. I’ll summarize below:
Read the rest of this entry »

