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.
The wizard
located the Compile, 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.
Click Next.
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 and update with your eBay credentials:
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 first line provided:
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.
Note, if you are behind a corporate proxy and get a ConnectException, you can add the following two lines of code to the top of FrameDemo constructor:
Download
and extract this apiCallsDemo.zip to the samples directory of your
eBay SDK for Java.
Start NetBeans 4.1 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