The Netbeans Python Debugger

As mentioned previously, the Netbeans IDE also includes a Python debugger that is derived from JeanYves Mengant's jpydbg debugger. This section will discuss how to make use of the Netbeans Python debugger along with some examples using our HockeyRoster code that was written in the previous section. If you have used a debugger in another IDE, or perhaps the Java debugger that is available for Netbeans, this debugger will feel quite familiar. The Python debugger includes many features such as...

Deploying a Single JAR

In order to deploy an application to the Java Warehouse, it must be packaged as a single JAR file. We've already discussed packaging Jython applications into a JAR file using the Jython standalone method in Chapter 13. In this section, you will learn how to make use of the One-JAR http one-jar.sourceforge.net product to distribute client-based Jython applications. In order to get started, you will need to grab a copy of One-JAR. There are a few options available on the download site, but for...

Parsing Feeds

Parsing feeds is easy with ROME. Using ROME with Jython makes it even easier with the elegant Jython syntax. We took the FeedReader example from the ROME site and translated it into Jython see the following . You can copy and paste the code into your own FeedReader.py module and run it to parse feeds. However, the output is unformatted and ugly. Creating a good looking frontend is up to you. Listing B-8. This module can be used to parse an RSS feed from java.net import URL from java.io import...

Writing Ant Tasks with Jython Ed Takema

Ant is the current tool of choice for Java builds. This is so partially because it was the first Java-oriented build tool on the scene and because the reigning champion Make was getting long in the tooth and had fallen out of favor with the Java crowd. But Java builds are getting more and more difficult, and these days there is general dissatisfaction with Ant. Note particularly Bruce Eckel's comments and Martin Fowler's further comments. The comments to Bruce Eckel's posting show similar...

Connections

A database connection is simply a resource object that manages access to the database system. Because database resources are generally expensive objects to allocate, and can be readily exhausted, it is important to close them as soon as you're finished using them. There are two ways to create database connections Direct creation. Standalone code, such as a script, will directly create a connection. JNDI. Code managed by a container should use JNDI for connection creation. Such containers...

Running a Modjy Application in Glassfish

To run a modjy application in any Java servlet container, the first step is to create a Java web application that will be packaged up as a WAR file. You can create an application from scratch or use an IDE such as Netbeans 6.7 to assist. Once you've created your web application, ensure that jython.jar resides in the CLASSPATH as modjy is now part of Jython as of 2.5.0. Lastly, you will need to configure the modjy servlet within the application deployment descriptor web.xml . In this example, we...

Virtualenv

Often, it is nice to have separate versions of tools running on the same machine. The virtualenv tool provides a way to create a virtual Python environment that can be used for various purposes including installation of different package versions. Virtual environments can also be nice for those who do not have administrative access for a particular Python installation but still need to have the ability to install packages to it such is often the case when working with domain hosts. Whatever the...

Read an Excel File

This Jython code will open and read an existing Excel file. Read an existing Excel file Book1.xls and show it on the screen from org.apache.poi.hssf.usermodel import from java.io import FilelnputStream Open an existing file and use HSSFWorkbook object to store it file H Book1.xls fis FilelnputStream file wb HSSFWorkbook fis Obtain reference to the first sheet in the workbook sheet wb.getSheetAt o rows sheet.getPhysicalNumberOfRows print wb, sheet, rows This trick ensures that we obtain the data...

An Interlude into Javas Memory Model

A note about reloading sometimes if you're doing development with Pylons on Jython, Java will throw an OutOfMemory error like this java.lang.OutOfMemoryError PermGen space at Method at Java keeps track of class definitions in something called the Permanent Generation heap space. This is a problem for Pylons when the HTTP threads are restarted and your classes are reloaded. The old class definitions don't go away they never get garbage collected. Because Jython is dynamically creating Java...

Pylons MVC

Pylons, like Django and any reasonably sane webframework or GUI toolkit for that matter uses the model-view-controller design pattern. Table 15-1 shows what this maps to in Pylons. Table 15-1. Pylon MVC Design Pattern Mapping Table 15-1. Pylon MVC Design Pattern Mapping SQLAlchemy or any other database toolkit you prefer Mako or any templating language you prefer To reiterate, Pylons is about letting you, the application developer, decide on the particular tradeoffs you're willing to make. If...

Method

For brevity, I will not repeat the original Java code here. The following shows how I call the Jython class note that one can use either addFile or addURL depending on whether the Jar is on a locally accessible file system or remote server . from com.ziclix.python.sql import zxJDBC if called from command line with .login CLASSPATH setup right,this works db zxJDBC.connect d, u, p, v except if called from Apache or account where the .login has not set CLASSPATH need to use run-time CLASSPATH...

Using the CLASSPATH Steve Langer

During October and November of 2006, there was a thread in the Jython-users group called adding JARs to sys.path. More accurately, the objective was to add JARs to the sys.path at runtime. Several people asked the question, Why would you want to do that Well there are at least two good reasons. The first is if you want to distribute a Jython or Java package that includes non-standard Jars in it. Perhaps you want to make life easier for the target user and not demand that they know how to set...

Other Netbeans Python Features

There are a number of additional features in the Netbeans Python IDE support that we haven t touched upon yet. For instance, minimal refactoring support is available for any Python module. By right-clicking on the module in the project navigator or within a module, a bevy of additional options become available to you via the right-click menu. You ll see that there is a Refactoring option that becomes available. However at the time of this writing the only available refactoring options were...