Friday, July 11, 2008

Eclipse 3.4 - New Features

Here are descriptions of some of the more interesting or significant changes made to the Java development tools for the 3.4 release of Eclipse.

Java Editor Breadcrumb
The Java editor now offers a breadcrumb which shows the path to the element at the cursor position. The breadcrumb can be enabled via the Toggle Breadcrumb tool bar button or by pressing Alt+Shift+B. Each element in the breadcrumb can be selected and actions can be invoked through a context menu or keyboard short cuts.Furthermore the breadcrumb lets you navigate to other elements via drop-downs.

Rich Javadoc Hover
The Javadoc hover can now be used to navigate Javadoc.
Follow links in Javadoc
Go forward and backward in the navigation history
Show the current content in the Javadoc view
Open the declaration of the current element
Open the current content in an external browser
Resize the hover
Move the hover (start dragging in the toolbar area)

Rich Java problem hover
The problem hover now offers all available quick fixes for a problem and shows a tool bar on F2 or when you move the mouse into it. Quick fixes can be executed by clicking on the links. The actions in the tool bar let you configure the annotation preferences and the problem severity.

Content assist improvements
Content Assist (Ctrl+Space) has been improved in several areas.
Content assist can now use the type of the enclosing instanceof condition to offer more field and method access proposals. The required cast will be inserted when such a proposal is selected.
Content assist for static members also work if the type has not been imported yet. The required import will be added when such a proposal is selected.
Content assist can now propose methods with unknown types.
Content assist on method invocations shows the guessed arguments.

Quick assists
New quick assists (Ctrl+1) have been added in this release.

Highlighting numbers in Java code
The Java editor can now show numbers with their own custom color.

Mark read and write occurrences
Mark Occurrences (Alt+Shift+O) now marks read and write accesses with different colors.

Occurrences in File improvements

Several improvements have been added to Search > Occurrences in File:

The quick menu (Ctrl+Shift+U) now only shows the searches applicable for the current selection. If only one search kind is possible, the shortcut will directly invoke the search.
The menu now offers all searches available by Mark Occurrences.
Matches are now highlighted with different colors for read and write accesses in the search view.
The search view offers a Link with Editor mode where the view input is connected to the current editor selection.

Java compiler on multi-CPU machines
The Eclipse Compiler for Java is now taking advantage of the multi-threading capability of multi-CPU machines. Our measurements show improvements up to 30%. Results depend on the JRE and platform used.

Support for external class folders
Class folders located outside the workspace (external) can now be added to the build path. To add an external class folder use the Java Build Path page of the project properties, select the Libraries tab and push the Add External Class Folder button.

Flexible ZIP archive extensions
It is now possible to add ZIP archives to the build path with file extensions other than .zip or .jar. It is now, for example, possible to add a .rar file on the build path.

Call Hierarchy view works with fields and types
The Call Hierarchy view in caller mode now works with more kinds of elements:
The children of a field are all members that access the field (read and write accesses).
The children of a type or an instance initializer are all constructors of the type

Runnable JAR export wizard
The Runnable JAR File Export wizard can create a JAR file based on a launch configuration. The generated JAR file contains all class files from the project including class files from required JARs and projects.
The generated JAR can be executed with the command: java -jar generated_file.jar
or, on most operating systems, by double-clicking the file.

More Java search options
Type reference search can now be limited to specific match locations in the code. For example, you can find references in cast expressions, or in field and local variable types.
The following example shows how to search for all catch clauses in your code (search for references to '*' and limit to catch clauses):

Paste creates snippet for members and statements
Paste (Ctrl+V) in the Package Explorer view now supports members and statements. Eclipse creates the required enclosing elements for you.

Enhanced debug hover
When debugging, hovers for variables have been enhanced to display an object inspector. The inspector will display logical structures according to the toggle setting in the visible Variables or Expressions view.

Saturday, July 5, 2008

SpringSource Application server

SpringSource announced a new application server that it claims will "liberate" Java users from "antiquated legacy Java technologies."
SpringSource Application Platform is a completely module-based Java application server that is designed to run enterprise Java applications and Spring-powered applications with a new degree of flexibility and reliability. The SpringSource Application Platform is based on the new SpringSource Dynamic Module Kernel™ (dm-Kernel). The dm-Kernel provides a module-based backbone for the server, which also harnesses the power of Spring, Apache Tomcat and OSGi-based technologies.
The product is now in beta at SpringSource's Web site.

Production Benefits
* Real time application and server updates
* Better resource utilization
* Side by side resource versioning
* Longer server uptime
* Run new and old web applications

Development Benefits
* Faster iterative development
* Small server footprint
* More manageable applications
* Greater code reuse


OSGi technology - Dynamic module system for Java

OSGi technology is Universal Middleware. OSGi technology provides a service-oriented, component-based environment for developers and offers standardized ways to manage the software lifecycle. These capabilities greatly increase the value of a wide range of computers and devices that use the Java platform.OSGi technology adopters benefit from improved time-to-market and reduced development costs because OSGi technology provides for the integration of pre-built and pre-tested component subsystems. The technology also reduces maintenance costs and advances unique new aftermarket opportunities because networks can be utilized to dynamically update or deliver services and applications in the field.

The OSGi framework can be divided in two main elements:

* Services Platform

A services platform is defined as a software platform that supports the service orientation interaction. This interaction involves three main actors: service providers, service requesters and a service registry, although only the service registry belongs to the services platform. In the service orientation interaction, service providers publish service descriptions, and service requesters discover services and bind to the service providers. Publication and discovery are based on a service description.
In the context of OSGi, a service is described as a Java class or interface, the service interface, along with a variable number of attributes, the service properties, that are name and value pairs. Service properties allow different service providers that provide services with the same service interface to be differentiated. The service registry allows service providers to be discovered through queries formulated in an LDAP syntax. Additionnaly, notification mechanisms allow service requesters to receive events signalling changes in the service registry; these changes include the publication or retrieval of a particular service.
In OSGi, service providers and requesters are part of an entity called a bundle that is both a logical as well as physical entity. Service interfaces are implemented by objects created by the bundle. In standard OSGi, the bundle is responsible for run-time service dependency management activities which include publication, discovery and binding as well as adapting to changes resulting from dynamic availability (arrival or departure) of services that are bound to the bundle.

* Deployment infrastructure

Physically, a bundle correspond to a delivery and deployment unit that is materialized by a JAR file that contains code and resources (i.e., images, libraries, etc.) along with a file that contains information about the bundle, the manifest file. The OSGi framework provides mechanisms to support continuous deployment activities (for example a local console or an administration web page). These deployment activities include installation, removal, update, starting (activation) and stopping (de-activation) of a physical bundle. Once a bundle is installed in the platform, it can be activated if deployment dependencies that are associated to the bundle are fulfilled (these dependencies are described in the next section).

Friday, July 4, 2008

Compile a Java source from inside a Java program

Here is sample program which shows how to compile Java source file from inside a Java program using JDK 6.

Sample Java Code

import java.util.ArrayList;
import java.util.List;

public class Compiler {

public static void main (String[] args) {
String sourceFile = "c:/Sample.Java";
JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool ();
StandardJavaFileManager fileManager =
compiler.getStandardFileManager (null);

// prepare the source file(s) to compile
List sourceFileList = new ArrayList ();
sourceFileList.add (new File (sourceFile));
Iterable compilationUnits =fileManager.getJavaFileObjectsFromFiles (sourceFileList);
CompilationTask task = compiler.getTask (null,fileManager, null, null, null, compilationUnits); ();
boolean result = task.getResult ();
if (result) {
System.out.println ("Compilation was successful");
} else {
System.out.println ("Compilation failed");
try {
fileManager.close ();
} catch (IOException e) {