Tag Archives: eclipse

Eclipse Unable to Detect Glassfish 3 Server Is Started

Found this problem on my Windows 7 PC where when I tried to start my Glassfish 3 server via Eclipse it seems to start alright, but Eclipse could not detect it has started.

On the server panel progress bar is stuck at “Starting glassfish..” message, and after few minutes it will say “Unable to start server on time”.. yet the server process is still running on the background.

glassfish

Thanks to this StackOverflow answer by HAmark, this problem seem to be caused by Java unable to resolve the host name “localhost”.

This can be resolved by adding following entry on your C:WindowsSystem32driversetchosts file:

127.0.0.1 localhost

Creating New Java EE 7 Maven Eclipse Project

Still on the Java EE 7 hype, here’s a quick cheat sheet on how to create a minimal Java EE 7 ready maven project:

  1. Ensure you have Eclipse Indigo installed with m2e (maven connector). If not you can drag and drop this logo into running Eclipse instance

    (thanks m2e team)
  2. Create new maven project, tick Create a simple project (skip archetype selection), on the next screen provide Group Id, Artifact Id, and set Packaging to war. Hit Finish
    new maven proj cut
  3. Open pom.xml, switch to source view. Add Java EE 7 dependency. Set the scope to provided so that it is included at compile time, but not on the war bundle (because it should be provided by container)
    
      4.0.0
      com.gerrytan
      jee7fiddle
      1.0
      war
      
      
      
        
          javax
          javaee-api
          7.0
          provided
        
      
    
  4. Tell Maven to compile using JDK 7, otherwise the deafault is JDK 5
      
        
          
          
            maven-compiler-plugin
            3.1
            
              1.7
              1.7
            
          
    
  5. And finally prevent maven-war-plugin from complaining because of missing web.xml. New Java EE 7 style provides good annotation support, web.xml can be omitted for a simple project
          
          
            maven-war-plugin
            2.3
            
              false
            
          
        
      
    
    
  6. Right click on the project -> Maven -> Update Project… -> OK. This will cause m2e to synchronize with all changes we made
  7. Test your new project by running clean package
    maven run cut
    You should end up with a war bundle with your project name under target directory

Working With Eclipse and Glassfish

With the new launch of Java EE 7, I felt the quickest way to get a taste of it is to use Glassfish (Java EE reference implementation). Here’s how to get started with Glassfish and Eclipse:

Eclipse GlassFish Setup

  1. Download and install JDK 7 if you haven’t done so.
    jdk download



  2. Ensure you have Eclipse installed. First we’ll add Glassfish runtime environment. On Eclipse, go to Preferences -> Server -> Runtime Environments -> Add and select Glassfish -> Glassfish 4.0 (Select Download additional server adapter if you can’t find it).

    eclipse glassfish 01

    Hit Next, select Java 7 runtime and glassfish directory (On windows this is normally C:glassfish4glassfish)

    glassfish eclipse setup 1

  3. Next, create a new Glassfish server. Ctrl+N (or Cmd+N on Mac) and select Server -> Server. Select server type GlassFish -> GlassFish 4.0. Accept all defaults and hit Finish. You should now have a Glassfish server on your Servers tab on eclipse:

    eclipse glassfish 2

  4. To test your server, select the Glassfish 4.0 Server from Eclipse server tab and right click -> Start. Glassfish server will output few messages to the console, and you can verify by opening http://localhost:8080 on your browser, you will see something like this:

    glassfish server running

    Right click the server -> Stop to stop the server.

Create New Glassfish Application Project

Now we have eclipse wired to Glassfish, we can begin coding the application.

  1. Create a new dynamic web project: Ctrl+N (or Cmd+N on Mac) -> Select Web -> Dynamic web project. Configure it like following:
    Screen Shot 2013-06-29 at 2.46.42 PM

    Accept all default (or configure if you need to) and hit Finish

Changing Eclipse Colour Theme

The default eclipse colour scheme is too bright and quite painful to the eye. Trying to change it isn’t the easiest thing to do either as I have spent 30min with no luck. But thanks to the guys behind Eclipse Color Theme plugin, you can change the color theme in an instant.

eclipsecolor

Installing the plugin is way too easy too, just drag and drop button below to running eclipse window (not on the text editor bit — but on the menu / other area)


Once installed and eclipse restarted, you will find following menu on the preference window to change colours

eclipse color theme 01

Unfortunately this only changes the editor window. Many other community attempts to change other components aren’t yet effective & looks good for Eclipse 4 running on Windows 7. Stay tuned will keep you posted.