Working
with VisualAge for Java Carol Jones Senior Technical Staff Member IBM September 1999
Introduction When you add dynamic content to your web applications, you are probably writing Java servlets, JavaBean classes, or Enterprise JavaBeans. This means you are probably using VisualAge for Java to do all the programming work, and you'd like to find a way to easily share the code with your Studio project. In this paper, we'll tell you about some of the special features that Studio has for working easily with VisualAge for Java. The remainder of this paper has the following sections:
Adding Java classes to Studio Projects If you already use VisualAge for Java, then you already know how it organizes your Java classes into projects. Let's suppose that you're using VisualAge to create a JavaBean class, which stores information about departments and people. Just for illustration, let's say it's the same class we used in one of the previous papers in this series, the one titled Using JavaBeans to Add Dynamic Elements to Web Pages. If you were using VisualAge to create the bean, it might look something like this: Once you have the bean written and tested, the next thing you want to do is add it to your Studio project. There are several ways to do this:
Let's look more closely at how the third option works. Once you have finished writing the class in VisualAge, you need to add it to your Studio project. The first step is to use the Insert File dialog, selecting the External Source tab. If you have VisualAge for Java installed, it will be displayed in the list on the left. Select it, and then click Browse to see what classes you can add: For this example, we select the Department class. You can add the compiled class, the Java source, or both to your project. Unless you plan on changing the source code in Studio (which is probably a bad idea!), you don't need the .java file. Later on, if someone updates the Java class, you can refresh the copy that you have in Studio by using Update from VisualAge option under the Project menu. If you want to move Java source code from Studio over to VisualAge (for example, the code that is generated by Studio's wizards), use the Send to VisualAge option, which is also under the Project menu. Debugging Java and Java Server Pages In WebSphere Application Server 3.0, a new Java and JSP debugger has been added. Once you have your server set up properly, it's easy to debug your code from Studio. All you need to do is select the Debug option under the Project menu or on the toolbar. Studio will show you a list of all the Java classes in your project, so it can prepare them for debugging. You can debug Java Server Pages files too. The next time you preview a JSP page or a page that causes one of your Java classes to run, the debugger window will open automatically. Here's what it looks like:
You can set breakpoints, watch the values of variables, and step through the lines of your
code.
If you are using VisualAge for Java to build Enterprise JavaBeans, there's a new feature that helps you use the EJB inside your Studio applications. Here's how it works: In your EJB Group, select Add->Adapter Bean from the popup menu. This will generate an ordinary bean, which acts as an interface for the EJB. Once you have this bean, you export the Client JAR file. Now, you can use the JavaBean wizard from Studio to build your pages and servlets that will run the EJB. Just add the Client JAR to your Studio project, then choose the adapter bean from the list in Studio. (You'll need to make sure that your Studio project is set for Version 3.0 of the Application Server for this to work.)
|