Wednesday, April 16, 2008

Process for generating Netsuite java files, compiling stub classes, and creating jar file

UPDATE February 24, 2011: I recently learned as of ColdFusion 8 that you can set wsdl2java command line parameters when calling CreateObject to create a web service object. Complete details are in this post.

UPDATE March 8, 2009: Since this was first posted, I verified that the incomplete stub file compilation issue appears to be an issue in ColdFusion 8, as well. I haven't tested it, but I have no reason to believe that the jar file trick described below wouldn't work in 8.

If you've read other posts I've done about ColdFusion and Netsuite integration, you may recall that I solved an issue with MX7 refusing to compile all of the necessary stub files from the Netsuite WSDL by manually compiling them and creating a jar file. This used to be a huge hassle for me each time Netsuite released an upgrade. This time, however, it should be a ridiculously smooth process. I know the following steps will look intimidating if you are not familiar with Apache ANT or Apache Ivy, but trust me, they will make your life a lot easier.

Someone recently wrote me with some questions about this process, and I thought I would post this for everyone's benefit. Or at least I hope it's for your benefit and not your additional confusion. *grin*

Oh, and a couple of notes. I have not done any development in ColdFusion 8, so some of the steps and issues below may not apply. In fact, this entire process may not be necessary at all for all I know. Also I'm quite green when it comes to ANT and Ivy, so as with everything else I post here, if there is a more efficient way to any of these steps, I'd love to hear from you.

Assumptions for this process (modify as necessary for your environment):

  • [Netsuite WSDL version] = 2_6_0
  • [CF install path] = C:\CFusionMX7
  • You are using ColdFusion MX 7 (Notes for ColdFusion 8 will be given where necessary)
  • [java install path] = C:\j2sdk1.4.2_12
  • [major java version that your CF installation uses] = 1.4
  • [stub class target] = C:\netsuiteclasses\2_6_0
  • [Apache Axis version] = 1.2.1

Prerequisites:

  • You have Apache ANT 1.7.0 or higher installed and have all environment variables set per its installation documentation. (Download binaries and see documentation at http://ant.apache.org/)
  • You have Apache Ivy 2.0.0 beta 2 or higher installed and have all environment variables set per its installation documentation. (Download binaries and see documentation at http://ant.apache.org/ivy/)
  • A version of the java jdk compatible with the java runtime version of your ColdFusion installation.
  • NOTE: This item is only for ColdFusion MX7 and likely does not apply to ColdFusion 8. A modified version of the Apache Axis 1.2 jar file (axis.jar) (distributed by Netsuite to fix a login issue caused by how cookies are passed by Axis in the HTTP header) was copied into [CF install path]\lib, and the ColdFusion server was restarted afterward.

Generate and Compile Process:

1. Generate java class source code (windows dos window).

[java install path]\bin\java -cp [CF install path]\runtime\lib\wsdl2java.jar org.apache.axis.wsdl.WSDL2Java -v -O 120 -a -o [stub class target] https://webservices.netsuite.com/wsdl/[Netsuite WSDL version]/netsuite.wsdl

2. Create Apache ANT build file.

Create a file named build.xml in [stub class target] with the following contents (pay attention to bracketed areas that you will need to modify accordingly):

<?xml version="1.0" encoding="UTF-8"?>
<project name="netsuite_[Netsuite WSDL Version]" default="init" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<description>
Build file for Netsuite [Netsuite WSDL Version] WSDL.
</description>
<property name="classes.dir" location="classes" />
<property name="dist.dir" location="dist" />
<property name="dist.jarfile" value="netsuite_[Netsuite WSDL Version].jar" />

<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve pattern="${lib.dir}/[type]/[artifact]-[revision].[ext]" conf="runtime"/>
</target>

<target name="clean" description="Clean up output directories.">
<delete dir="${classes.dir}" />
</target>

<target name="compile" depends="-init" description="Compile all sources.">
<mkdir dir="${classes.dir}" />
<javac srcdir="." destdir="${classes.dir}" debug="true" deprecation="true">
<compilerarg line="-source [major java version that your CF installation uses]" /> <!—NOTE: The “-source” option may not be necessary for CF8 -->
<compilerarg line="-classpath [CF install path]\lib\axis.jar; [CF install path]\lib\jaxrpc.jar" />
</javac>
</target>

<target name="rebuild" depends="clean,compile" description="Cleanly compiles all sources." />

<target name="-init">
<!-- Create the time stamp. -->
<tstamp>
<format property="TODAY_US" pattern="dd MMM yyyy HH.mm" locale="en_US" />
</tstamp>
</target>

<target name="dist" depends="rebuild" description="Creates the binary distribution.">
<mkdir dir="${dist.dir}/${TODAY_US}" />
<jar basedir="${classes.dir}" destfile="${dist.dir}/${TODAY_US}/${dist.jarfile}" />
</target>

</project>

3. Create Apache Ivy config file.

Create a file named ivy.xml in [stub class target] with the following contents (pay attention to bracketed areas that you will need to modify accordingly):

<ivy-module version="2.0">
<info organisation="apache" module="hello-ivy"/>
<dependencies>
<dependency org="apache" name="axis" rev="[Apache Axis version]"/>
</dependencies>
</ivy-module>

4. Compile files and generate jar file.

Open a Command Prompt window and change directories to your [stub class target] directory and run the following command:

ant dist

You may see multiple warning messages throughout the compile process, but as long as you see a BUILD SUCCESSFUL message upon completion, there shouldn’t be any problems. Copy the generated jar file (the output of the ant command should indicate the filename and location of the jar file) to [CF install path]\lib and restart your ColdFusion Application Server service.

No comments: