Monday, March 26, 2012

How to obtain Xalan and Xerces's version numbers from their jars?

Both Xerces and Xalan has a utility class that reports its version number:

java -cp ./xerces.jar org.apache.xerces.impl.Version
java -cp ./xalan.jar org.apache.xalan.Version

Thursday, November 24, 2011

How to fix GWT 2.3.0's No source code is available for type ; did you forget to inherit a required module?

To fix the following error (or similar errors) when doing a mvn clean compile on a GWT 2.3.0 app:

[ERROR] Errors in 'jar:file:/C:/Documents%20and%20Settings/myfolder/.m2/repository/com/google/gwt/gwt-user/2.3.0/gwt-user-2.3.0.jar!/com/google/gwt/editor/client/EditorDriver.java'
[ERROR] Line 97: No source code is available for type javax.validation.ConstraintViolation; did you forget to inherit a required module?


Ensure that you have the following validation-api jar and validation-api-sources jar in your pom.xml file (OUTSIDE of the gwt-maven-plugin dependencies in your pom.xml):


< dependency >
< groupId >javax.validation< /groupId >
< artifactId >validation-api< /artifactId >
< version >1.0.0.GA< /version >
< scope >provided< /scope >
< /dependency >
< dependency >
< groupId >javax.validation< /groupId >
< artifactId >validation-api< /artifactId >
< version >1.0.0.GA< /version >
< classifier >sources< /classifier >
< scope >provided< /scope >
< /dependency >

Tuesday, September 13, 2011

Adding 'cmd.exe' onto the Windows context menu

Manually add the context menu

In explorer, open Tools, Folder Options.
Select the File Types tab.
For Windows XP: Go to NONE / Folder.
For Windows 2000: Press n to scroll to the N/A section.
For Windows NT/98/95: Press f to scroll to the Folders section.
Select the entry labeled Folder
For Windows 2000/XP: Press Advanced button.
For Windows NT/98/95: Press Edit button.
Select New
In the action block type "Command Prompt" without the quotes.
In the app block type "cmd.exe" without the quotes.
Save and exit Folder Options.
Now right click on Start, you should have a new drop down option. Open explorer and right click on a folder, select Command Prompt and a command window opens in that folder.

Wednesday, July 21, 2010

Setting tomcat in debug mode

To set Tomcat in debug mode:
1. Run {catalina_home}/bin/tomcat6w.exe
2. In Java tab, add the following lines to Java options:

-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y


Thats it!

Thursday, May 20, 2010

m2eclipse (Maven 2 Eclipse Plugin) does not resolve project dependencies in Eclipse Ganymede/Eclipse Gallileo workspaces

This has bitten me too many times in the arse that I have finally decided to write myself a wiki on how to resolve this issue.

Reproducable on
---------------
Eclipse 3.4 Ganymede
Eclipse 3.5 Gallileo


Issue
------
Maven does not resolve all the dependencies and add the jar files in the workspace.


How to Resolve
----------------
1. Ensure that the following tags is in your .classpath file in your project (ensure that you have your JRE classpathenry above your maven classpathentry - exactly like the following):
< classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/ >
< classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/ >

2. Right click on your Project and navigate to Build Path -> COnfigure Build Path
3. In the 'Libraries' tab, click on 'Add Library' and click on 'Maven Managed Dependencies'
4. Click on the 'Maven Project Settings' link on the next window and ensure that the 'Resolve Dependencies from Workspace projects' is enabled.
5. Then, click on Windows -> Preferences -> Maven
6. Ensure that the 'Support multuple Maven modules mapped to a singe Eclipse workspace project' is enabled.
7. In that Maven dialog box, also ensure that 'install' is written in the 'Goals to run on project import:' textbox.
8. Now, right click on your Project and navigate to Maven
9. Ensure that the following are visible:
Disable Workspace Resolution
Disable Nested Modules
Disable Dependency Management
(The above three options mean that they are currently enabled. If, for example, it says 'Enable Nested Modules' rather than 'Disable Nested Modules', click on it to enable it.
10. Clean your project and build it.
11. Walla! You should see all your dependency jar files in the Maven Dependencies folder on your workspace. You can right click on your project -> Maven -> Update dependencies just to be sure too.

Friday, May 14, 2010

Checking security settings for each Windows user

To check the security settings for all your Windows users, go to:

gpedit.msc > "Local Computer Policy" > "Computer Configuration" > "Windows Settings" > "Security Settings" > "Local Policies" > "User Rights Assignment" >

Friday, January 29, 2010

Embedded jetty version problems in Eclipse

Issue:

In my project, I was getting maven to download two dependencies:
1.
< dependency >
< groupId >org.mortbay.jetty< /groupId >
< artifactId >jetty-embedded< /artifactId >
< version >6.1.9< /version >
< /dependency >


2. < dependency >
< groupId >org.openqa.selenium.client-drivers< /groupId >
< artifactId >selenium-java-client-driver< /artifactId >
< version >0.9.2< /version >
< /dependency >


Looking at the dependency tree for the selenium codebase, I found that the org.mortbay.jetty version number used in Selenium 0.9.2 was 5.1.0. Hence, Eclipse defaults to using Jetty API 5.1.0 for rather than 6.1.9 - causing my code (which needs Jetty 6.* to be marked as an error in Eclipse).


How to Resolve It?
-------------------------
Use Selenium 1.0.1:
< dependency >
< groupId >org.seleniumhq.selenium.client-drivers< /groupId >
< artifactId >selenium-java-client-driver< /artifactId >
< version >1.0.1< /version >
< /dependency >

This Selenium version uses Jetty 6.1.6. Hence, your project code (that needs Jetty 6.*) will be resolved correctly by Eclipse.

Tuesday, December 15, 2009

How to increase the heap size available to a JUnit Test Class in Eclipse?

If your running a JUnit Test on Eclipse, do the following to increase the heap size available for it:
1. Click on 'Run' and 'Open Debug Dialog'
2. Click on 'JUnit' on the left pane of the window
3. Enter a name for the JUnit test
4. Fill up all the relevant details in the 'Test' tab
5. Click on the 'Arguments' tab
6. In 'VM arguments', type the following:
-Xmx1024M

Monday, November 2, 2009

Getting the attributes of an OpenLayer.Feature.Point that has been clustered in a OpenLayers.Layer.Vector layer

I encountered this problem and spent a day trying to understand how it worked. I have figured it out and am sharing my understanding with everyone.

Issue
------------
I had a GeoJSON parser that parsed the following geojson file:

{
"type": "FeatureCollection",
"features": [
{"type":"Feature", "id":"computer1", "properties":{"trial":"test"}, "geometry":{"type":"Point", "coordinates":[143, -35.91]}},
{"type":"Feature", "id":"computer2", "properties":{"trial":"test"}, "geometry":{"type":"Point", "coordinates":[144, -37.81667]}}
]
}

Once the GeoJSON parser parsed the file and created 2 OpenLayer.Feature.Points, these points were parsed to the OpenLayers.Layer.Vector object that implemented the clustering strategy.

Now, since the two points were within a close distance (specified by me), they were clustered and only one top level feature point was displayed on the map.

I wanted to get the 'id' and 'properties' (as in the GeoJSON file above) of each of the two points (when I zoomed into the map). However, I could not get it. It seemed to me, back then, that the GeoJSON parser had somehow overriden the properties I added into the "properties":{} field (in the above geojson file) with the 'count' property of the clustering Vector layer.

Hence, the question was, how do I get the attributes and ID of each point in the map (as in the geojson file).


Fix
----
feature.cluster solved the problem.

For other users who come across this problem, try to get the attributes of a point (specified in the geojson file in the 'properties' list) by using
feature.cluster[0].attributes.

Basically, this is what happens when the geojson fileabove is parsed by OpenLayers.Format.GeoJSON parser and added as OpenLayers.Vector.Feature objects into a OpenLayers Vector layer (that performs the clustering strategy):
1. GeoJSON file is read by the GeoJSON parser.
2. Parser creates OpenLayers.Vector.Feature objects for each string.
3. These OpenLayers.Vector.Feature objects are then added to the OpenLayers Vector layer
4. OpenLayers Vector layer performs clustering strategy
5. Each feature point that appears on the map is the top-level feature point (for a group of clusters). The attributes for this feature point is:

undefinedlayer value :[object Object]
lonlat value :null
data value :[object Object]
id value :OpenLayers.Feature.Vector_201
geometry value :POINT(15918687.18122222 -4288244.5663272375)
state value :null
attributes value :[object Object]
style value :null
cluster value :[object Object],[object Object],[object Object] //this indicates that this cluster point has three feature objects underneath it
renderIntent value :select
marker value :null

6. As it can be seen above, there is a 'cluster' property that holds 3 objects (being the three points). Hence, if you drill down to the 'cluster' property (i.e. feature.cluster[0]), it will give you the attributes of the first object in the cluster (being the point):

undefined0 value :[object Object]
layer value :null
lonlat value :null
data value :[object Object]
id value :OpenLayers.Feature.Vector_197
geometry value :POINT(8218510.393273033 -2699238.272071229)
state value :null
attributes value :[object Object]
style value :null
fid value :computer14
marker value :null

7. From the above, it can be seen that the 'id' property from the geojson file has been mapped to the 'fid' key of the feature point object. You can also see that the 'attributes' key holds an [object Object]. If you do feature.cluster[0].attributes.trial , it will display the 'trial' property and value that you specified in the geojson file (i.e. 'test').

Hence, adding as many property-value pairs in the GeoJSON file is easy as the GeoJSON parser just parsers the property-value pairs and enters the data into feature point object attributes that are beneath the top-level cluster point (it does not override the properties as I initially thought).

Friday, October 30, 2009

Printing Javascript object properties

If you would like to print out all the properties of an Javascript object and their associated values, do this:

Note: Replace < objName > below with the name of your instantiated object.

var str;

for(prop in < objName >)
{
str += prop + ' value :' + < objName >[prop]+ '\n ';
}

alert(str); //Show all properties and its value

Friday, October 16, 2009

Resolving the Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/gwt/dev/GWTCompiler(Unsupported major.minor version 48.0)

When I tried compiling my GWT project using TestProject-compile.cmd, I got the following exception:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/google/gwt/dev/GWTCompiler (Unsupported major.minor version 48.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)



How To Resolve This?

Ensure that your JRE version in your environment variable in anything from Version 1.4 and above.
To check your Java version, pull up comman prompt and type in the following on the command line to check your JRE version:
java -version

Since I had Oracle installed, my "Path" environment variable was referencing 2 Oracle JVM's that were versions 1.1.3 and 1.1.8. I deleted these two paths and ensured that JVM path in the environment variable was pointing to the folder where I had installed Java 1.6.

This worked and did not cause the UnsupportedClassVersionError exception to be thrown anymore.

Tuesday, October 13, 2009

How to print output on the same line on the console in Java?

Trying to continuously print output onto the same line in a console using Java?

Try this:
System.out.print("TEST TEXT\r");

The "\r" (carriage return) character returns the cursor to the beginning of the output line.

Just remember that if you do System.out.print("TESTTEXT\r"); and then System.out.print("BLAH\r");, your final output will be
BLAHTEXT

This is because the remaining characters from the longest string are not deleted after the shorter string overwrites it. Hence try to do something like this to delete of all characters from the longest string:
System.out.print("TESTTEXT\r"); //write text and go back to beginning of line
System.out.print(" \r"); //have many empty spaces to overwrite the chars from the longest string and then go back to the beginning of the line
System.out.print("BLAH\r"); //write text and go back to the beginning of the line

This will output:
BLAH

Monday, October 12, 2009

Internet Information Services - Setting Up Access Permissions for Specific Windows Users to Access Specific FTP Virtual Directories

To set up the Windows IIS FTP Server to allow certains Windows users to access certain virtual directories, ensure that you have done the following:
1. Install an IIS FTP Server
2. Ensure that you have a Windows User account set up for the user you want to log on as, onto your FTP Server.
3. In the 'Default FTP Site Properties', uncheck the 'Allow Anonymous Connections' checkbox which can be found under the 'Security Accounts' tab. This will allow specific users that have the right username and password of one of the Windows user accounts on the FTP Server machine to access the FTP Virtual Directories.

Once Step 1 and 2 above is set up, permissions to specific FTP Virtual Directories can be set up as follows:
3. Right click on the virtual directory you have created (eg. CHITRATEST). Below this Local Path textbox, there are three checkboxes (Read, Write and Log Visits). You can uncheck/check these boxes. Think of these boxes as three different pipes. Clogging a pipe (i.e. unchecking a say, 'Write' checkbox) will cause all Windows users who log on to the FTP Server to not have Write permissions to CHITRATEST, regardless of whether the folder on the local path of the virtual directory (e.g. c:\TEST) has 'Write' permission enabled for the currently logged in Windows Users.
4. Once the FTP Server evaluates the super access priviledges it can give to a currently logged Windows user (by evaluating the checkboxes in Step 3 above), it will then evaluate the next level folder properties of the virtual directory. If say, C:\TEST is mapped to a virtual directory called CHITRATEST, the Security permissions set on C:\TEST and C:\Inetpub\ftproot\CHITRATEST will both be evaluated to give the currently logged Windows user specific permissions. Both C:\TEST and C:\Inetpub\ftproot\CHITRATEST must have the exact permissions set/unset for folder level permissions to be evaluated by the FTP Server.

Summary
-------

To allow users with the username and password of a specific Window User account to access the FTP server, follow Steps 1 and 2.

To allow specific logged on Windows users (with a corresponding Windows User account) to gain access permissions to specific virtual directories, follow Step 3.

To allow a lower level folder access permission for logged on Windows users, follow Step 4.

Why does a file on a Windows machine have different timestamps on different Windows machines?

I have a program (which runs on a Windows machine) that gets a list of files and their corresponding timestamps from a remote Windows machine.

On the 4th of Oct (the day when Daylight savings triggered of a 1.59am to 3am time change in Melbourne, Australia), my program returned a null value when retrieving the last modified timestamp of a file that was created at 1.21am that day.

What puzzled me was that although the file was created at 1.21am (which was recorded within the contents of the file), the last modified timestamp was 2.21am. When I uploaded this file across to a machine that had the Windows option "Automatically Adjust for Daylight Saving Time" turned off, it had a last modified time of 1.21am.

After reading up on http://www.peterdonis.net/computers/computersarticle3.html and http://support.microsoft.com/kb/129574 , I finally realised why the last modified timestamp of the file on a Windows machine was different to the timestamp when it was actually created:

On Windows, if you are in a location that observes DST (Daylight Savings Time) and the DST time change kicks in, the timestamps on all files on the Windows NT file system (NTFS) are shifted by an hour. Even the files that were created BEFORE the daylight saving time change are shifted. So basically, the timestamps of ALL files created ANYTIME before 4/10/2009 1.59am will have one hour added to it.

As stated on the Windows Help and Support page, "All times displayed in Windows NT for event log events and files on NTFS partitions are computed as offsets to Greenwich Mean Time (GMT). When you set the time on your system, you are setting the value for GMT. When you select your local time zone for the system, the appropriate number of hours are added or subtracted to the stored GMT value. This adjusted time is displayed. When "Automatically Adjust for Daylight Saving Time" is selected, an additional hour is added to GMT during daylight savings time (the first Sunday in April through the last Sunday in October)." In other words, manually changing the system time does not affect file timestamps but when the local time zone is changed, all file timestamps will be adjusted to display the new zone time.

Friday, September 25, 2009

Postgres 8.3 error: Internal account lookup failure: no mapping between account names and security IDs was done

If you have encountered this error on a Windows XP machine, check to see if your machine name in the 'Account Domain' field (in the PostgreSQL installer GUI) is correct.

If you are pulling up the GUI through the command line which has the servicedomain='' parameter, your 'Account Domain' field will be populated to have the value ''. This is obviously erroneous because of the single quotes in the value.

It would be best to not specify the servicedomain='' parameter. Postgres usually pre-fills the 'Account Domain' field correctly.

Monday, September 21, 2009

SimpleDateFormat parse error - from 12pm to 12am

I got this error today, only to find out that it was a very simple code error that I overlooked.

The Error
-----------

I have a SimpleDataFormat parser to parse a date string variable to a required format:

String time = "Mon Sep 21 2009 12:56:02";
SimpleDateFormat df= new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss");
Date parsedDate = sdf.parse(time);

However, a System.out.println("parsedDate = " + df.format(parsedDate )); gives me a 00:56:02 time and not a 12:56:02 time.


Reason for error
-----------------
In the SimpleDateFormat class, formatting hour in HH will return a hour between 00-23 (i.e. in 24 hour format) while formatting hour in hh will return a hour between 01-12 (12 hour format). - a good source code to look at is http://www.java-examples.com/formatting-hour-using-simpledateformat

Ensure that your SimpleDateFormat class has been instantiated this way:
SimpleDateFormat df= new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss");

Wednesday, September 16, 2009

What is a Windows lmhosts file?

lmhosts stands for LAN Manager Hosts file. This host file is called 'hosts' and can be found in C:\WINDOWS\system32\drivers\etc

To put it very simply, it is a file that maps IP addresses to the NetBIOS host names of the machines. For example, write this into your hosts file:
192.168.1.1 Test-Machine

Hence, when 'Test-Machine' is pinged, it will be translated to '192.168.1.1' without needing to check your DNS.

Friday, July 24, 2009

Windows SYSTEM user

I have a program that copies files from one machine to another over a network. It uses port 445 (called the SMB port - SMB is a protocol for sharing files between computers in a network).

When I ran this program in MS DOS, the remote folder in which the remote files are in was recognised as a directory (i.e. dir.isDirectory() = true). However, when I ran this program from Windows Services, the remote folder was not recognised as a directory.

The reason for this was because of the user under which the program is ran. When it was run in MS DOS, the current Windows user (Administrator) was running the program. Hence, it had access priviledges to read/write the remote folder.

However, as the Windows Services process is controlled by System User, when the program was run in Windows Services, the program was run under the SYSTEM user, disallowing it to have access priviledges over the remote folder.

Basically, although a SYSTEM user is higher than an administrator and has full control of the OS and kernel, it cannot access remote systems. It is just for a local system.

To ensure that the program is run under the current Windows user (Administrator), you will need to set up the program's properties in services.msc. Click on the Properties of the program, then on the 'Log On' tab. Here, ensure that you log on as 'This Account' (type in your current Windows Administrator username and password) and NOT as 'Local System Account'.

This will allow the program (running as a Windows Service) to copy files over a network as it will be running under the current user. You can check the username it is running under by going to your Task Manager.

Thursday, July 23, 2009

Basic PostgreSQL Must-Know's

1. String concatenation using the PL/pgSQL language is done like this:

declare
split_table_name text[];
v_PK text;
v_Query text;

v_Query := 'select ' || v_PK || ' from ' || split_table_name[1];


2. To run the above query string variable (i.e v_Query), use the EXECUTE statement like this:

declare
result text;

EXECUTE v_Query into max_num_str ;

or

EXECUTE 'select ' || v_PK || ' from ' || split_table_name[1] into max_num_str ;

Advanced PostgreSQL Queries

All Postgres users, like it or not, will need to retrieve information about the tables, triggers, sequences etc that they have in their databases. The following are some of the things you might want to query:

1. What constraints does my table have?


select pgc.relname as "TableName", pc.conname as "ConstraintName",
contype as "ConstraintType", conkey as "KeyCols",
confkey as "ForeignCols", consrc as "Src"
from pg_class pgc, pg_constraint pc
where pgc.oid = pc.conrelid
and relname = '< tablename >';


2. How to get the column name of the primary key of a table?

select column_name from information_schema.key_column_usage where constraint_name IN
(
select c.conname as "ConstraintName"
from pg_class r, pg_constraint c
where r.oid = c.conrelid
and contype = 'p'
and relname = '< tablename >' );


3. What triggers are on my table?

select pc.relname as "Table", pt.tgname as "TriggerName",
pt.tgconstrname as "ConstraintName", pt.tgenabled as "Enabled",
pt.tgisconstraint as "IsConstraint", pcc.relname as "ReferencedTable",
pp.proname as "FunctionName"
from pg_trigger pt, pg_class pc, pg_class pcc, pg_proc pp
where pt.tgfoid = pp.oid and pt.tgrelid = pc.oid
and pt.tgconstrrelid = pcc.oid
and pc.relname = '< tablename >';


4. What indexes are on my table?


select * from pg_indexes where tablename = '< tablename >';


More Advanced PostgreSQL Queries can be found here:
http://www.thegeekstuff.com/2009/05/15-advanced-postgresql-commands-with-examples/