- Go to {path-to-Eclipse-installation}\configuration\.settings
- Open the file “
org.eclipse.ui.ide.prefs” using any text editor
- Look out for the property “RECENT_WORKSPACES” which stores the paths to the workspaces currently in use, each separated by ‘\n’ (for example, C\:\\eclipse-workspaces\\customer1\nC\:\\eclipse-workspaces\\customer2\nC\:\\eclipse-workspaces\\customer3\nC\:\\eclipse-workspaces\\customer4)
for a setup similar to
eclipse-workspaces
- customer1
- customer2
- customer3
- customer4
- To add a workspace, add the full path (preceded by a ‘\n’) to the end. To remove a workspace, remove the path any trailing ‘\n’
The above has been tried out and works for Eclipse 3.4.2, 3.5, 3.5.2
If ever you find yourself in a similar situation,
BUILD FAILED
C:\work\build.xml:188: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to “C:\java\jre\6″
Ensure the following:
- Ensure that
JAVA_HOME is set
- Ensure that
JAVA_HOME does not end with ‘bin’ – if it does, then ANT will not work as it will look for tools.jar under “{JAVA_HOME}\lib“
- On command prompt, type
SET JAVA_HOME={Full path to JDK install} (for example, C:\java\jdk\160_16)
3120 bytes to be precise.
I had access to code which instantiated 3 java.text.SimpleDateFormat objects per method call.
I recently came across simple yet effective instrumentation to query the size of a Java object, javamex. Using it, I found that each instance of java.text.SimpleDateFormat has a deep memory usage of 3120 bytes! In comparison, a 3 character String, say, “ABC” has a deep memory usage of 48 bytes.
This article suggests using an instance of the java.text.SimpleDateFormat per thread by making use of the java.lang.ThreadLoca class.
After referring to two articles online (which you can read here & here), I made some modifications to the code and sure enough, I no longer face the earlier problems related to memory usage.
Some excerpts. I created a per-thread Singleton, DateUtil.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| public class DateUtil
{
private static SDF1 sdf1 = new SDF1();
private static SDF2 sdf2 = new SDF2();
// Returns the SimpleDateFormat object
// for the date pattern "ddMMMyyyy".
public static SimpleDateFormat getSimpleDateFormat_ddMMMyyyy() {
return (SimpleDateFormat) sdf1.get();
}
// Returns the SimpleDateFormat object
// for the date pattern "EEE dd MMM yyyy".
public static SimpleDateFormat getSimpleDateFormat_EEE_dd_MMM_yyyy() {
return (SimpleDateFormat) sdf2.get();
}
// A ThreadLocal subclass for the SimpleDateFormat
// for the date pattern "ddMMMyyyy"
private static class SDF1 extends ThreadLocal<SimpleDateFormat> {
public SimpleDateFormat initialValue() {
return new SimpleDateFormat("ddMMMyyyy");
}
}
// A ThreadLocal subclass for the SimpleDateFormat
// for the date pattern "EEE dd MMM yyyy"
private static class SDF2 extends ThreadLocal<SimpleDateFormat> {
public SimpleDateFormat initialValue() {
return new SimpleDateFormat("EEE dd MMM yyyy");
}
}
} |
In the older code which previously instantiated a java.text.SimpleDateFormat object, I replaced it with the following,
1
2
3
| SimpleDateFormat travelDateFormat = DateUtil.getSimpleDateFormat_ddMMMyyyy();
Date date = travelDateFormat.parse(strToParse);
//where, strToParse is a String similar to "31Jan2010" |
Here’s something that worked for me after having spent several hours on it. First the relevant part of the build.xml file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <copy todir="${build.dir}${file.separator}schemaSrc">
<fileset dir="${schemas.dir}">
<include name="*.xsd"/>
<include name="*.xsdconfig"/>
</fileset>
</copy>
<path id="xmlbeans.path">
<fileset dir="${lib.dir}/xmlbeans">
<include name="xbean.jar"/>
<include name="jsr173_1.0_api.jar"/>
</fileset>
</path>
<property name="xmlbeans.compiler" value="javac1.5"/>
<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpath="${toString:xmlbeans.path}" />
<xmlbean schema="${build.dir}${file.separator}schemaSrc"
destfile="schemas.jar"
srcgendir="${build.dir}"
debug="on"
classpath="${toString:xmlbeans.path}"
javasource="1.5"
/> |
A sample .xsd file,
1
2
3
4
5
6
7
8
9
10
11
12
13
| <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Employee">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SSN" type="xsd:string"/>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="DateOfBirth" type="xsd:date"/>
<xsd:element name="EmployeeType" type="xsd:string"/>
<xsd:element name="Salary" type="xsd:long"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema> |
A sample .xsdconfig file,
1
2
3
4
5
| <xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
<xb:namespace uri="##any">
<xb:package>com.acompany.xsd</xb:package>
</xb:namespace>
</xb:config> |
Very trivial Java code to get the dates in a window around a specified date (i.e., X days before and Y days after a specified date). The dates are returned as strings of a configurable format.
For example, to get the dates 2 days before and 1 day after 25Dec2009, the returned String[] contains the Strings “23Dec2009“, “24Dec2009“, “25Dec2009“, “26Dec2009“. In this example, I chose to use “ddMMMsyyyy” format, so the date strings look similar to 25Dec2009.
Calling The getDatesAround Method
1
2
3
4
5
6
7
8
| SimpleDateUtil util = new SimpleDateUtil();
final String pattern = "ddMMMsyyyy";
try {
util.getDatesAround(util.constructDate( pattern, "25Dec2009"), 2, 1, pattern);
util.getDatesAround(util.constructDate( pattern, "14Feb2010"), 4, 1, pattern);
} catch (ParseException e) {
e.printStackTrace();
} |
Calling the getDatesAround method to get the dates 2 days before and 1 day after 25Dec2009, the returned String[] contains the Strings “23Dec2009″, “24Dec2009″, “25Dec2009″, “26Dec2009″.
And now, the source code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| public Date constructDate(String pattern, String dateString) throws ParseException {
dateFormatter.applyPattern(pattern);
return dateFormatter.parse(dateString);
}
public String[] getDatesAround(Date centredDate, int numDaysBefore, int numDaysAfter, String pattern) {
int totalNumDays = ((numDaysBefore > 0) ? numDaysBefore : 0) + 1 + ((numDaysAfter > 0) ? numDaysAfter : 0), pos = 0;
String[] dateStrings = new String[totalNumDays];
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
// Get a Date object, which we will be using for manipulations
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(centredDate);
Date dateObj = cal.getTime();
long time = dateObj.getTime();
// Constructing the date Strings before the centredDate
if (numDaysBefore > 0) {
time = dateObj.getTime();
for (int i = numDaysBefore; i > 0; i--) {
dateObj.setTime(time - oneDayInMillis * i);
dateStrings[pos] = sdf.format(dateObj);
pos++;
}
}
// centredDate
dateStrings[pos] = sdf.format(centredDate);
dateObj.setTime(centredDate.getTime());
pos++;
// Constructing the date Strings after the centredDate
if (numDaysAfter > 0) {
for (int i = pos; i < totalNumDays; i++) {
time = dateObj.getTime();
dateObj.setTime(time + oneDayInMillis);
dateStrings[i] = sdf.format(dateObj);
}
}
return dateStrings;
} |
Assuming you’d need to create a calendar (or 2) in order to add in some text for specific dates, you’d probably want to create your own calendar using a simple HTML table and few lines of Javascript and later (depending on what additional text you want to display), you could add in some jQuery code to access the cells for the specific dates and modify their contents.

1
2
3
4
| //Some constants
var monthLabels = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var daysOfWeek = new Array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
The function below, takes the following parameters:
monthId = 1 or 2, month = 0 to 11, year = 2009 and above
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| function constructCalendarTable(monthId,month,year)
{ var dateObj = new Date(); dateObj.setDate(1); dateObj.setMonth(month); dateObj.setYear(year);
var dow_theFirstOfMonth = dateObj.getDay();
//Get the maximum number of days in current month
var maxDaysIntheMonth = daysInMonth[month];
if(month == 1) { if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){ maxDaysIntheMonth = 29; } }
//Creating the table
var calmonthtd = $("#calmonth"+monthId+"td");
var caltable = $("<table>").attr("align","center"); caltable.appendTo(calmonthtd);
//Creating the label row
var rowRMonthLabel = $("<tr>").attr("align","center"); rowRMonthLabel.appendTo(caltable);
var rowRMonthLabelCell = $("<td>").attr("colspan","7").text(monthLabels[month]+", "+year);
rowRMonthLabelCell.appendTo(rowRMonthLabel);
//Creating the rest of the rows
var rowR = $("<tr>"); rowR.appendTo(caltable);
var dayOfMonthCounter = 0;
for (var i=1;i<50;i++)
{ if(i%7==1) { rowR = $("<tr>"); rowR.appendTo(caltable); }
var cellR = $("<td>").attr("id","calmonth"+monthId+"d"+i);
if(i<=7)
{ //Populating the days' headers
cellR.addClass("calhdr").text(daysOfWeek[i-1]);
}
else
{ //Populating the days
var dayOfWeek = (i%7);
if(dayOfWeek==dow_theFirstOfMonth && dayOfMonthCounter==0) { dayOfMonthCounter=1; cellR.text(dayOfMonthCounter).addClass("calday"); }
else if(i<=49 && dayOfMonthCounter>=1 && dayOfMonthCounter<maxDaysIntheMonth) { dayOfMonthCounter++; cellR.text(dayOfMonthCounter).addClass("calday"); }
else
cellR.text("").addClass("calnonday");
}
cellR.appendTo(rowR);
}
} |
[Update Dec 9, 2009]
I have used this code in one of my pet projects, http://cheapflightsearch.appspot.com/
Java code to split up a cAmelCaSe string by using the uppercase characters as the separators. For example, aBcDe into a_b_c_d_e.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| private String convertCamelCaseString(String camelCaseString, String optionalSeparator) {
int n = camelCaseString.trim().length();
StringBuilder sb = new StringBuilder(n * 2);
for (int i = 0; i < n; i++) {
char c = camelCaseString.charAt(i);
int x = (int) c;
// A=65, N=78, Z=90, a=97
// See http://blossomassociates.net/ascii.html
if(optionalSeparator==null) optionalSeparator="";
if (x >= 65 && x <= 90) { // Converting to lower case
c = (char) (x + 32);
sb.append(optionalSeparator).append(c);
} else
sb.append(c);
}
// Final string converted from camelCaseString
String convertedString = sb.toString();
sb = null;
return convertedString;
} |
In my code, there is a Struts 2 ActionSupport subclass passing a List of Item objects to a form, to be used to populate a Struts 2 Select tag.
The relevant part of the form, is
<s:form action="someAction" method="POST">
<s:select label="Associate This With Item"
name="itemId"
list="items"
listKey="id"
listValue="title"
value="%{items.{title}}"/>
<s:submit type="button" value="Associate" />
</s:form>
Here, the Item object’s title attribute is being displayed and upon form submit, the id attribute of the selected Item object is passed to the backend. This is specified by using the listValue and listKey parameters respectively.
Form used to update an entity, involving a radio button.
<s:form action="editSomethingAction" method="POST">
<s:radio name="moduleStateSelected" key="label.state"
list="#{1:'Draft', 2:'Published'}"
value="%{module.state}" />
<s:submit value="Update" align="right"/>
</s:form>
The form parameter moduleStateSelected takes in the value of the state attribute of an object of the Module class, passed by the Struts 2 action.
The related code in the Struts 2 ActionSupport subclass,
public class SomeWebAction extends ActionSupport {
private Module module;
public Module getModule() {
return module;
}
public void setModule(Module m) {
this.module = m;
}
//.. other methods not listed here
}
And, relevant code of the Module class,
public class Module {
private short state;
public short getState() {
return module;
}
public void setState(short newState) {
this.state = newState;
}
//.. other methods not listed here
}
I have a Struts 2 action with getter/setter methods for 3 attribute, say, name, id and an object of a class Question (which has a string attribute, questionText, which I want to access in the form).
I somehow forgot how to access the attributes to be used as the default values in a form, so after a bit of searching old code, here’s what it should look like:
<s:form action="editSomethingAction" method="POST">
<s:hidden name="id" value="%{#parameters['id']}" />
<s:hidden name="name" value="%{#parameters['name']}" />
<s:textarea name="questionText" label="" rows="3" cols="80" value="%{question.questionText}"/>
<s:submit value="Update" align="right"/>
</s:form>