Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, November 05, 2010

Installing GWT Developer Plugin in Firefox 3.6 for Linux

If you are developing GWT web apps on a Linux system with Firefox 3.6+, then you might have been prompted to install the GWT Developer Plugin when trying to debug your app on Firefox (see image below).


The problem happens when you try to install the plugin and restart Firefox - only to be prompted to re-install the GWT Developer Plugin again.

It seems like the latest Plugin on Firefox 3.6 requires the libnspr4.so.0d library and Mozilla Firefox 3.6+ only provides libnspr4.so. To solve this problem, simply locate the library and create a sym-link. For example, as root, execute the command:

sudo ln -s /usr/lib64/libnspr4.so /usr/lib64/libnspr4.so.0d

Then restart Firefox, install the GWT Developer Plugin, and then restart Firefox once more. You should now be able to debug your GWT web app!

Note that the location of the libnspr4.so library differs in each Linux distro. But here are a few common folders where it might be

/lib/
/lib64/
/usr/lib/
/usr/lib64/

If you are unable to locate the library in one of the directories above, you can try finding it by executing on the command:

locate libnspr4.so

UPDATE: The library should be provided in mozilla-nspr-32bit or mozilla-nspr.

Hope that helps some of you out! Leave me a comme
nt if you have any questions.


Wednesday, March 10, 2010

Setting Up SmartGWT 2.1 and GWT 2.0 with Eclipse 3.5

Requirements:
Setting Up Eclipse Environment:
  1. First, install Java and Eclipse like you normally would, setting up all the necessary environments (e.g. CLASSPATH, JAVA_HOME, etc).
  2. Install the GWT Eclipse plugin by going to Help > Install New Software...
  3. Press the Add... button and enter the following URL: http://dl.google.com/eclipse/plugin/3.5
  4. Check Google Plugin for Eclipse 3.5 and Google Web Toolkit SDK 2.0.3 and press the Finish button.
  5. Restart Eclipse after installing the GWT Eclipse plugin.
Create a GWT Web Application Project:
  1. Go to File > New > Web Application Project
  2. Enter the Project name: HelloSmartGWT
  3. Enter the Package: com.puguasoft.examples.smartgwt
  4. Be sure Use Goolge Web Toolkit is checked.
  5. Be sure Use Google App Engine is unchecked.
  6. Press the Finish button.
Setup SmartGWT:
  1. In your HelloSmartGWT project, create a new folder lib.
  2. Unzip smartgwt-2.1.zip and place both the smartgwt.jar and smartgwt-skins.jar in the lib folder you just created.
  3. Right-click on the HelloSmartGWT project and go to Properties > Java Build Path > Libraries tab and add both the smartgwt.jar and smartgwt-skins.jar to the build path.
  4. Open the com.puguasoft.examples.smartgwt.client.HelloSmartGWT.java class and replace the entire onModuleLoad() with the following:


public void onModuleLoad() {
IButton button = new IButton("Click Me");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SC.say("Hello SmartGWT!");
}
});
button.draw();
}
  1. Open the com.puguasoft.examples.smartgwt.HelloSmartGWT.gwt.xml file and delete or comment-out the following:
        <inherits name='com.google.gwt.user.theme.standard.Standard'/>
  1. In the same XML file, add the following inherits elements:
        <inherits name='com.smartgwt.SmartGwt' />
<inherits name='com.smartclient.theme.silverwave.SilverWave' />
  1. Open the war/HelloSmartGWT.html file and add the following between the <head> section and before the hellosmartgwt.nocache.js script:
        <script> var isomorphicDir = "hellosmartgwt/sc/"; </script> 



Compile and Deploy:
  1. Right-click on the HelloSmartGWT project and select Google > GWT Compile.
  2. Press Compile in the dialog.
  3. Pay attention to the console to make sure there are no compile errors.
  4. Now deploy the app by right-clicking on the HelloSmartGWT project and select Debug As > Web Application
  5. After the embedded web server starts, point your browser to the the URL: http://127.0.0.1:8888/HelloSmartGWT.html?gwt.codesvr=127.0.0.1:9997
  6. You should see the following page:

Wednesday, July 22, 2009

Setting up Eclipse and Maven2 for SmartGWT

There is a great HOWTO for setting up Eclipse and Maven2 for SmartGWT:

http://smartgwt.rorschach.de/index.php5/Setting_up_Eclipse_%26_Maven2

[update] The original link seems to be broken, you can try to use the following:


I have also included the instructions below for future reference:


Verifying Maven Configuration

Maven needs to be configured for the GWT-Maven plugin to work correctly, so navigate to your HOME - Folder and make sure there is a valid Maven configuration file. If your username is john, then these would be valid configuration file locations:

   Linux → /home/john/.m2/settings.xml
MacOS X → /Users/john/.m2/settings.xml
Windows XP → C:\Documents and Settings\john\.m2\settings.xml

If you can't find .m2/settings.xml, then create it with the following content:

   <settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
</settings>

(Check out Maven Settings Reference for detailed information on configuring Maven.)

Setting up Eclipse IDE

Download Eclipse IDE for Java EE Developers at Eclipse Downloads, install and launch.

Setting up Maven Integration

  • Navigate to Help > Software Updates and select the Available Software Tab. Click Add Site... and enter the URL below:
     http://m2eclipse.sonatype.org/update
  • Click OK
  • Expand the m2eclipse.sonatype.org/update node and check Maven Integration:
  • Click Install...
  • Click Next, accept the license and click Finish
  • Click Yes when you are asked if you want to restart Eclipse

Creating the Project

  • Navigate to File > New > Project...
  • Select Maven > Maven Project and click Next twice
  • If you've already installed the GWT-Maven Archetype, you can skip the next step
  • Click Add Archetype..., enter the values below and click OK

    Archetype Group Id: com.totsp.gwt
Archetype Artifact Id: maven-googlewebtoolkit2-archetype
Archetype Version: 1.0.3
Repository URL: http://gwt-maven.googlecode.com/svn/trunk/mavenrepo

  • Select Archetype maven-googlewebtoolkit2-archetype and click Next
  • Provide your Maven - Properties and click Finish. Example values:

    Group Id: com.acme
Artifact Id: helloworld
Version: 0.0.1-SNAPSHOT
Package: com.acme.helloworld

  • Open your pom.xml in the Maven POM Editor by double-clicking it
  • Select the Repositories Tab
  • Click Add... and provide the values below * :

    Id: smartclient
Name: smartclient.com
URL: http://www.smartclient.com/maven2/


  • Save your pom.xml and check the Maven Console output for errors
  • Select the Dependencies Tab
  • Click Add... and provide the values below:

    Group Id: com.smartgwt
Artifact Id: smartgwt
Version: 1.0b2-SNAPSHOT

  • Save your pom.xml and check the Maven Console output for errors

Modifying the Application

  • Modify the generated Application.gwt.xml (add the line in bold)

  <module>
<inherits name="'com.google.gwt.user.User'">
<inherits name="'com.google.gwt.user.theme.standard.Standard'">
<inherits name="'com.smartgwt.SmartGwt'"></inherits>
<entry-point class="'com.acme.helloworld.client.Application'">
<stylesheet src="'Application.css'"></stylesheet>
</entry-point>
</inherits>
</inherits>
</module>
  • Modify the generated Application.java (replace all content)

  package com.acme.helloworld.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.util.SC;

public class Application implements EntryPoint {
public void onModuleLoad() { SC.say("Hello SmartGWT"); }
}
  • Modify the generated Application.css (remove all content)

You need to remove all generated CSS - Styles because they would break the SmartGWT layout.
You can add your own Styles if they don't conflict with SmartGWT, of course.

Running the Application

  • Right-click your pom.xml and select Run As > Maven build...
  • Enter the value below into the Textfield labeled Goal:

   gwt:gwt
  • Click Run to start your Application in the GWT Shell

SVN Snapshots

If you want to develop against the latest snapshot from SVN use the repository and artifact properties below:

  • Repository

   Id: smartgwtsnap
Name: smartgwtsnap.rorschach.de
URL: http://smartgwtsnap.rorschach.de
  • Artifact

   Group Id: com.smartgwt
Artifact Id: smartgwt
Version: 1.0b3-SNAPSHOT

More Goals

Appending -U tells Maven to check for updates of -SNAPSHOT dependencies.

All Goals for GWT-Maven can be found here.

  • clean → Purge working directory (target)
  • gwt:gwt → Build Application, Run in Hosted Mode
  • gwt:test → Build Application, Run GWT-Tests
  • javadoc:javadoc → Generate API-Documentation (→ target/site/apidocs)
  • package → Build Application, Run Non-GWT-Tests, Run GWT-Tests, Build WAR-Archive
  • test → Build Application, Run Non-GWT-Tests, Run GWT-Tests

List of Goals Example

Maven supports a comma or space separated list of Goals:


   clean package javadoc:javadoc -U
  • Checks for updates of -SNAPSHOT dependencies (-U)
  • Purges the working directory (clean)
  • Builds the Application (package)
  • Runs the Non-GWT-Tests (package)
  • Runs the GWT-Tests (package)
  • Builds the WAR-Archive (package)
  • Generates the API-Documentation (javadoc:javadoc)

Troubleshooting

Problems loading gwt-dev libraries


   Can't load library: [...]/.m2/repository/com/google/gwt/gwt-dev/1.5.3/[...] 
  • Problem

The GWT-Maven plugin didn't pick up your local Maven repository location when it tried to extract the GWT development libraries. The libraries probably have been extracted to a folder named ${settings.localRepository} inside your workspace. You can delete this folder, of course.

  • (Quick) Solution

Verify your Maven configuration, delete the folder com/google/gwt/gwt-dev inside your local Maven repository and retry.

Problems loading libxpcom / libstdc++


   ** Unable to load Mozilla for hosted mode **
java.lang.UnsatisfiedLinkError: [...]/libxpcom.so: libstdc++.so.5: cannot open shared object file: No such file or directory
  • Problem

Version 5 of libstdc++ isn't installed.

  • Solution

Install the package libstdc++5 and retry. If you're running a Debian-based distribution like Ubuntu use apt-get:

   sudo apt-get install libstdc++5

Warning: Locking assertion failure

   Locking assertion failure.  Backtrace:  #0 [...] 
  • Problem

There is some sort of problem with how the JRE was built.

  • Solution

Can be found here.

   sudo sed -i 's/XINERAMA/FAKEEXTN/g' /usr/lib/jvm/java-1.5.0-sun/jre/lib/i386/xawt/libmawt.so 

and / or

   sudo sed -i 's/XINERAMA/FAKEEXTN/g' /usr/lib/jvm/java-6-sun/jre/lib/i386/xawt/libmawt.so

NoClassDefFoundError: GWTShell

   java.lang.NoClassDefFoundError: com/google/gwt/dev/GWTShell
Caused by: java.lang.ClassNotFoundException: com.google.gwt.dev.GWTShell [...]
Could not find the main class: com.google.gwt.dev.GWTShell. Program will exit.
  • Problem

There is a problem with the path to your local Maven repository.

  • Solution

Make sure the path to your local Maven repository doesn't contain any non-US-ASCII characters, e.g. an Umlaut.

Friday, October 24, 2008

Sharing Java Applet Sessions in Firefox

There is a known problem in JEP (Java Embedding Plugin) for Firefox in which new sessions (or no sessions at all) are used for every new Java applet request to a servlet. This can be problematic for applets that requests data or URL from a servlet requiring authentication or a login. To get around this problem, you can pass in the current HTLM document's cookie as a Java applet parameter, and then use the cookie in the HttpServletRequest's Cookie request parameter.

In your HTML applet code, just add the document's cookie as a parameter. (Note that I'm writing the HTML applet code in JavaScript to dynamically get the document's cookie.)

<script language="JavaScript" type="text/javascript">
<!--
   document.write("<embed");
   document.write("name='MyApplet'");
   document.write("type='application/x-java-applet;version=1.6'");
   document.write("code='org/puguasoft/examples/MyApplet.class'");
   document.write("codebase='/applets/'");
   document.write("browserCookie='" + document.cookie + "'");
   document.write("</embed>");
-->
</script>
Then in your servlet, use the browserCookie parameter value as the Cookie property in the HttpServletRequest.
import javax.swing.JApplet;
import java.net.URL;
import java.net.URLConnection;

public class MyApplet extends JApplet{

   public void doIt(URL url){
      URLConnection urlConnection = url.openConnection();
      String cookie = getParameter("browserCookie");
      urlConn.setRequestProperty("Cookie", cookie);
      urlConnection.connect();

      // Now you can do what you need with the URLConnection
      // (e.g. open up an InputStream to read the data)
      // using the same cookie session.


   }
}

For more information check out these postings:


Friday, October 10, 2008

Detecting Browser Java Version Using Javascript

Trying to detect a client's browser for the installed Java plugin version and whether or not it's installed, can be a real pain. Luckily,Eric Gerds has created a JavaScript library to do just that. The JavaScript can detect the version of the Java plugin, if any, on different browsers including FireFox, Internet Explorer, Safari, and Opera. In addtion, his script can also detect QuickTime, Flash, Windows Media Player, and many other browser plugins.

Check out the PluginDetect JavaScript: http://www.pinlady.net/PluginDetect/

Thursday, July 03, 2008

Getting a List of Installed System Fonts in Java

Previously, you could get a list of fonts installed in the running system by using using the Java AWT Toolkit:
Toolkit tk = Toolkit.getDefaultToolkit();
String[] fontNames = tk.getFontList();
However, the Toolkit.getDefaultToolkit() method has been deprecated in favor of the java.awt.GraphicsEnvironment. The GraphicsEnvironment class describes the collection of java.awt.GraphicsDevice objects and java.awt.Font objects available to a Java application on a particular platform.

To get a list of font names installed on the system, just use the the getLocalGraphicsEnvironment() method:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontnames = ge.getAvailableFontFamilyNames();
There are many other usefull methods in GraphicsEnvironment class, for more information, take a look at the API.

Sunday, March 26, 2006

It's Good To Be Back!

Finally, after a week-long conference in Silicon Valley, and a weekend spent with friends in San Fran, and after a three-hour flight delay, I'm back home.

EclipseCon 2006 was a great experience for me - I learned so many new things that will be beneficial for my Software Development career. In addition to the great talks, tutorials, and three-course meals, I really enjoyed meeting people from all over the world with the same interest as mine.

Hanging out in San Fran with a bunch of friends was really nice after the week-long conference. The weather wasn't particulary nice when I arraived in San Fran despite being sunny all week long! Regardless, I still enjoyed my short stay there and will definitely want to come back again some time - I love the Bay Area!

To top the week off, I was greeted with a three-hour delay from my connecting flight from Seattle to Eugene. Apparently our Alaska Airline had some kind of mechanical failure and we had to wait for a new plane to fly in for us. After the long wait and short flight, I'm now back in my cozy apartment gearing up for a long week at work. At least now I can put what I learned from the EclipseCon into actual use!

Thursday, March 23, 2006

Eclipse Con 2006 - Day 4

Today was the last day of EclipseCon 2006. I think that I got more out of the talks and presentations today than I did yesterday - alot of informative topics on RCP, SWT, Web Services, and more.

Today's opening and closing remarks/talks weren't all that interesting - so I left the conference mid-way through the closing remark to get a little R&R at the hotel's spa.

Overall, I think the EclispeCon 2006 went really well - except for the short talks (read my previous posts). Then again, this was my first time attending a conference this size. Regardless, I came out of the four-day conference with alot of great and useful information - more than I imagine I would before coming here to Silicon Valley. If I have the opportunity, I definitely would like to attend future EclipseCons as well as other software and IT conferences.

Now that I have all this information about the different Eclipse projects, I can't wait to get back to the lab and start on new projects for myself as well as for my employer.

Although this is the end of the EclipseCon, it definitely isn't the end of my "vacation". In fact, it's just the start when I head up to San Fran to party it up with some friends for the weekend!!!

Wednesday, March 22, 2006

Eclipse Con 2006 - Day 3

It's day 3 of EclipseCon 2006 and nothing too exciting happened. I went to the usual talks and presentations about RCP, DSDP, and other Eclipse projects and tools. Some of the more interesting ones I attended were about actions and commands and the undo system.

The key note about Apache and Eclipse presented at the start of the day wasn't particually interesting. I spent most of the talk just checking email and surfing the web...

After the second day of attending the short talks held towards the end of the day, I have to say that I really hate the way they have set it up. As I mentioned in yesterday's post, the short talks of nine minutes are held in different conference rooms spread all over the convention center and are presented one right after the othere. There are not breaks in between the short talks. So that means you gotta run or leave the a talk early in order to attend the next talk without missing it.

Today's lunch wasn't all that great either - it was some kind of pasta. But the reception at the end of the day was much better. There were a variety of foods from different cultures.

Anyway, I bought a bunch of books on Eclipse plug-in and RCP development, and one on JST. Although I can get them for less expensive at Amazon.com because of the taxes I have to pay here, I figured that since my company is gonna reimburse me for the purchases, why not go all out!

Tuesday, March 21, 2006

Eclipse Con 2006 - Day 2

Day 2 of EclipseCon 2006 was great - lots of informative talks and presentations, good food (breakfast, lunch, AND dinner), and free vendor marketing crap!

The talks and presentations I attended today mostly consisted of RCP and plug-in development, and various tools for Web Services and Hibernate. The one talk I attended today that was particularly interesting was "NASA Mission Operations with RCP". The talk went over how NASA uses RCP and many other Eclipse platform tools to create custom applications used by the Mars lander and Mars rover missions. It's hard to describe everything the RCP application does, so just take my word for it, it was very cool!

The one thing I don't like at the conference are the the 9-minute talks. I don't mind that the talks are only 9 minutes, actually I think it's a good thing since it prevents the presenters from rambling on and on. What I DON'T like is that there is no extra time in between the short talks to move from one place to the other - a new short talk starts right after the other ends. That means I had to run from one conference room to another if I wanted to attend a different short talk without being late. I hope this is something they'll change in next year's conference. I think a two minute passing time would be great to have between each short talk.

Monday, March 20, 2006

Eclipse Con 2006 - Day 1

So my employer, Lunar Logic, Inc., sent me over to Santa Clara for this year's Eclipse Conference. I was pretty excited because it's my first time attending the Eclipse Conference, or any conference of this size and exposure for that matter. Not only am I excited about the conference, but also to take a week away from work and visit the Bay Area. I have a few friends in San Fran that I plan to visit at the end of the week before I head back to Eugene.

Today was the first day of Eclipse Con 2006 - and what a day it was! There were ALOT of people at the Santa Clara Convention Center, and I'm sure there will be even more during the rest of the conference. There were people of all ages and ethnicities from all over the world. Not surprisingly, the male/female ratio was about 10 to 1...

All registered participants recieved a compensation bag full of goodies. There was a nice EclipseCon backpack specifically designed for the tech geek in all of us - lots of pockets for your accessories, a pouch for your laptop, and even a PDA protector! Also included in the bag were a 256MB USB stick, the "Eclipse Rich Client Platform" book (McAffer, Lemieux), CDs, brochures, a t-shirt, and some marketing junk.

The two turtorials I took today were "Plug-in Development" and "Rich Client Platform Development". Both were really good and full of useful information. Before taking the tutorials, I knew very little about both subjects. Now, I feel like I can program them in any applicatoin - well, not really, but I do know much more that before and I plan to use this information in some future projects I have in mind.

The next few days at Eclipse Con I'll be attending various talks and presentations on RCP, plug-in, and mobile development. I feel these subjects will be most useful for my personal, as well as professional, projects.