Anyone that has ever tried to use Applet-based embedded device managers (just how many times a day does my office-mate curse Bluecoat?!!) knows that the "write once, run anywhere" credo of Java is not all its cracked up to be. But it does work sometimes. And distributing a [cross-platform] stack of apps that only depends on a JVM has its advantages on having to satisfy OS package dependencies and/or scripting language dependencies (ala GEMs or Python eggs)
To that end I've built a self-contained package for playing around with JXTA that not only includes the necessary .jar's for JXTA 2.4.1 (or at least for what I've been doing so far) but also includes the latest version (1.0.0RC) of JRuby. This a good companion to the JXTA Programmer Guide which I've been going through today.
Hopefully this makes it a little easier for folks to play around with this Open Source P2P API. As bloated and complex (and probably overkill for the mysterious new security project I have in mind) as JXTA is, it was far better documented than some of the alternatives such as or P2PS and there seem to be a lot more applications out there using JXTA.
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Saturday, June 09, 2007
Hello JXTA (JRuby Style)
So the original Java version was 42 lines
hello is a short wrapper shellscript to set the classpath to:
$HOME/java/jxta.jar:$HOME/java/bcprov-jdk14.jar:$HOME/java/jxtaext.jar:$HOME/java/log4j.jar
and ran jruby jxtahello.rb
which is
And when executed prints pretty much the same:
This probably the shortest JXTA code shows the real power of JRuby in prototyping and learning JAVA APIs.
BTW, all the JXTA examples are up at http://www.threatmind.net/jxta
hello is a short wrapper shellscript to set the classpath to:
$HOME/java/jxta.jar:$HOME/java/bcprov-jdk14.jar:$HOME/java/jxtaext.jar:$HOME/java/log4j.jar
and ran jruby jxtahello.rb
which is
require 'java'
include_class "net.jxta.peergroup.PeerGroup"
include_class "net.jxta.peergroup.PeerGroupFactory"
include_class "net.jxta.exception.PeerGroupException"
npg = PeerGroupFactory.newNetPeerGroup()
puts "Hello from JXTA group " + npg.getPeerGroupName().to_s
puts " Group ID = " + npg.getPeerGroupID().to_s
puts " Peer name = " + npg.getPeerName().to_s
puts " Peer ID = " + npg.getPeerID().to_s
npg.stopApp()
And when executed prints pretty much the same:
franz-g4:~/Desktop/jxta/ruby mdfranz$ ./hello
INFO 2007-06-09 15:49:55,134 NullConfigurator:::132 JXTA_HOME = file:/Users/mdfranz/Desktop/jxta/ruby/.jxta/
INFO 2007-06-09 15:49:55,305 NullConfigurator::adjustLog4JPriority:316 Log4J [user default] requested, not adjusting logging priority
INFO 2007-06-09 15:49:56,681 NullConfigurator::adjustLog4JPriority:316 Log4J [user default] requested, not adjusting logging priority
Hello from JXTA group NetPeerGroup
Group ID = urn:jxta:jxta-NetGroup
Peer name = bobo
Peer ID = urn:jxta:uuid-59616261646162614A7874615032503399A33A2EB7BB47E5BA108F6B6D2BDF3203
This probably the shortest JXTA code shows the real power of JRuby in prototyping and learning JAVA APIs.
BTW, all the JXTA examples are up at http://www.threatmind.net/jxta
Hello JXTA

So I downloaded Netbeans 6.0 Milestone 9 this morning and after briefly playing around with it is new Ruby project capabilities (quite nice) I finally got a JXTA 2.4.1 Hello World app built and running. I'll probably document this better, but the main thing was getting the right libraries (.jar's) added to the Netbeans project:
- jxta.jar jxtaext.jar
- log4j.jar
- bcprov-jdk14.jar
franz-macbook:~/dist mdfranz$ java -jar JxtaSample.jar
Starting JXTA .... INFO 2007-06-09 11:27:52,358 NullConfigurator::
Hello from JXTA group
NetPeerGroup Group ID = urn:jxta:jxta-NetGroup Peer name = moonface Peer ID = urn:jxta:uuid-59616261646162614A787461503250334C06A0908D664660BDEFCD8DF2E958E603 Good Bye ....
Subscribe to:
Posts (Atom)
