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

Tuesday, April 26, 2011

content assist issue in Flash Builder eclipse plugin

I had some rough time trying to get standalone flash builder version 4 to work with Java code and Tomcat. After hours of scratching my head, I gave up. It just shouldn't be this hard. But if you are adventurous enough to give it a try, here is a great tutorial you may want to read first: http://flashworks.wordpress.com/2011/03/25/java-flex-blazeds-project-solving-issues-with-flash-builder-4-stand-alone/

So my next logical step is to install flash builder plugin to an eclipse installation. I know eclipse pretty well so the java/maven/wtp/tomcat parts went smooth without any drama. Flash builder plugin installed fine. And I was able to import flex projects and tweak the class path to make it build. The only thing missing in this setup is content assist, where I don't get code complete, API suggestions, or open declaration (F3) etc.

After two days of suffering without content assist and numerous googling, I finally found this great discussion which gave me a pointer to get it fixed. :)
http://forums.adobe.com/thread/694803

The culprit: Flash Builder doesn't work well with m2eclipse. Importing flex project as maven project confused the crap out of flash builder.
So what I end up doing is to start with clean project checkout, then in eclipse, create a new flex project with the same name as the checked out project, uncheck the "default project location" and point it to where the project is checked out. then tweak the src folder and build path to make the new project look just like "we imported it from the SCM checkout". After that content assist works like a charm.

Tuesday, November 23, 2010

Use compiler to catch new enum value not covered in "switch"

This old trick shines more and more when our project's code base grew over million+ lines. I have to put it on the web one more time just in case there is a developer out there haven't seen this.

Basically you can set the compiler to generate compilation errors when there are enum values not covered in switch block. So that when a new value is added to an enum class, every switch statement on this enum class will get a compilation error. This way it is easier to find and add corresponding cases, and it is impossible to ignore them. :)

To make this work, you have to do (or not do) two things:

  1. DO NOT use "default" case when you do switch on enum values.
  2. Set your compiler to generate ERROR instead of ignore enum values not covered in switch. In eclipse (the greatest IDE), it is here:

Tuesday, February 16, 2010

JBoss Tools Eclipse plugin content assist lessons

I learned a couple lessons in the process of making JBoss Tools Eclipse plug-in to do content assist (where you type ctrl-space to get code suggestions). This is mostly about JSF component libraries.

First of all, in order to get content assist for JSF components, you must have the TLD file in your class path. We are using Richfaces libraries, and all its components get content assist. The ones I had trouble with are jsf-core and jsf-html, the f: and h: tags by default. Oddly enough though, with all the JSF libraries I have on my class path, none of them had packaged the TLDs for these two. I made a jar file and put jsf-core.tld and jsf-html.tld in the META-INF folder to get this working.

Another lesson learned is that the name space URI has to match exactly with the TLD's. I mean exactly. Kind of obvious, but easy to miss when trouble shooting. I added Openfaces like this xmlns:o="http://openfaces.org" in the first place and it didn't work, because it is expecting a "/" at the end. So the correct syntax is xmlns:o="http://openfaces.org/"

Tuesday, June 03, 2008

upgrade JBoss Tools from 2.0.1 to 2.1.0

Since JBoss Tools is a drop in plugin, you just copy the files into eclipse/plugin folder to install, I wasn't able to figure out how to remove the old version. It may not matter to eclipse but it just doesn't feel right to have multiple versions hang around. I know you can switch back and forth among different versions. But how often do you switch back? Plus eclipse is not able to recognize 2.1.0 of JBoss Tools anyways.

After fiddling with eclipse plugin management UI for a bit, I lost my patient and went with the brutal force:


cd eclipse/plugin
ls -d org.jboss.tools.* | grep 2.0.1.GA | xargs rm -rf
So far so good. Everything is still working.

Please comment if you have a better way to upgrade JBoss Tools.

Monday, March 31, 2008

join lines in Eclipse 3.3

Many times a day when formatting/re-factoring code I join the next line of code to the end of current line. If it is java code, you can do ctrl-delete twice then insert a white space in between two lines. If it is xhtml file, two ctrl-delete will remove the opening tag of next line (at least in JBoss Tools editor), so a lot of times I just type delete key as fast as I can, Yuk. I cannot tell how much I miss 'J' in vi to join lines.

NOW in Eclipse 3.3, a new (new to me) shortcut ctrl-alt-j will do exactly what 'J' does in vi, joining two lines and put a white space in between. Command-alt-j on mac.

Try it and you will like it.

Tuesday, May 22, 2007

Debug Blackberry app inside Eclipse

Once you get your eclipse environment setup, it is pretty straight forward to debug your app, thanks to Blackberry JDE, 4.1 and higher comes with JDWP implementation.

Let's first start JDWP, from Start --> All Programs --> Research In Motion --> Blackberry JDE 4.?.? --> JDWP. In this interface, the first main tab "Simulator" configures the simulator to lanch when debugger connects and the other behaviors. Please make sure that in the "General" tab "Launch simulator when debugger connects" is checked. In the second main tab "Communications", you can change the port JDWP listens to. This is the port we will connect to from our eclipse debugger.

With JDWP running, we can go back eclipse. Before we get started, we should increase the debugger's timeout threshold. Start elcipse, go to Window --> Preferences --> Java --> Debug, at the bottom of the dialog, increase the "Debugger timeout" and "Launch timeout" to 10 times longer. :) It is much needed unless you have a monster computer with multiple cores and multiple gigs of memory.

To config the debugger, go to Run --> Debug... In the dialog, select "Remote Java Application" from left hand list, then click on the "New" button; now at the right hand pane, give it a meaningful name, check the remote host and port matches JDWP's, then go to the third tab "Common", check "Debug" option in "Display in Favorites menu" so you don't have to open this dialog next time. Click "Debug" button if you are ready, otherwise click "Close" button to save the configuration.

Now the fun part begins. Edit code, run the ant task to deploy, set break point, click on the debug icon, and repeat this cycle.

Monday, May 21, 2007

Eclipse setup for blackberry development

These are proven-to-work steps to setup your eclipse environment for developing Blackberry applications. I hope this post will make somebody's entry into the RIM development easier.

To get started, do the following if you haven't done so:

  1. Download and install Eclipse
  2. Download and install BlackBerry JDE
  3. Download and install Apache ant
  4. Download RAPC ant task jar file
Now let's setup our eclipse environment.
  1. Start your eclipse, switch to a brand-new workspace, for example: c:\RIM\workspace
  2. go to Window --> Preferences --> Java --> Installed JREs, click on "Add" button.
  3. In the dialog, leave the default "Standard VM" option for JRE type;
  4. Type in a "JRE name" as you like, such as 'RIM JRE';
  5. In "JRE Home Directory", navigate to your installed JDK home, such as 'C:\Program Files\Java\jdk1.6.0';
  6. Leave "Default VM Arguments" blank;
  7. Now select all the jar files in "JRE System Libraries", then click "Remove" button to remove all of them; Click "Add External JARs", navigate to you Blackberry JDE installation folder, select lib/net_rim_api.jar, such as 'C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\lib\net_rim_api.jar'.
  8. Click "OK" button to add the new JRE.
  9. Check the checkbox of your newly added JRE to make it the default (Optional: select this JRE, click on "Edit" button to see if the system libraries are still like you set. It happened to me a couple times that eclipse added the jars in JRE home back into the list.)
With the eclipse setup, we are ready to create our first project:
  1. Goto File --> New --> Project, select "Java Project", enter Project Name "HelloWorld", Make sure in the JRE group the "RIM JRE" is selected. In the "Project Layout" group, I prefer to have src and class output into separate folders. Click "Finish" button.
  2. Right click the project, select New --> Folder, create a folder named "lib"
  3. Right click the project, select New --> Folder, create a folder named "resources"
  4. Right click "lib" folder, select "import"; in the dialog, select "general" --> "file system", import the anttask-rapc-1.?.jar you downloaded. Right click the jar file and select "Build Path" --> "Add to Build Path".
  5. Follow the same step to import an icon file in GIF format into "resources" folder. (other image formats work too, we use GIF for demo).
  6. Create a package named "com.mycompany.sample"
  7. Create a class named "HelloWorld.java" in this package and paste these code:
    package com.mycompany.sample;

    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.container.MainScreen;

    public final class HelloWorld extends UiApplication {

    public HelloWorld(){
    super();
    MainScreen screen = new MainScreen();
    screen.add(new LabelField("Hello world!"));
    pushScreen(screen);
    }
    public static void main(String[] args) {
    new HelloWorld().enterEventDispatcher();
    }
    }
  8. Now right click on the project name and create a new file named "build.xml", copy and paste the following code and edit the JRE and RIM JDK pathes accordingly, also search and replace the simulator batch file "8800.bat" to one that exists in your JDE (this ant build script is modified based on a post in Blackberry Java Forum.)

    <?xml version="1.0" encoding="UTF-8"?>

    <project name="HelloWorld" default="buildRIM" basedir=".">

    <taskdef name="rim" classname="com.etaras.anttask.rapc.RAPC" classpath="lib/anttask-rapc-1.8.jar" />

    <property name="jdehome" value="C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1" />
    <property name="javahome" value="C:\Program Files\Java\jdk1.5.0_11"></property>
    <property name="simulator" value="${jdehome}\simulator" />
    <property name="bin" value="${jdehome}\bin" />

    <target name="debug" depends="buildRIM">
    <copy todir="${simulator}" overwrite="true">
    <fileset dir=".">
    <include name="*.cod" />
    <include name="*.debug" />
    <include name="*.csl" />
    <include name="*.cso" />
    </fileset>
    </copy>
    <exec executable="cmd.exe" dir="${bin}" spawn="true">
    <arg value="/c" />
    <arg value="jdwp.bat" />
    </exec>
    </target>

    <target name="simulate" depends="deploy">
    <exec executable="cmd.exe" dir="${simulator}" spawn="true">
    <arg value="/c" />
    <arg value="8800.bat" />
    </exec>
    </target>

    <target name="deploy" depends="buildRIM">
    <copy todir="${simulator}" overwrite="true">
    <fileset dir=".">
    <include name="*.cod" />
    <include name="*.debug" />
    <include name="*.csl" />
    <include name="*.cso" />
    </fileset>
    </copy>
    </target>

    <target name="buildRIM" description="Composes RIM">
    <rim jdehome="${jdehome}" javahome="${javahome}">
    <workspace src="helloworld.jdw" build="true" update="true">
    <cldc src="helloworld.jdp"
    title="HelloWorld"
    vendor="my company"
    version="0.1"
    description="HelloWorld"
    arguments=""
    systemmodule="false"
    runonstartup="false"
    startuptier="7"
    ribbonposition="0"
    output="helloworld"
    options="-quiet"
    update="true">
    <files dir=".">
    <include name="**/*.java" />
    <include name="resources/**/*.*" />
    </files>
    <icons dir=".">
    <include name="resources/**/*.png" />
    <include name="resources/**/*.gif" />
    </icons>
    </cldc>
    </workspace>
    </rim>
    </target>

    </project>

  9. Open a DOS window, change to the directory where you have your build.xml file, type "ant simulate", this task will build the project, deploy it and start the simulator.
  10. Look for the logo you picked for your HelloWorld app and open it, you should see a blank screen displaying "Hello World!". How exciting!
I will write down my experience of debugging applications inside eclipse in the next couple of days.