DailyJS

Nodyn: No Dice

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

java node

Nodyn: No Dice

Posted by Alex R. Young on .
Featured

java node

Nodyn: No Dice

Posted by Alex R. Young on .

Nodyn (GitHub: projectodd / nodyn, License: Apache 2.0) is a Node API-compatible JVM-based project. That means you can technically use Java libraries from within Node programs.

I've been using it on my Mac, running Mavericks. Here's what I had to do to get it to work:

brew install maven  
git clone https://github.com/projectodd/nodyn.git  
cd nodyn  
export JAVA_HOME=`/usr/libexec/java_home`  
mvn install -Dmaven.test.skip=true  
cd nodyn-standalone/target  
java -jar nodyn-standalone.jar --console  

It took me a while to figure all of this out. I already had Homebrew installed, but I didn't have Maven. I'm an amateur Android developer, so I only ever really write Java through Google's recommended IDE tools.

Maven installed without too much trouble, except I found it used the wrong version of Java. The export JAVA_HOME line makes Maven use the right version. I'm not sure why this is required because java -version showed 1.7, but for some reason Maven was building Nodyn with 1.6, which generated a long and inscrutable error message.

The mvn install -Dmaven.test.skip=true line builds Nodyn, and skips tests. I wanted to skip the tests because they seemed to hang on this line:

Starting test: src/test/resources/os|os_test.js|testFreemem  

Once I built it, I ran a small program that reads its own source and prints it to stdout:

var fs = require('fs');

console.log('I can print my own code');

fs.readFile('test.js', 'utf8', function(err, text) {  
  if (err) console.error(err);
  console.log(text);
  console.log('When I work correctly');
});

This printed the following output, which is incorrect:

log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).  
log4j:WARN Please initialize the log4j system properly.  
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.  
I can print my own code  

The expected output is this:

I can print my own code  
var fs = require('fs');

console.log('I can print my own code');

fs.readFile('test.js', 'utf8', function(err, text) {  
  if (err) console.error(err);
  console.log(text);
  console.log('When I work correctly');
});

When I work correctly  

It seems like Node API compatibility isn't quite there yet. I also noticed it takes much longer than Node to start up, but I seem to remember jRuby developers complaining about startup time so that might be something to do with how Java works. It probably doesn't really matter for long-running server processes, but I quite like the fact Node programs start up quickly.

If you're a Java programmer Nodyn might seem cool, but so far I've struggled with it. Despite my Maven issues, the project looks neatly organised and carefully written, so I'm going to keep watching it.