{"id":2218,"date":"2010-02-08T10:44:56","date_gmt":"2010-02-08T09:44:56","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=2218"},"modified":"2010-02-08T10:44:56","modified_gmt":"2010-02-08T09:44:56","slug":"fun-with-javafx-on-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=2218","title":{"rendered":"Fun with JavaFX on Ubuntu Linux"},"content":{"rendered":"<p>A <a href=\"http:\/\/blog.crossedstreams.com\/\">friend of mine<\/a> got me interested in <a href=\"http:\/\/javafx.com\/\">JavaFX<\/a> recently and my interest grew when I discovered that it had some <a href=\"http:\/\/blogs.infosupport.com\/blogs\/paul_bakker\/archive\/2009\/07\/10\/javafx-charts.aspx\">nice charting functionality<\/a>.\u00a0 Dean Iverson has written <a href=\"http:\/\/pleasingsoftware.blogspot.com\/2009\/06\/this-is-test.html\">some great tutorials on the subject over at his blog<\/a> and includes a link to a demo showing some of the different plot types that are available.<\/p>\n<p>The demo is called ChartDemo and can be found here<\/p>\n<p><a href=\"http:\/\/pleasingsoftware.blogspot.com\/2009\/06\/this-is-test.html\">http:\/\/pleasingsoftware.blogspot.com\/2009\/06\/this-is-test.html<\/a><\/p>\n<p>In an ideal world you simply have to click on the demo&#8217;s screenshot for it to download and launch but that wasn&#8217;t what happened for me.\u00a0 What happened when I clicked on it was nothing.\u00a0 No error messages&#8230;just nothing.\u00a0 It&#8217;s difficult to google &#8216;nothing happened&#8217; and get something useful so I downloaded the demo (which had the filename ChartDemo.jnlp) and tried to launch it from the command line using<\/p>\n<pre>javaws ChartDemo.jnlp<\/pre>\n<p>This gave me the error message<\/p>\n<pre>netx: Unexpected net.sourceforge.jnlp.ParseException: Invalid XML document syntax. at\r\nnet.sourceforge.jnlp.Parser.getRootNode(Parser.java:1200)<\/pre>\n<p>What follows is the story of how I eventually got this demo to work in the hope that it will help someone out there.<\/p>\n<p>So, first things first, what are some of the relevant system specs I am using?\u00a0 Well, I am running 32bit Ubuntu Linux 9.10 (Karmic Koala) and<\/p>\n<pre>java -version<\/pre>\n<p>gives<\/p>\n<pre>java version \"1.6.0_0\"\r\nOpenJDK Runtime Environment (IcedTea6 1.6.1) (6b16-1.6.1-3ubuntu1)\r\nOpenJDK Server VM (build 14.0-b16, mixed mode)<\/pre>\n<p>Now, when I googled the error message I discovered that Linux (more specifically, I guess, the <a href=\"http:\/\/en.wikipedia.org\/wiki\/OpenJDK\">OpenJDK<\/a>) is much more sensitive to xml errors than Windows\/Mac OS X (.jnlp files are written in xml).\u00a0 Take double quotes for example; according to the <a href=\"http:\/\/www.w3.org\/TR\/REC-xml\/\">W3C XML recommendations<\/a> you should not use \\&#8221; inside an xml attribute but should use &#8220;&amp;quot;&#8221; instead.\u00a0 Some java implementations don&#8217;t seem to care but, at the time of writing at least, OpenJDK definitely does.\u00a0 <a href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=494302\">Follow this link <\/a>to see the original discussion thread where I learned this.<\/p>\n<p>The practical upshot of this extra level of strictness is that .jnlp files that work just fine on Windows and Mac OS X won&#8217;t work on Linux and I guessed that was what as happening here.\u00a0 Sadly there were no examples of \\&#8221; in ChartDemo.jnlp for me to change to &#8220;&amp;quot;&#8221; so there must be something else &#8216;wrong&#8217; with it; but what?<\/p>\n<p>I decided to try the &#8216;stare at it until you figure it out&#8217; approach to debugging and left the laptop on the side of the sofa while watching a movie on TV.\u00a0\u00a0 About halfway through the movie, inspiration struck and I changed the line<\/p>\n<pre>&lt;update check=\"background\"&gt;<\/pre>\n<p>to<\/p>\n<pre>&lt;update check=\"background\"\/&gt;<\/pre>\n<p>which got things past the xml parsing stage.  Sadly, I then hit another problem.  Rather than a working ChartDemo, my efforts were rewarded with nothing more than just a blank window and a load of java errors in the terminal.  When I say &#8216;a load&#8217; I mean HUNDREDS and none of them looked particularly illuminating.  I was starting to remember why I had avoided Java in the past but was not about to give up so easily.<\/p>\n<p>Let&#8217;s take stock:<\/p>\n<ul>\n<li>The .nlbp file was fine (or at least didn&#8217;t return any parse errors)<\/li>\n<li>The ChartDemo code must be bug free because if it wasn&#8217;t then the author would have been told so rather quickly in the comments section of his blog<\/li>\n<li>My Java setup was presumably fine since I was able to run other JavaFX examples.  For example I successfully worked through a <a href=\"http:\/\/javafx.com\/docs\/gettingstarted\/javafx\/create-first-javafx-app.jsp\">JavaFX programming tutorial<\/a> on Sun&#8217;s website without incident.<\/li>\n<\/ul>\n<p>Of those three points I figured that the third one was the most likely to be wrong.  It was OpenJDK&#8217;s handling of the .jnlp file that caused my first problem so maybe it was causing this second problem too.  Could I switch from using OpenJDK to a different version of Java I wondered?  Some googling ensued and I discovered some useful incantations.<\/p>\n<p>I can list the versions of Java installed on my machine with the command<\/p>\n<pre>sudo update-java-alternatives -l<\/pre>\n<p>to get<\/p>\n<pre>java-6-openjdk 1061 \/usr\/lib\/jvm\/java-6-openjdk\r\njava-6-sun 63 \/usr\/lib\/jvm\/java-6-sun<\/pre>\n<p>I can change from the openjdk to sun-java with<\/p>\n<pre>sudo update-java-alternatives -s java-6-sun<\/pre>\n<p>Once I did this I tried to run the ChartDemo.nlbp file again:<\/p>\n<pre>javaws ChartDemo.jnlp<\/pre>\n<p>and it worked perfectly.  I was rewarded with a very nice demo of JavaFX&#8217;s charting functionality and Dean&#8217;s tutorials proved to be very useful to me.  So useful in fact that I bought <a href=\"http:\/\/www.amazon.co.uk\/gp\/product\/1430218754?ie=UTF8&amp;tag=walkingrandom-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=1430218754\">his book<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"http:\/\/www.assoc-amazon.co.uk\/e\/ir?t=walkingrandom-21&amp;l=as2&amp;o=2&amp;a=1430218754\" border=\"0\" alt=\"\" width=\"1\" height=\"1\" \/>.<\/p>\n<p>Incidentially, the java-6-sun version of java doesn&#8217;t care about the syntax of the .jnlp file quite so much as openjdk.  However, if you want to change back to using openjdk you can do<\/p>\n<pre>sudo update-java-alternatives -s java-6-openjdk<\/pre>\n<p>I hope this little tale helps someone out there.  Let me know if it does and also feel free to let me know if I have got anything wrong.  My knowledge of all things Java is rather basic at the moment to say the least &#8211; something I am trying to change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A friend of mine got me interested in JavaFX recently and my interest grew when I discovered that it had some nice charting functionality.\u00a0 Dean Iverson has written some great tutorials on the subject over at his blog and includes a link to a demo showing some of the different plot types that are available. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14,7],"tags":[],"class_list":["post-2218","post","type-post","status-publish","format-standard","hentry","category-java","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-zM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2218"}],"version-history":[{"count":17,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2218\/revisions"}],"predecessor-version":[{"id":2322,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2218\/revisions\/2322"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}