Java platform for dummies (or at least Lispers)

14 views
Skip to first unread message

Zak Wilson

unread,
Jun 14, 2008, 3:45:40 PM6/14/08
to Clojure
I've been a Lisp (mostly CL, but I've used Scheme and Arc a bit) user
for quite a while. Clojure as a language has been pretty easy for me
to pick up, but I've never done anything non-trivial with Java or any
language on the JVM. The Java platform is huge and popular - there's
so much information out there, but most of it is less than concise and
I'm a bit lost trying to figure out how to get things done.

Is there a concise, central source for figuring out how to get things
done on the JVM? Right now, I'm having trouble using serial ports and
figuring out how best to package a program for distribution to end
users, but I'm sure I'll have a bunch more questions that should be
easy to find answers to if I only knew where I should look.

Raoul Duke

unread,
Jun 14, 2008, 4:16:47 PM6/14/08
to clo...@googlegroups.com
> Is there a concise, central source for figuring out how to get things
> done on the JVM? Right now, I'm having trouble using serial ports and
> figuring out how best to package a program for distribution to end
> users, but I'm sure I'll have a bunch more questions that should be
> easy to find answers to if I only knew where I should look.

sometimes the official Sun tutorials ("trail"s) are useful, at least
for getting the basic gist of things. I don't know about serial ports,
that might be generally beyond the ken of regular Java, and might get
into JNI (calling native code) stuff. as far as packaging for others
to be able to consume, the usual thing is a .jar file, or if it is
going to a web server for public deployment as a web application a
.war file.

sincerely.

Dustin Withers

unread,
Jun 14, 2008, 9:28:19 PM6/14/08
to Clojure
I've been playing around with serial ports myself. I've had luck with
RXTX (http://users.frii.com/jarvi/rxtx/). Check out the wiki for
instructions on how to install. The wiki has instructions for how to
install on Windows, OS X, and Linux. Seems to work for my OS X
machine.

Hope that helps,
-dustin

Zak Wilson

unread,
Jun 14, 2008, 10:05:21 PM6/14/08
to Clojure
Ubuntu has a package for RXTX, but after installing, (import
'(javax.comm CommPortIdentifier)) still fails with a
ClassNotFoundException. I'm not sure if there's something I need to do
after installing the .deb, or if I should just not use the .deb and
install it manually.

Raoul Duke

unread,
Jun 14, 2008, 11:35:10 PM6/14/08
to clo...@googlegroups.com
Sorry if this is already understood, but in case - You may or may not
have come across the "classpath" idea that Java uses - if not, it is
basically yet another kind of lookup path (like, there's PATH,
LD_LIBRARY_PATH, etc.) but specifically for Java to find classes. It
is useful for both compiling & running things. If you have stuff which
compiles OK but then you get a runtime "not found", it could be that
the runtime classpath isn't set to include the desired classes.

To print out the classpath for debugging you can use code like (in
Java, not Clojure syntax)

System.out.println( getProperty("java.class.path") );

Assuming there is e.g. "rxtx.jar" somewhere, like "/foo/bar/rxtx.jar"
then you'd run Java like (assuming Main.java -> Main.class are your
entry point)

java -cp /foo/bar/rxtx.jar:$CLASSPATH Main

But of course it is never that simple, any example I give is 99.9%
likely to not be verbatim what would really work for you. In
particular, it depends on what OS you are using so the path separator
on Windows is i think semi-colon whereas it is colon on Unix.

Raoul Duke

unread,
Jun 14, 2008, 11:36:14 PM6/14/08
to clo...@googlegroups.com
follow up to classpath message: so if you use dpkg or whatever to list
all the files installed by the RXTX package, you should see something
like rxtx.jar somewhere, and that is what you'd need to get included
in your classpath.

Zak Wilson

unread,
Jun 15, 2008, 4:04:20 AM6/15/08
to Clojure
The .deb drops it in /usr/share/java/ which seems like the sort of
place that would be in the default classpath. According to the
documentation on the wiki Dustin linked, the jar should go in /usr/lib/
jvm/java-6-sun-1.6.0.06/jre/lib/ext/. Putting it there makes it
available by default. (. System (getProperty "java.class.path")) only
includes clojure.jar, but the gnu.io package from RXTX is available
now. There's clearly something still missing in my understanding here,
but my immediate problem is solved. Thanks for the help, guys.

Josip Gracin

unread,
Jun 15, 2008, 4:58:54 AM6/15/08
to Clojure
Hi Zak!

On Jun 15, 10:04 am, Zak Wilson <zak.wil...@gmail.com> wrote:
> The .deb drops it in /usr/share/java/ which seems like the sort of
> place that would be in the default classpath.

When JVM starts, it needs to be told explicitly where to look
for .class files. It can look in .jar files or in directories. Note
the subtle distinction: you're telling JVM where to look for .class
files, NOT .jar files. WRT to finding .class files, jar files are the
same thing as directories. If you put a directory in the CLASSPATH,
JVM will search for class definitions in that directory but not in
the .jar files in that directory.

For example, if you have a directory with the following content:

mylibs/
mylibs/org/apache/SomeClass.class
mylibs/serial.jar

and you put directory mylibs in your classpath, then when the JVM
looks for class org/apache/SomeClass, it will find it because mylibs
is in the classpath, and relative to it file org/apache/
SomeClass.class can be found. On the other hand, *nothing* from the
serial.jar is visible. To be able to find classes from serial.jar,
you need to add serial.jar to the classpath the same way you added
directoy mylibs. Therefore, your CLASSPATH will need to look
something like: 'mylibs:mylibs/serial.jar' (colon is a separator).

I hope this makes it clear why putting a directory full of .jar files
into your classpath does not make the classes within those .jar files
available. You need to put all the jar files explicitely. Nobody
puts all the files from /usr/share/java in their classpath. That's
just a repository of available stuff, and applications decide which
ones to use.

To actually set the classpath, you can use either '-cp' option when
you start JVM or CLASSPATH environment variable.

> According to the
> documentation on the wiki Dustin linked, the jar should go in /usr/lib/
> jvm/java-6-sun-1.6.0.06/jre/lib/ext/.

The JVM itself has some jar files which constitute the base of the
system, and those jar files are in directory such as the one you
mention above. It is definitely not the place in which you're
expected to put your stuff.

Hope this helps.
Reply all
Reply to author
Forward
0 new messages