The Wayback Machine - https://web.archive.org/all/20050508000343/http://www.netbeans.org:80/kb/articles/ebay-sdk-api-calls-demo.html

Launching the eBay Java SDK API Calls Demo Sample Application from NetBeans 4.0

This is a follow up to the 23 Feb 2005 article, Using NetBeans to Develop with the eBay SDK for Java. As I continued to experiment with eBay's Java SDK, I found one sample application, the API Calls Demo, an invaluable resource for helping me learn the APIs. In this article, I show you how to create a NetBeans project that will will run and debug the API Calls Demo sample application.

Fast Track

If you're not interested in the details and just want to run the demo inside NetBeans, the complete project is provided for you below. Just following the instructions to download, extract, configure and run.


Setting Up Your Environment

This article assumes you have already followed the steps for setting up your environment outlined in Using NetBeans to Develop with the eBay SDK for Java.

Creating the eBay API Calls Demo Project

  1. Choose File > New Project (Ctrl+Shift-N).
  2. Select Java Project with Existing Ant Script under the General Category. This will create what's known as a Free-Form Project in NetBeans. To learn more about this project type, see Advanced Free-Form Project Configuration.
  3. For the Location, browse to the samples/apiCallsDemo folder where you installed the eBay SDK. The wizard will locate the build script and recommend a Project Name. Select Next.
  4. Set the Build Project target to compile. The wizard located the Clean, Javadoc and run targets. Select next.
  5. Add the application's source package folder, which is simply src. If you've correctly configured NetBeans to start with the –jdkhome argument, the Source Level will say JDK 1.4.
  6. Add the eBay SDK JARs to the project's classpath:
    1. choose Add JAR/Folder
    2. Select all the JAR files in the <eBay SDK Install Location>/lib/ directory. These should be attributes.jar, ebaycalls,jar, ebaysdkcore.jar, eps.jar and helper.jar.
    3. Choose Add JAR/Folder again
    4. Select axis.jar from the <eBay SDK Install Location>/externalLib/axis-1_1/ directory.
  7. Click Finish.

Building and Running the Application

Building the Application

Select Build > Build Main Project, press F11, or right-click the project node and choose Build Project from the context menu.

Running the Application

Select Run > Run Main Project, press F6, or right-click the project node and choose Run Project from the context menu.

The project runs, however, you have to configure your account information every time you run the application, which can be quite tedious.





Let's fix that.


Enhancing the API Calls Demo Application

Create a Properties File to Hold Our Account Configuration Information

  1. Select File > new File, press Ctrl + N, or right-click the project node and choose New > File/Folder...
  2. Select Properties File from the Other Category and select Next.
  3. Name the file keys and select Finish.
  4. The key.prorties file opens in the editor. Add the following properties:
        devId = <enter you developer ID>
        appId = <enter your application ID>
        certId = <enter your certificate ID>
        token = <enter your token>
        apiServerUrl = https://api.sandbox.ebay.com/wsapi
        epsServerUrl = http://msa-e1.ebay.com/ws/eBayISAPI.dll?EpsBasicApp
                    

Read the Properties from the Application

  1. Open FrameDemo.java
  2. In the constructor, all the following code following the line:
        ApiCredential cred = new
        ApiCredential();
    
        // Read properties file to load
        developer credentials Properties keys = new Properties();
        try {
            keys.load(new FileInputStream("keys.properties"));
        } catch (IOException e) {
            System.out.println(e);
        }
    
        cred.seteBayToken(keys.getProperty("token"));
        ApiAccount ac = cred.getApiAccount();
        ac.setDeveloper(keys.getProperty("devId"));
        ac.setApplication(keys.getProperty("appId"));
        ac.setCertificate(keys.getProperty("certId"));
                    
  3. Press Alt + Shift + F to fix the missing imports.
  4. Replace the hard-coded strings for API and EPS Server URLs with the following:
        this.apiContext.setApiServerUrl(keys.getProperty("apiServerUrl"));
        this.apiContext.setEpsServerUrl(keys.getProperty("epsServerUrl"));
                    

Build and Run the Application Again

Press F11 to build the application and F6 to run it. The API Account dialog is now properly configured. Select and API from the list box, such as GetSearchResults and press Run.


Debugging the Application

Add a debug target to build.xml

  1. Open build.xml
  2. Scroll to the bottom of the file and add the following target:
    <target name="debug" depends="compile" description="Debug Project">
        <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
        <nbjpdastart name="Sample App" addressproperty="jpda.address" transport="dt_socket">
            <classpath refid="project.class.path"/>
            <sourcepath path="${src}"/>
        </nbjpdastart>
        <java fork="true" classname="apicallsdemo.ApiCallsDemo">
            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xnoagent"/>
            <jvmarg value="-Djava.compiler=none"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
            <classpath refid="project.class.path"/>
        </java>
    </target>
            

Map the Target

Open the Project Properties and select Build and Run. Set the Debug Project to the new debug target we just added.

Set a breakpint and Debug the Application

  1. Click on the left margin on the FrameDemo.java to set a breakpoint.
  2. Right-client the consoleViewItem project and choose Debug Project.
  3. From here you can step though your application, viewing locale variables, setting watches, etc. See Debugging Applications for more information.

Fast Track

Follow these steps to quickly get the API Calls Demo up and running in NetBeans 4.0. Note, your environment must be set up as documented in Using NetBeans to Develop with the eBay SDK for Java.

  1. Download and extract this apiCallsDemo.zip to the samples directory of your eBay SDK for Java.
  2. Start NetBeans 4.0 and browse to the samples directory of the eBay SDK for Java. The IDE will recognize the apiCallsDemo as a NetBeans project.
  3. Select apiCallsDemo and Open Project Folder
  4. Switch to the Files tab and open the keys.properties file. Set your credentials in the keys.properties file.
  5. Press F11 to build the project.
  6. Press F6 to run the project or F5 to debug the project.

You may find it interesting to note how small an impact NetBeans has on the existing project. Looking at the apiCallsDemo.zip file, only 4 files were affected by this exercise, and only 1 is related to NetBeans:

  • project.xml (in the nbproject subfolder) – the NetBeans specific file. Delete this folder and you have your original apiCallsDemo, albeit improved to read our credentials from the properties file.
  • keys.properties – added to enhance the project
  • FrameDemo.java – modified to read the keys.properties
  • build.xml – modified to include a debug target.