Saturday, April 6, 2013

Random Eclipse Tips

  • User Library - You can label a bunch of jars as a one user library and just import that one library in all your projects and servers without having to worry about adding the same jars in all places. You can also export library to a file like you would export a playlist. One nice feature is that you can also define source jar for each jar, so wile debugging you can actually see the source. You also get access Javadoc and that makes development so much easier.
  • svn:ignore - Do you have some files or directories in your project that you don't want to sync with the repositorty? Just right click on that file go to Team > Add to svn:ignore

Thursday, March 10, 2011

MySQL 5.5 Installation / Uninstallation Troubleshooting

Problem: MySQL Instance Configuration: Service fails to start or Security Settings cannot be applied.

Blunt but working solution: 

  1. Uninstall MySQL and MySQL tools.
  2. Restart the computer. 
  3. Delete MySQL Data folder. Typically at C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.5/Data/
  4. Delete MySQL folder from Program Files
  5. Re-install MySQL and MySQL tools
Problem: MySQL command line tool can connect to localhost but MySQL Query Browser other third party tools cannot.Also, MySQL command line tool cannot connect to!

By default MySQL (5.5 version on Windows XP) binds to "localhost"  (somehow is not same as localhost) and it will accept connections only from localhost.
Since the OS would convert localhost to automatically, other programs are unable to connect. 
(MySQL command line client might be functioning differently Because it can connect using localhost as host name.)

If you want MySQL port to listen on all interfaces add this setting to your my.ini file

Setups in general may fail if  a registry or file system resource is not accessible due to security restrictions.
I typically secure the Auto Run registry entries and some drives on my machine.

Sunday, December 20, 2009

Spring annotations static injection tutorial

I found this interesting code snippet to initialize static properties of a class using Spring IoC

public class UserUtils
  private static UserAccessor userAccessor;

   * Sets the rule DAO. This method should never be called except by Spring
   * @param userAccessor The user accessor to set
  @Autowired(required = true)
  public void setUserAccessor(userAccessor UserAccessor) {
    UserUtils.userAccessor = userAccessor;

Friday, December 4, 2009

MySQL: Export Table

C:\>mysqldump -hlocalhost -P3307 -uroot -ppass --tables gis places > c:/x.sql

This would export table structure and data for table named places from schema named gis
you can export multiple tables by providing list of table names instead of just one in this example
C:\>mysqldump -hlocalhost -P3307 -uroot -ppass gis  > c:/y.sql

This would export all tables in schema gis
C:\>mysql -hlocalhost -P3307 -uroot -ppass myschema < c:/x.sql

This would import the data into schema named myschema
Export schema objects without data
C:\>mysqldump -hlocalhost -P3307 -uroot -ppass --tables --no-data myschema > c:/myschema_script.sql

C:\>mysql -hlocalhost -P3307 -uroot -ppass myschema  < c:/myschema_script.sql

Monday, November 30, 2009

Incorporating GWT into your project structure

GWT Release: 1.7.1

Problem: I wanted to use GWT in one of my project. I first played around with a fresh project generated using the eclipse plugin for GWT. All went well until I decided to integrate it into another project I already had.
Now this old project was a "Dynamic Web Project" which has a different folder structure than a GWT plugin created project.

GWT comiler puts all output in a "war" directory directly under project dir (MyProject/war)
Since all the JS and other artifacts generated are under this directory, they are not accessible from the browser when the Dynamic Web Project is run on server.

The trick to make it work is to write a customized Ant build file which would put the gwt generated files into WebContent (the base directory of a deployed web app which  holds WEB-INF etc) instead of "war" folder.

Actually you don't even have to write a build file, just modiy one created by webAppCreator

To create a template application run the following command:

webAppCreator -out MyApplication com.mycompany.MyApplication

This would create standard GWT files including build.xml

Now import files into your existing project as follows:
Say your project's name is MyProject
MyApplication.gwt.xml > src/com/mycompany/
x/y/ > src/x/y/
build.xml > MyProject/
put other files like htmls and css scripts at appropriate places in WebContent

Now add this line in the gwtc and hosted mode tasks to override the default location for GWT compiler:output.
<arg line=" -war WebContent"/>

  <target name="gwtc" depends="javac"  description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="">
        <pathelement location="src"/>
        <path refid="project.class.path"/>
      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
      <jvmarg value="-Xmx256M"/>
      <jvmarg value="${XstartOnFirstThreadFlag}"/>
      <jvmarg value="${d32Flag}"/>
      <arg line=" -war WebContent"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg value="com.mycompany.MyApplication"/>


  <target name="hosted" depends="javac" description="Run hosted mode">
    <java failonerror="true" fork="true" classname="">
        <pathelement location="src"/>
        <path refid="project.class.path"/>
      <jvmarg value="-Xmx256M"/>
      <jvmarg value="${XstartOnFirstThreadFlag}"/>
      <jvmarg value="${d32Flag}"/>
      <arg line=" -war WebContent"/> 
      <arg value="-startupUrl"/>
      <arg value="MyApplication.html"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg value="com.mycompany.MyApplication"/>

Run the build target. It should generate Java > JS files and other GWT artifacts in a new folder under WebContent. In this case it is myapplication

Now run the hosted target in build.xml. The hosted browser should now run without a hitch!!

You may also want the run application on server the way you normally the application on the server (Run As> Run on Sever)

Instead of firing a build every time, you can automate this process by going the project menu and adding the Ant build task in Builders