How to use the Google App Engine with the NetBeans IDE

At IDR Solutions I spend a lot of time on the Development of the JPedal Java PDF Library and PDF to HTML5 Converter. Recently I have spent a lot of time studying the cloud and thought it might be useful to create some guides on how to use various cloud platforms with the NetBeans IDE.

If you want to run a Java web application on the Google Cloud then you are going to have to become acquainted with the Google App Engine (GAE) which lets you build and run applications on Google’s infrastructure. For those of you who are looking to host an application that you have already created, please be aware that the GAE doesn’t support every class in the Java Runtime Environment. For example java.awt.Color isn’t supported but org.w3c.dom.css.RGBColor is. You can check out the JRE white list here.

Did you know that the NetBeans Community is holding a Free NetBeans Event Day, with lots of interactions, workshops and more.
Learn more about the day here.
NetBeans Day is the 25th of April – Get tickets and register your interest for the day here.

 

What you will need before you start:

  • – Java 7 EE installed. Make sure it is set as your JAVA_HOME environment variable. We tried using Java 8 and encountered problems when using .jsp files
  • – Apache Maven installed. I would recommend adding Maven’s bin directory to your PATH environment variable because this will make your life easier later e.g. add this to the end of your current PATH ;C:\Program Files\apache-maven-3.3.3\bin
  • – Simple knowledge of how to operate your computer’s command line/terminal

1. Sign up for a Google Developer account

Before we can get started with the technical bits you have to be eligible to use the Google Cloud services. You can do this by either signing up for a 60 day free trial or by paying for the service. This page will give you some insight on what you can expect from the trial. Once you have successfully signed up you gain access to the Google Development Console, which will let you manage your application once it is deployed and other cloud resources.

2. Create a new Project on the Google Developer Console

You first register a new project in the Google Developer Console. Click the Create Project button and enter a project name. Each project has a project ID which will either be the same as your project’s name or a slightly different ID will be suggested. This is because the project ID must be globally unique and someone is already using that ID. Once you have clicked Create you will receive notifications on the browser to confirm your project was created. This will create your application’s host location e.g. yourProjectId.appspot.com

projectID

3. Download the Google App Engine SDK

You can download the SDK here. You have to make sure you get the Java version as the page shows multiple. Once it has been downloaded, extract the zip from your downloads folder and save the extracted folder in your Program Files directory. e.g. C:\Program Files\appengine-java-sdk-1.9.26

googleSDK

4. Download the NetBeans Google App Engine plugin

This plugin will allow you to create and run a Google App Engine Server instance which is what we will use to deploy your applications to the Google Cloud Platform. You can download the latest version here. Gaelyk carried on development of the plugin after Kenai created it but stopped development back in 2009. Make sure you download the most recent update. Again extract the download and place in the Program Files directory

5. Add the Plugin to NetBeans

In your NetBeans IDE go to Tools menu and click the Plugins option. In the Plugins window go to the Downloads tab and click Add Plugins. Navigate to where you saved the plugin in the Program Files directory and open all of the NetBeans Modules (.nbm). Click Install at the bottom left of the plugins window and an Installation Wizard will pop up. Accept the Licence Agreement and install the modules.

addPlugin

6. Create the Google App Engine Server instance

Go to your Services window, right click on Servers and select the Add Server option. In the wizard select Google App Engine and click Next. For the installation location put in the location of the SDK in the Program Files directory. e.g. C:\Program Files\appengine-java-sdk-1.9.26. You can leave the port numbers for now and change them later if need be. Click Finish. You should now have Google App Instance under Servers.

addServer

7. Create a Google App Engine Project

Now we can create a new Web Application. Go to the File menu and select New Project. In the Java Web category select Web Application. Fill in the name and location details for your project. On the Server and Settings screen select Google App Engine for the server. Java EE 5 is the only option for the Java EE version. Now click Finish and your project will be created.

googleAppSettings

8. Change Project ID

Below shows what your project’s file structure should resemble. To correctly deploy your application to the Google Cloud Platform you need to add your project Id to the appengine-web.xml file. Remember to save the file.

googleProjectId

9. Prepare the Project for Deployment

Right click the project and there should be a Change email/password option. Here you should enter your Google Development Account credentials. Then right click the project again and select Clean and Build which will compile the application for you.

10. First time Deployment

This stage is needed for the very first deployment to Google App Engine. After you have completed this stage you will never have to carry this out for ANY other GAE project. I am using Windows so I will be using the command line. The commands will vary slightly for those on different Operating Systems.

Navigate to your Google App Engine SDK in your Program Files directory. Then use cd bin to navigate you in the SDK’s bin directory. From there you will need to run appcfg.cmd with the update argument and the path to your applications web directory e.g. appcfg update C:\Users\userName\Documents\NetBeansProjects\WebApplication1\web

If you  get an error message related to JSP files or that you are pointing to the JRE instead of the JDK, then this may be due to your PATH environment variable. If you open up your PATH and see something along the lines of C:\ProgramData\Oracle\Java\javapath then you need to delete and replace this with the path to your current SDK’s bin directory. e.g. C:\Program Files\Java\jdk1.7.0_79\bin

commandPrompt

You should be asked for an authentication code. A web browser will be opened  and you will be asked to sign in to your google account if you are not signed in already. After that there will be a code displayed which you need to copy from your browser into the command line. You should see output similar to below if your application has been deployed correctly.

commandOutput

11. Deployment from here on

Like I said before you will not have to complete step 10 again. You can simply right click your project in NetBeans and select the Deploy to Google App Engine option. Much simpler right?

12. View your application

To see your application running go to yourProjectId.appspot.com

And voila! There you have it ladies and gentlemen. That is how to setup and deploy an application to the Google Cloud using the Google App Engine.

Next time I will be looking at ‘How to set up Amazon Cloud/AWS Elastic Beanstalk on the NetBeans IDE

Hopefully you found this guide Tutorial useful, if you have not read my other cloud series articles be sure to check them out below:

If you want to trying running Java Software on the Amazon and Azure Cloud you can try following these handy tutorials

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the  Blog RSS.

Related Posts:

The following two tabs change content below.

Georgia Ingham

Java Developer at idrsolutions
Georgia is a Java Developer at IDRSolutions. She is currently working along side the team on the development of JPedal and JPDf2HTML5. Her hobbies include reading and cycling.
Georgia

About Georgia Ingham

Georgia is a Java Developer at IDRSolutions. She is currently working along side the team on the development of JPedal and JPDf2HTML5. Her hobbies include reading and cycling.

15 thoughts on “How to use the Google App Engine with the NetBeans IDE

  1. Hennie

    Thanks for the great tutorial on GAE deployment in Netbeans, Georgia. It really helped me a lot.

    There is only one little problem: I can deploy from the command line without a problem, but when I deploy in Netbeans, it seems to work fine without errors, but nothing is deployed.

    For the Google Development Account credentials, I put my Google email and password. Is this correct?

    Kind Regards,
    Hennie Reyneke

    • Georgia Ingham

      Hi Hennie,
      I’m happy that is was helpful to you. You should enter your google account credentials there. Another possibility is that your Project Id doesn’t match your project in GAE in your appengine-web.xml file.
      Kind regards,
      Georgia

      • Hennie

        Thanks for the reply and the advice, Georgia.

        Yes I did put my google account creds in there. And the application tag contains the Project ID. But it’s obviously a local problem here and I can live with it.

        A bigger problem is that JSF isn’t working. GAE seems to ignore the jstl tags.

        Take care,
        Hennie

        • Georgia Ingham

          Hi Hennie,
          Sorry I won’t be able to help you there as I never used JSF when using GAE.
          Kind regards,
          Georgia

  2. Hennie

    Hi Georgia. Sorry, my mistake: I didn’t see that there was a new ‘Deploy to Google App Engine’ option in the drop-down (as you wrote!).

  3. Kuban

    This is really awesome!
    Thanks a lot.

  4. Mohamed Farid

    I tried this link
    but I can’t complete step 10
    I have the code it said about but how I can copy it in command line?

  5. Georgia Ingham

    Hi Mohamed,
    The cause might be that your environmental variables are not set up correctly. If you open up your PATH environment variable and see something along the lines of C:\ProgramData\Oracle\Java\javapath then you need to delete and replace this with the path to your current SDK’s bin directory. e.g. C:\Program Files\Java\jdk1.7.0_79\bin

    Also NetBeans has its own path to the JDK set in a configuration file. You may have to update this too. You can see how to do that here

  6. Rohan

    My error is coming like
    java.lang.RuntimeException: Cannot get the System Java Compiler. Please use a JDK, not a JRE.
    Unable to update app: Cannot get the System Java Compiler. Please use a JDK, not a JRE.

    I changed the path ofenvironment variable from C:\ProgramData\Oracle\Java\javapath to C:\Program Files\Java\jdk1.7.0_79\bin.

    Then also same error is coming now what i can do to resolve it. And in the last comment you have mention that “Also NetBeans has its own path to the JDK set in a configuration file. You may have to update this too. ” But i am not able to getting it that how to change Netbeans path to current JDK.

    Please help me to resolve it.

    • Georgia Ingham

      You can find the NetBeans configuration file (netbeans.conf) in the etc folder of where your NetBeans IDE is stored in program files e.g. C:\Program Files\NetBeans 8.1\etc\netbeans.conf
      Once you open that you need to change this line to which jdk you would like to use: netbeans_jdkhome=”C:\Program Files\Java\jdk1.8.0_60″
      Please note that the bin directory should not be added here and that JDK8 had a few issues when I was using it and so would not recommend using any of those versions.

  7. Justin Mann

    Nice one. gonna spin up a new VM when I get home and give it a run.

  8. Lucia

    Hi, I was following your tutorial (which worked great) but then when I tried to create an object on the index.jsp file I got this error: http://stackoverflow.com/questions/15950166/creating-an-object-within-a-jsp-page
    Eventually I came across this answer http://stackoverflow.com/questions/20762423/why-i-cannot-create-an-object-of-some-java-class-in-jsp-page and realized that the structure in the folder you mentioned at step 10 doesn´t have that structure.
    Instead I had to select this one: C:\Users\userName\Documents\NetBeansProjects\WebApplication1\build\web
    Maybe it’s something well known, but just in case..
    Thanks for the tutorial!

  9. DaveJ

    Worked perfectly! Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>