Tag Archives: eclipse

Eclipse Xtend – a language made for Java developers

In contrast to Java, Xtend removes unnecessary noise. Reducing code to the minimum not only helps you type less, but more important makes the code more readable and maintainable. Boilerplate is mainly avoided by the following features:

(Full Story: Eclipse Xtend – a language made for Java developers)

Amazon Web Services Toolkit for Eclipse – Version 2.0

The new features include a new AWS Explorer, support for multiple AWS accounts and identities, new editors for Amazon S3, Amazon SNS, and Amazon SQS, a new SimpleDB query editor, remote debugging for Elastic Beanstalk environments, and support for creating connections to databases hosted on Amazon RDS.

(Full Story: Amazon Web Services Toolkit for Eclipse – Version 2.0)

JBoss Developer Studio 4 is now available for free

The free version of JBoss Developer Studio is the standalone version which can be used with both community and productized versions of JBoss Application Server and related frameworks such as Hibernate, Seam, Drools, jbpm, etc. The difference between this distribution and JBoss Tools boils down to ease-of-installation and future updates. The product called JBoss Developer Studio Portfolio Edition is also available for 99$ and in addition to  JBoss Developer Studio it gives access to JBoss EAP Server and additional downloads for development purposes of JBoss and Red Hat runtime distributions.

(Full Story: JBoss Developer Studio 4 is now available for free)

GWT Tutorial

This tutorial describes how to develop a Web application with GWT and the Google Plugin for Eclipse. This article assumes basic Eclipse and Java knowledge. The tutorial was developed using JDK 1.6, GWT 2.1 and Eclipse 3.6.

(Full Story: GWT Tutorial)

Stay Productive with Java Server Growl Notifications

When developing it’s easy to get distracted while waiting for a Java Application Server to restart.

Inspired by Ben Ellingson I went looking for a way to get Growl notifications when my local JBoss server had started.   I couldn’t find much so I threw a java solution together such that whenever your JBoss server has started or shuts down you get a notification like:

I think this might be useful to others, so the code is below and the installation instructions for JBoss 5 are:

  1. If you don’t already have them, install growl and growlnotify http://growl.info/extras.php#growlnotify
  2. Copy the compiled Growler.class (remove .odt from this) and Growler.command (remove .odt from this) to <JBOSS_HOME>/bin
  3. Configure the last line in Growler.command, the options are:
    1. -u Specify the username for JBoss authentication(defaults to admin)
    2. -p Specify the password for JBoss authentication(defaults to admin)
    3. -s Use sticky growl notification windows(defaults to not sticky)
    4. -i The location of the JBoss Developer Studio.ico file (defaults to /Applications/jbds/eclipse/jbds.ico)
  4. If you want to run Growler on demand simply launch Growler.command whenever you launch eclipse
  5. However if you want Growler to always be running you’ll need to create a Launch Agent, to do so:
    1. Copy the attached info.sordyl.Growler.plist (remove .odt from this) to your user Launch Agent folder at ~/Library/LaunchAgents/
    2. Open your copy of info.sordyl.Growler.plist
    3. Edit Item 0 under ProgramArguments and update YOUR_JBOSS_HOME_PATH to point to where your Growler.command file lives in <JBOSS_HOME>/bin


Here is the Growler.java source as well; the code can be easily modified to monitor for changes in any JMX property, to access other JMX enabled servers or to access remote server(s).  As written this assumes JBoss 5.x.

import gnu.getopt.Getopt;
import java.io.IOException;
import java.util.ArrayList;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.naming.CommunicationException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;

/**
 *
 * Install growl and growlnotify http://growl.info/extras.php#growlnotify
 *
 * usage: Growler [options]
 * -u <name>    	Specify the username for authentication
 * -p <name>    	Specify the password for authentication
 * -s    			Use sticky growl notification windows
 * -i <filepath>	The location of the JBoss Developer Studio .ico file
 *
 * @author <a href="mailto:brent.sordyl@amentra.com">Brent Sordyl</a>
 */
public class Growler {

	// Use sensible defaults for all properties
	private String username = "admin";
	private String password = "admin";
	private int pollingFrequency = 3;
	private String jbdsIconLocation = "/Applications/jbds/eclipse/jbds.ico";
	private String growlTitle = "JBoss Application Server";
	private String serverStartedMessage = "Server Started";
	private String serverShutdownMessage = "Server is shutting down";
	private boolean stickyGrowlNotifications = false;
	private String jndiUrl = "jnp://localhost:1099";

	public Growler(String[] args) {
		processArguments(args);
	}

	/**
	 * The main method that checks for changes in
	 * server state and sends growl notifications.
	 *
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		Growler g = new Growler(args);
		boolean lastStatus = false;

		while (true) {
			try{
				boolean currentStatus = g.isJBoss5Up();
				if ( (currentStatus != lastStatus) && currentStatus) {
					sendNotification(g.growlTitle, g.serverStartedMessage,  g.jbdsIconLocation, g.stickyGrowlNotifications);
				} else if (currentStatus != lastStatus) {
					sendNotification(g.growlTitle, g.serverShutdownMessage, g.jbdsIconLocation, g.stickyGrowlNotifications);
				}

				lastStatus = currentStatus;
				Thread.sleep(g.pollingFrequency * 1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * Checks if the JBoss 5 server is up, this
	 * will need to change for JBoss 6 per
	 * http://community.jboss.org/wiki/WhichRemoteInterfaceShouldIUseForTheMBeanServer
	 *
	 * @return true, if is server up
	 * @throws Exception the exception
	 */
	private boolean isJBoss5Up() throws Exception
	{
		boolean up = false;
		try {
			SecurityAssociation.setPrincipal(new SimplePrincipal(username));
			SecurityAssociation.setCredential(password);

	    	System.setProperty("java.naming.provider.url", jndiUrl);
		  	System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
	    	System.setProperty("java.naming.provider.url.pkgs", "org.jboss.naming");
	    	System.setProperty("java.naming.provider.url.pkgs", "org.jnp.interfaces");

			InitialContext ctx = new InitialContext();
			MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
			up = Boolean.parseBoolean((server.getAttribute(new ObjectName("jboss.system:type=Server"), "Started")).toString());
		} catch (CommunicationException ce) {} 	// Exception expected when server is shutdown
		  catch (NamingException ne) {} 		// Exception expected when server is starting or stopping

		return up;
	}

	/**
	 * Sends a growl notification using growlnotify.
	 *
	 * @param title the title
	 * @param message the message
	 * @param jbdsIconLocation the jbds icon location
	 * @param sticky the sticky
	 */
	private static void sendNotification(String title, String message, String jbdsIconLocation, boolean sticky) {
		ArrayList<String> args = new ArrayList<String>();
		args.add("growlnotify");
		args.add("-m");
		args.add(message);
		args.add("--image");
		args.add(jbdsIconLocation);
		args.add("-t");
		args.add(title);
		if (sticky)
			args.add("-s");

		try {
			@SuppressWarnings("unused")
			Process exec = Runtime.getRuntime().exec( args.toArray(new String[] {}) );
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Process command line arguments
	 * to override default values.
	 *
	 * @param args the command line args to parse
	 */
	private void processArguments(final String[] args) {
		try {
			String sopts = "u:p:i:s";
			Getopt getopt = new Getopt("Growler", args, sopts);
			int code;
			while ((code = getopt.getopt()) != -1) {
				switch (code) {
					case 'u':
						username = getopt.getOptarg();
						break;
					case 'p':
						password = getopt.getOptarg();
						break;
					case 's':
						stickyGrowlNotifications = true;
						break;
					case 'i':
						jbdsIconLocation = getopt.getOptarg();
						break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

JAutodoc – Eclipse Plugin

JAutodoc will generate comments from element and method names

(Full Story: JAutodoc – Eclipse Plugin)


Follow

Get every new post delivered to your Inbox.