Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Saturday, 13 July 2013

MonjaDB - The Eclipse plugin for MongoDB

MonjaDB is an Eclipse plug-in for connecting to a mongoDB server and manipulating data records. It provides a simple intuitive interface for viewing, querying and performing CRUD operations on JSON documents stored within the database. As described in the screenshot below, the list of available databases is shown in the DBTree window. In this case, the blog database has been selected and from within it the posts table is active. Data from the posts table is visible in the central window, titled  Document List. The windows to the right of the Document List provide an interface for editing a particular data row.

monjaDB Interface


The bottom windows titled Actions and Saved Actions give the ability to re-run any database commands or queries and to save those commands for further reference. Finally, the console window captures log statements generated by the MongoDB server.
Overall, monjaDB is a simple yet powerful MongoDB GUI client that provides the ability to perform basic database operations and run queries against a MongoDB database.

Friday, 29 March 2013

Generating JavaDoc with Eclipse or Maven

Generating JavaDocs is an integral part of every Java project and there are various options of generating the required documentation.

Option 1 :  Using Eclipse and JDK's JavaDoc tool.

This is the simplest option. If you are using Eclipse and have the path to the JDK (not JRE) set in the Eclipse > Windows Preferences > Installed JRE option set correctly (as shown in the screenshot below), Eclipse should be able to find the JavaDoc tool.
Set the path to your installed JDK

JavaDoc Tool in Eclipse
That's it. Clicking on the Javadoc option will bring up a wizard that will prompt you for the Destination folder for the generated JavaDocs. Apart from generating the JavaDocs, the tool will also create a stylesheet.css for the JavaDocs that can be edited if required.

Option 2 :  Using Maven and the JavaDoc plugin.

Add the plugin definition to your pom.xml
               
                
                     ...........
                  
                  org.apache.maven.plugins
                  maven-javadoc-plugin
                  2.9
                  
                    C:/javadoc/stylesheet.css
                     public
                  
                  
                
                  


In the snippet above, I have added the plugin definition and configuration to the build section. It can also be repeated in the section. This will allow me to run the Javadoc generation goal during the build cycle. I have also specified a path to a stylesheet file that will define the look and feel of the JavaDoc generated.

To generate the JavaDoc using Maven, use mvn javadoc:javadoc

More details on this option is available here.




Sunday, 19 August 2012

Managing PermGen and Heap allocations in Tomcat7

If you are developing a web-application that runs on Tomcat 7, it is highly likely that you will encounter a PermGen space error on Tomcat which happens when you deploy and undeploy the application several times and there is a memory leak. There could be several reasons for a memory leak and they could stem from loading third-party jars such as JDBC drivers and logger jars from within the web-application lib. To overcome some of these potential issues, it is best to load them directly into Tomcat lib and let Tomcat the Driver Manager take care of de-registering them when not in use.

While the best approach to dealing with this problems and other memory related problems is debugging the cause of the memory leak and fixing it, there are times when tuning the JVM parameters can alleviate the cause and improve performance of the application to a certain extent.

Before diving into the tuning the JVM parameters, it is important to understand how JVM organises its memory space and what is the difference between heap and permgen space and how they are used. This article gives a very good overview of the JVM memory layout.  To summarise the difference between the two, the permgen space is used to store classes loaded by the class loader, primitives,any static classes and other JVM related data. On the other hand, the heap space is mainly used to store objects created by the application. It is further divided as explained here into Eden, Survivor and Tenured Gen space.

It is also important to note that since Java 1.6 update 16, there have been some major changes to the process used to compute heap size in 32 bit and 64 bit JVMs and in client / server mode.

Having understood the basics of JVM memory organisation, we can look at tuning Tomcat's memory allocation for its heap and permgen. While there are several parameters that can be used for tuning the JVM, this post is just going to describe the minimum and maximum parameters for specifying the heap and the permgen space. The location of where to specify these parameters and their values depends on your machine specification (operating system, memory size, 32 bit or 64 bit) and how you invoke Tomcat.

Deciding on the actual values of the parameters should be taken after monitoring the JVM using some tools such as jVisualVM. The values given below are sample values that worked in my particular case.

Case 1: Tomcat is invoked from within Eclipse on a 32 bit machine.
Specs : Tomcat 7.0.28, Eclipse Juno, Sun Java 1.6.30, Windows 7.0

The parameters should be specified in Server Launch Configuration -> Open Launch Configuration -> Edit Launch Configuration Properties ->Arguments
Tomcat Launch Configuration in Eclipse
The detailed steps are available here.

Case 2: Tomcat is invoked via its start up script on a 32 bit virtual machine.
Specs : Tomcat 7.0.28, Sun Java 1.6.30, Ubuntu 12.04

Create a setenv.sh file and add the following one line in it.

export JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms128m -Xmx256m -XX:MaxPermSize=128m -XX:+DisableExplicitGC"

Transfer this file to your Tomcat/bin directory and re-start Tomcat.

There are a number of ways of verifying that the JVM parameters were applied to Tomcat. The easiest way on Ubuntu is : ps -ef | grep tomcat

You should see something similar to the line below:

john     17841     1  5 15:23 pts/0    00:00:09 /usr/bin/java -


Djava.util.logging.config.file=/usr/local/apache-tomcat/conf/logging.properties -Xms128m -Xmx256m -XX:MaxPermSize=128m -XX:+DisableExplicitGC -
Djava.endorsed.dirs=/usr/local/apache-tomcat/endorsed -classpath /usr/local/apache-tomcat/bin/bootstrap.jar:/usr/local/apache-tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat -Dcatalina.home=/usr/local/apache-tomcat -Djava.io.tmpdir=/usr/local/apache-tomcat/temp org.apache.catalina.startup.Bootstrap start



With respect to parameter values for the heap, it is important to note that :

(Managed Heap + native heap + (thread stack size * number of threads)) cannot exceed 2GB on 32bit x86 Windows or Linux systems (ref)


2GB is a theoretical limit. Since the heap requires contiguous memory space, it might be hard to push the heap beyond 1.4GB on a 32 bit Windows machine.

A final comment.
The JVM is an intelligent software and has several inbuilt processes built into it that work to optimize its performance. Attempting to tune the JVM may not always result in a performance improvement. Tuning the JVM is dependent on the machine specification, the design decisions taken behind the architecture of the web-application it is hosting, the number of applications hosted by the JVM and when all else fails, Trial and Error. 

Saturday, 30 June 2012

Eclipse Juno has arrived.

Continuing with the tradition of yearly June releases, Eclipse rolled out its latest offering - Juno. While as always there are a significant number of bug fixes and features, Juno mainly targets the Eclipse Development community by base lining the current version as the mainstream target platform for RCP development.
Another interesting offering is the Code Recommenders that promises to made coding 'smarter' by offering "by means of intelligent code completion, extended javadocs, smart bug detectors, stacktrace search engines and others...". While it would be unfair to expect an immediate performance boost from the Code Recommender feature, it can be regarded as a major stepping stone towards integrating coding standards and quality benchmarks within the IDE.

Saturday, 23 June 2012

Bracketeer : Bracket your Java Code in Eclipse

As an application developer, I regularly have to  understand and re-factor code that has been authored by other developers. It could be code coming from an open-source library or code from within the existing application. If it is Java code, it is sure to have one thing - Brackets and Braces. For simplicity, I am going to use the term 'Brackets' interchangeably for the rest of the article.
Since well commented and well-formatted code makes understanding the logic of the method or block easier, working out the start and end brackets within a block can take up a fair amount of time, especially  if the code has a high degree of cyclomatic  complexity. This scenario is when Bracketeer, which is currently featured as one of the top-most popular new Eclipse plugins is useful. While the plug-in is just six months old (as on June 2012) and is still in a beta-stage, I installed it in Eclipse Indigo SR1 and gave it a run.
While Bracketeer's ability to match brackets and color them is not exactly a new feature for Eclipse users, it's ability to introduce comments at the closing end of brackets is something that I found useful.
For example, the screenshot below show's an Eclipse editor without Bracketeer activated and the screenshot following it shows the comments that come up when Bracketeer's commenting feature is activated.
Bracketeer - Inactivated. No comments are visible
The screenshot below displays the result after activating, Bracketeer's commenting feature. It generates a comment that appears at the end of each closing bracket. This comment is similar to a pop-up and does not get added to the source file. Thus, resolving the start and end of braces becomes considerably simpler. {}
Source code with the Commenting Feature Enabled.

Finally, Bracketeer is customizable and can be configured to cater to your coloring and bracket matching requirements.Bracketeer can be installed as an Eclipse plug-in from here.
Customizable Interface for Bracketeer

Saturday, 24 September 2011

Maven-ise your Eclipse (Indigo)

With the transition of the Maven2Eclipse plugin project from the Sonatype boys to the Eclipse umbrella, support for running Maven from within Eclipse has become smoother and definitely easier. To get started, install the Maven2Eclipse plugin from within Eclipse using the Help->Install new software menu option. The link to the plugin download is http://download.eclipse.org/technology/m2e/releases but verify the same from the  plugin site.
After successfully installing Maven, you will have access to several Maven project wizards that will help you get started with a Maven project with a few clicks as shown in the example below as I did for Eclipse Indigo.

  • Select a New project and choose Maven project. Click through the next few steps. You will get an option to choose the Maven archetype and specify the GroupId, Artifact Id, Version and Package






















  • After you select the required options, the wizard will generate a project file structure and populate it with some skeleton code including a Junit test.











  • That's it. You have created a Maven based project which is now awaiting functionality. Adding new dependencies, plugins to the project and the POM is made easy using the Maven project menu, available by right clicking on the project folder and selecting the required option.























  • A Maven Build can be set-up and initiated from the Run- As menu option. 













  • Selecting the Maven build option for the first time which will bring up a set-up configuration dialog that will enable you to specify the goals, profiles and set up any required parameters.

















  • Once the Run configuration is ready, you can build your Maven project and deploy your snapshot.

Saturday, 10 September 2011

Designing Model Driven Architectures using the Eclipse Modelling Framework

The Eclipse Modelling Framework (EMF) is another useful tool within the Eclipse suite that offers an open source framework for the designing model driven applications. In terms of technology, EMF unifies Java, XML and UML. Given a 'model' described in either of the three technologies i.e Java, UML or XML schema, it is possible to generate the other two. To get an idea of what type of applications can be designed using the EMF, check out this list

The major advantage of using EMF is that it connects a model to its Java based implementation and this simplifies the process of designing and implementing a model. EMF generates Java code separating interfaces from their implementation. In addition, it also generates Factory classes for managing objects. EMF also supports standard CRUD operations, specification of cardinality constraints and the enforcement of referential integrity. Database persistence is available via Teneo.

Designing models in EMF is done using the Eclipse Java Development Tools.Third party options such as Topcase's Ecore editor and Ormondo's EclipseUML editors can also get the job done.
While the Ecore model can realised from Java (using Annotations) , XML Schema orUML, persisting the serializable version requires another form : XML Metadata Interchange (XMI).

Lars Vogel's tutorial is a good starting point for learning and implementing an EMF based application. While the learning curve for EMF is not very steep, debugging problems in the generated code can be a little painful. To get started with the development of EMF based applications, download the Eclipse Modelling Tools IDE and create a new EMF project using File -> New -> Project

Saturday, 3 September 2011

Designing Swing / SWT GUIs using WindowsBuilder in Eclipse Indigo

The latest release of Eclipse code named Indigo includes the WindowsBuilder project as an open source project within the Eclipse umbrella of projects. WindowsBuilder which is a significant GUI designing tool in its own right provides a WYSIWYG editor for desgining Swing and SWT interfaces from within Eclipse.

WindowsBuilder comes bundled with the standard download 'Eclipse IDE for Java Developers' but if you choose to download another version of Eclipse and you need to manually add the plugin, , goto Help->Install New Software -> and in the 'worh with' box enter the site : site http://dl.google.com/eclipse/inst/d2wbpro/latest/3.7  and then follow the usual steps for adding the plugin. After successfully installing it, you will be able to view the plug-in in the 'Installation History' and the'Plugins' tab of Eclipse Installation Details.


Now that you have WindowsBuilder installed, creating Swing / SWT based GUIs is just a matter of clicking through a few wizards. To create a screen using the wizard, create a Java project and then select New-> Other->WindowsBuilder and open up the wizard.

Other->WindowsBuilder and open up the wizard. Select the required option. In this case, I selected 'ApplicationWindow' and the wizard generates the ApplicationWindow for me as shown in the screenshot.
At the bottom of the editor view, there will be two options, 'Source' and 'Design'. Click on the Design option. This will open the design page and load up the pallet and give you the WYSIWYG option.You can now see your 'frame' object on the right hand side and the pallet with different Swing and SWT controls that you can use. I added a JPanel and set its layout to 'JGoodiesFormLayout' and then added a couple of labels, textboxes and a 'Send' button.
Add the required controls you need. You can also select any of the controls and add any EventHandlers that you might need by right clicking on the controls.


The wizard will create skeleton code for you which you can customize as required. Once you are done, just run the application.




Finally, if you want a different 'Look and Feel', especially a 'Native Platform' look, the WindowsBuilder has an option in the top menu, that allows you to change the Look and Feel as shown in the screenshot below.


Thus, within a few minutes, you can design a fully functional Java application with a few bells and whistles. This is very useful, if you need a prototype and some sample screenshots to show the user. Instead of wasting time,drawing the screens in a prototyping tool, create the same using the WindowsBuilder plugin and when the client gives you the green light, come back to your prototype, clean up the code and add the required functionality. Finally, there are a couple of good tutorials on YouTube that describe using WindowsBuilder with Eclipse.

Saturday, 2 July 2011

Building RCP applications with Eclipse

While Eclipse is a well known and respected development platform, it also serves as a basis for the development of RCP (Rich Client Platform) applications. In doing so, Eclipse presents itself as an open tools platform. Since the architecture of the Eclipse platform is modular and is built upon the plugin methodology, it is possible to reuse the core components of the Eclipse platform and build just about any Rich Client Platform. Here is a good list of commercial products that are based on the Eclipse RCP framework. The main reasons for developing an Eclipse RCP application would be that it would be realised as a 'Component' model. In other words, building blocks of the application can be re-used as building blocks of other distinct applications. Further, the application would remain OS Independent while giving the user an OS based native look and feel.


Since the main components that serve up an Eclipse RCP UI application JFace and SWT (Standard Widget Toolkit) are distinct to Swing in architecture and purpose, there is a learning curve involved which is made easier via a good set of regularly updated tutorials. Hardcore Swing users need not despair as it is possible for both technologies to share the same space. A good place to start learning RCP applications is here and Lars Vogel's comprehensive tutorial.

Tuesday, 28 June 2011

Eclipse Indigo arrives...

Eclipse Indigo became available for download on June 22,2011. 62 teams coordinated in bringing together 46 million lines of code to make this release possible.I download a copy and noticed a marked improvement in Project Refresh rates. While Indigo appears to be faster, it has bought in some key features such Better support for using GIT, WindowsBuilder for GUI development and automated functional testing of GUI development for Java.