[SOLVED] How to Fix JasperReport Server and iReports in OS X Mavericks

So I am evaluating using JasperServer for an upcoming project. As a result I have a Jasper development environment setup on my MacBook Pro which includes JasperReports Server and Jasper iReports.

Recently I upgraded to OS X Mavericks and everything Jasper came crashing down. After further investigation I discovered a few things:

  1.  Mavericks actually didn’t come with a version of JDK, and in fact removed the version was installed on my Mac.
  2. As a result, $JAVA_HOME appeared to be non-existent
  3. Also, after getting Java installed again the default path bin/java has changed to Commands/java

So, to get things working again I did the following:

Install Java

Go here to download the latest release of java.

 

Upgrade and Reinstall JasperServer

My existing copy of JasperServer would still not run so I upgraded to the latest release (v5.5 at the time of this writing).

Download the latest Jasper here

Note:  In hindsight I’m assuming that this because of the $JAVA_HOME issues and the installer setting paths in configuration files. (Therefore, you may not need to upgrade.  You might be able to simply re-install the existing version. If so, let me know in the comments.)

Once you do this, JasperServer should run again.

Test Java

Check that java is installed

open terminal and type

java -v

You should see your java version number…

To Check your $JAVA_HOME

Open terminal and type:

echo $JAVA_HOME

If you see an empty line then follow steps in Part B, else if you see a path like this:

/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

then congratulations – continue on to the next step.

Part B) Manually Set Your Java_Home (Only if the last steps didn’t work)

So if you tried to set your JAVA_HOME  on your mac but it didn’t work then try doing the following which was originally written about here:

  1. Start up Terminal
  2. Type “cd ~/” to go to your home folder
  3. Type “touch .bash_profile” to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type “open -e .bash_profile” to open it in TextEdit.
  5. Type “. .bash_profile” to reload .bash_profile and update any functions you add.

Now test your JAVA_HOME again – Open terminal and type:

echo $JAVA_HOME

Finally, Tell iReport where Java is in Mavericks

  • Right click on the iReport.app (in Applications)
  • Show Package Contents
  • Navigate to /Contents/Resouces/ireport/etc
  • Edit iReport.conf with your favorite text editor
  • Add a line that says something like
  • jdkhome=“/path/to/javahome”

Where “jdkhome” should match the path that appears when you type “echo $JAVA_HOME” in terminal  For example, mine is:

jdkhome="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"

Finally…

Save the file and try running iReport again.  Your problems should be solved.

Let me know on Twitter or in the comments if this helped you!

Easily Parse XML

How to Easily Parse XML

XML is used a lot on the internet and in business .  For instance, it is used by Blogs in a format called Real Simple Syndication, or RSS , to allow people to read a blog without actually visiting the blog’s website.  XML is also used to store reference information in web services and configuration files on many open and closed source products such as Instant Messager servers , web servers , and Oracle’s SQL Developer .

Since XML has become so popular in recent years, there are tools for most languages that make XML pretty easy to parse and handle.

Here are 2 tools you can use to parse XML:

1)  MagpieRSS for PHP

MagpieRSS is a great way to parse almost any format of XML clearly and concisely.  Simply include the file "rss_fetch.inc" and then access the entire XML feed as an array.

From their example page:

<item rdf:about="http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257">
<title>Weekly Peace Vigil</title>
<link>http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257</link>
<description>Wear a white ribbon</description>
<dc:subject>Peace</dc:subject>
<ev:startdate>2002-06-01T11:00:00</ev:startdate>
<ev:location>Northampton, MA</ev:location>
<ev:enddate>2002-06-01T12:00:00</ev:enddate>
<ev:type>Protest</ev:type>
</item>

Get's parsed to:

array(
title => 'Weekly Peace Vigil',
link => 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257',
description => 'Wear a white ribbon',
dc => array (
subject => 'Peace'
),
ev => array (
startdate => '2002-06-01T11:00:00',
enddate => '2002-06-01T12:00:00',
type => 'Protest',
location => 'Northampton, MA'
)
);

2) RSSutils Jar and Tag Library for Java

First, download and unpack RSSutils from here
.  Next copy 
rssutils.jar

and rsstaglib.tld
into your 
/WEB-INF/lib
directory.  Then add the following to web.xml
:


    <taglib>
<taglib-uri>/WEB-INF/lib/rssutils.tld</taglib-uri>
<taglib-location>/WEB-INF/lib/rssutils.tld</taglib-location>
</taglib>

Now you can reference the tag library in your JSP page similar to the following example:

    <%@ taglib uri="/WEB-INF/lib/rssutils.tld" prefix="rss" %>

<rss:feed
url="http://url/to/xml.xml" feedId="xmlFeed"/>
<b>Image: </b><rss:channelImage feedId="xmlFeed"/><br>
<b>Title: </b><rss:channelTitle feedId="xmlFeed"/><br>
<b>Link: </b><rss:channelLink feedId="xmlFeed" asLink="true"/><br>
<b>Description: </b><rss:channelDescription feedId="xmlFeed"/><br>
<ul>
<rss:forEachItem feedId="xmlFeed">
<li><rss:itemDescription feedId="xmlFeed"/><br><br>
</rss:forEachItem>
</ul>


Make sure you come up with a unique feedId
to use throughout the page, especially if you are going to be parsing multiple feeds on a single page.  Read a much longer rssutils tutorial here
.

Call Web Service in Java

Consume a Web Service with Java

As I stated before, calling a web service in .Net is easy .  However, using a Java Web Service is a little more difficult .  This is not because .Net is superior to Java, but instead because of the various standards that Java allows for since it is open sourced.  In other words, Java can be extended and new standards can be developed, whereas Microsoft keeps tight control over their beloved .Net framework.

Step 1:  Download and Install NetBeans

First you must download and Java IDE such as Netbeans , Eclipse , or Oracle’s JDeveloper .  I have used all three and I would recommend NetBeans because I found that JDeveloper was a little behind on certian standards and Eclipse requires that you install additional plugins to allow you to develop with web services.  However, the latest version of NetBeans (6.5 as of this writing) comes with everything you need to develop and consume web services, including a choice of embedded web servers for development.

Step 2: Create a Web Project and Web Service Client

Next, create a new Web Project by clicking File > New and selecting Web Project from the list.

Once it builds your project, you must tell NetBeans what type of project you are developing.  You can do this by right clicking your newly created Project in the Projects pane and selecting New > Web Service Client .  If I remember correctly, this is where a wizard will prompt you for the Web Service WSDL that you are wanting to call .

WSDL stands for Web Service Definition Language and is a document that is generated when you build a web service to tell the applications that want to use it what methods are available to use.

Step 3: Call Web Service

Once your project finishes generating the local methods for calling the external web service, you should see a tree option under your project entitled Source Packages . Open this tree item and all items below it and you should see a Java file "*.java" .  Double click this so it opens, then right click > Web Service Client Resources > Call Web Service Operation .

Step 4: Modify and Test

Once the generation is completed, you should be able to reference the web service objects similar to the following:

WsNameOfService port =   service.getWsNameOfServicePort();
boolean tf;
tf = port.isReady();

out.println("Result: " + tf);

Enjoy and Good Luck!

Note: If your not getting the same menu items as me then you probably created the wrong project type in the first couple of steps.  For instance, NetBeans may not allow you to create a Web Service Client in a regular Java project.  Start over with a new project and ensure you are selecting the correct project types.