Starting in 1996, Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the Wayback Machine after an embargo period.
Launching the eBay Java SDK API Calls Demo Sample Application from NetBeans 4.0
Contributed and maintained by
, 09 Mar 2005
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.
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.
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.
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.
Set the Build Project target to
compile. The wizard
located the Clean, Javadoc and run targets. Select next.
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.
Add the eBay SDK JARs to the
project's classpath:
choose Add JAR/Folder
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.
Choose Add JAR/Folder again
Select axis.jar from the <eBay
SDK Install Location>/externalLib/axis-1_1/ directory.
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
Select File > new File, press
Ctrl + N, or right-click the project node and choose New >
File/Folder...
Select Properties File from the
Other Category and select Next.
Name the file keys
and select Finish.
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
Open FrameDemo.java
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"));
Press Alt + Shift + F to fix the
missing imports.
Replace the hard-coded strings for
API and EPS Server URLs with the following:
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
Open build.xml
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
Click on the left margin on the
FrameDemo.java to set a
breakpoint.
Right-client the consoleViewItem
project and choose Debug Project.
From here you can step though your
application, viewing locale variables, setting watches, etc. See
Debugging
Applications for more information.
Download
and extract this apiCallsDemo.zip to the samples directory of your
eBay SDK for Java.
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.
Select apiCallsDemo and Open
Project Folder
Switch to the Files tab and open
the keys.properties file. Set your credentials in the
keys.properties file.
Press F11 to build the project.
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