Monday, 31 December 2007
Monday, 24 December 2007
Sunday, 23 December 2007
Sunday, 16 December 2007
Sunday, 9 December 2007
Saturday, 8 December 2007
SSH access to Joyent
This hopefully the first of a few posts on the general topic of Facebook application development with Java using the free hosting provided by Joyent.
I've setup cygwin for remote access to my joyent account. I followed this tutorial to configure SSH with no password to ease the hassel of logging into the server.
I've setup cygwin for remote access to my joyent account. I followed this tutorial to configure SSH with no password to ease the hassel of logging into the server.
Friday, 7 December 2007
Installing Java JTP into Maven
First download the Java Transaction API
Classes 1.0.1B zip.
And then run this maven command to add the zip to the local repo.
Classes 1.0.1B zip.
And then run this maven command to add the zip to the local repo.
mvninstall:install-file-DgroupId= javax.transaction
-DartifactId=jta
-Dversion=1.0.1B-Dpackaging=jar-Dfile=jta-1_0_1B-classes.zip
Monday, 26 November 2007
cygwin & java classpaths
alias xsl='/cygdrive/c/tools/Java/jdk1.5.0_13/bin/java -server -classpath 'cygpath -wp /cygdrive/c/tools/xalan-j_2_7_0/xalan.jar:/cygdrive/c/tools/xalan-j_2_7_0/xml- apis.jar:/cygdrive/c/tools/xalan-j_2_7_0/xercesImpl.jar:/cygdrive/c/tools/xalan-j_2_7_0/serializer.jar ' org.apache.xalan.xslt.Process -v'
http://narencoolgeek.blogspot.com/2005/07/java-classpaths-on-cygwin.html
Friday, 9 November 2007
Maven OutOfMemory
[javac] The system is out of resources.
[javac] Consult the following stack trace for details.
[javac] java.lang.OutOfMemoryError
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
The solution : MAVEN_OPTS=-Xmx512m
Friday, 21 September 2007
Java Persistence API
Java Persistence API
Trying to get JPA and derby working together with jdk 5 SE.
JPA with a Derby DB
Rehash of the JPA tutorial
Hibernate as JPA provider
Trying to get JPA and derby working together with jdk 5 SE.
JPA with a Derby DB
Rehash of the JPA tutorial
Hibernate as JPA provider
Wednesday, 25 July 2007
java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V
Seems this error happens when running ANT 1.7 and JUnit 3.8.1. The quick solution is upgrade junit to 3.8.X.
The cause as i can make out at this time is this. The junit task in the ant script forks a new jvm which creates a new classloader, this correctly picks up the junit 3.7.1 jar. Between 3.7 and 3.8.1 junit changed the default method name for getting the test name, from name() to getName(). ANT 1.7 in this case, first checks the junit version and then attempts to use reflection to call the correct test name method, but since the Task class has a protected constuctor method and there is a new classloader this IllegalAccessError is thrown.
The method name change is correct, the reflection stuff is correct but the classloader stuff is probally smack.
The cause as i can make out at this time is this. The junit task in the ant script forks a new jvm which creates a new classloader, this correctly picks up the junit 3.7.1 jar. Between 3.7 and 3.8.1 junit changed the default method name for getting the test name, from name() to getName(). ANT 1.7 in this case, first checks the junit version and then attempts to use reflection to call the correct test name method, but since the Task class has a protected constuctor method and there is a new classloader this IllegalAccessError is thrown.
The method name change is correct, the reflection stuff is correct but the classloader stuff is probally smack.
C:\Develop\UIClaims50_PeriodicBuilder\UI\UITools\components\cruisecontrol\projects\build-ant.xml:94: The following error occurred while executing this line:
C:\Develop\UIClaims50_PeriodicBuilder\UI\EJBServer\ant\uiclaims.junit.xml:43: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:541)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:418)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
...
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: C:\Develop\UIClaims50_PeriodicBuilder\UI\EJBServer\ant\uiclaims.junit.xml:43: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
... 16 more
Caused by: java.lang.IllegalAccessError: tried to access method junit.framework.TestCase.()V from class org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl$VmExitErrorTest.(JUnitTaskMirrorImpl.java:80)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl.addVmExit(JUnitTaskMirrorImpl.java:55)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.logVmExit(JUnitTask.java:1446)
Friday, 13 July 2007
Google Syntax Highlighter
I'm just going to outline the three steps that are needed to enable the google syntax highlighter within blogger.com sites. A patched version of the 'shCore.js' script has been made available by Wctang, which corrects Issue 18 : Syntaxhighlighter doesn't work on blogger.com. In your template file
1 : Reference the wctang 'shCore.js'
2: Reference the 'svn/tags/1.5.0' version of the code scripts.
3 : Don't reference the 'SyntaxHighlighter.css'.
The '.dp-highlighter .tools' section needs to be patched to enable the syntax high lighter in firefox. Copy the content of the 'SyntaxHighlighter.css' to your template file, and make sure to update the correct section.
The final result ....
1 : Reference the wctang 'shCore.js'
2: Reference the 'svn/tags/1.5.0' version of the code scripts.
3 : Don't reference the 'SyntaxHighlighter.css'.
The '.dp-highlighter .tools' section needs to be patched to enable the syntax high lighter in firefox. Copy the content of the 'SyntaxHighlighter.css' to your template file, and make sure to update the correct section.
/* Styles for the tools */
.dp-highlighter .tools
{
padding: 3px 8px 3px 10px;
font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
color: silver;
background-color: #f8f8f8;
/* text-align: right; */
padding-bottom: 10px;
border-left: 3px solid #6CE26C;
}
The final result ....
public class HelloSyntaxHighlighter
{
public HelloSyntaxHighlighter()
{
}
private void xx()
{
}
protected boolean static getXX()
{
return null;
}
}
Extending ANT JUnitTask
I needed to run the JUnitTask from code (since i needed to create a custom FileSet for the BatchTest). I started out with a plan Task, but while the code below runs the classpath details that the task uses are incorrect.
I wanted to avoid having to set the classpath in code, so i took another aproach to the issue. I decided my Task would extend from the JUnitTask, this allows me to keep that majority of the task config in xml, and reuse the default handling of classpaths and jvm args.
The xml for this command
public class JunitTestExistsTask extends Task {
private void runAntJUnitTests()
throws BuildException {
try
{
JUnitTask jUnitTask = new JUnitTask();
jUnitTask.setOutputToFormatters(true);
jUnitTask.setProject(getProject());
jUnitTask.setShowOutput(true);
jUnitTask.setFork(true);
FormatterElement formatterElement = new FormatterElement();
TypeAttribute typeAttribute = new TypeAttribute();
typeAttribute.setValue("xml");
formatterElement.setType(typeAttribute);
jUnitTask.addFormatter(formatterElement);
BatchTest batchtest = super.createBatchTest();
File results = new File(getProject().getProperty("dir.test.results"));
batchtest.setTodir(results);
batchtest.addFileSet(createFileSet());
log("runAntJUnitTests --> execute()");
jUnitTask.execute();
}
catch(Throwable e)
{
e.printStackTrace();
throw new BuildException(e);
}
}
}
I wanted to avoid having to set the classpath in code, so i took another aproach to the issue. I decided my Task would extend from the JUnitTask, this allows me to keep that majority of the task config in xml, and reuse the default handling of classpaths and jvm args.
public class JunitTestExistsTask extends JUnitTask {
/**
* Add the test files to a BatchTest and start the JUnit process.
* @throws BuildException
*/
private void runAntJUnitTests()
throws BuildException {
try {
BatchTest batchtest = super.createBatchTest();
File results = new File(getProject().getProperty("dir.test.results"));
batchtest.setTodir(results);
batchtest.addFileSet(createFileSet());
super.execute();
} catch (Exception e) {
throw new BuildException(e);
}
}
}
The xml for this command
name="junitTestsExist"
classname="curam.uic.tools.policing.junit.JunitTestExistsTask"
classpathref="junit.target.cp"/>
Thursday, 14 June 2007
JMockit : Non-public mock class
Running a simple unit test, with the 'new Object()' syntax.
I got this error.
Solution
Use an named class
public void test()
{
Mockit.redefineMethods(emeraldjava.impl.ApplicationCase.class, new Object() {
public void method()
{
System.out.println("JMocked");
}
});
}
ApplicationCaseTest appCase = new ApplicationCaseTest(getName());
assert(appCase.method(),..);
}
I got this error.
java.lang.IllegalArgumentException: Non-public mock class
at mockit.Mockit.collectMockMethods(Mockit.java:182)
at mockit.Mockit.redefineMethods(Mockit.java:170)
at mockit.Mockit.redefineMethods(Mockit.java:124)
at emerabldjava.workflow.ClaimIntakeTest.test2(ClaimIntakeTest.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at junit.framework.TestSuite.runTest(TestSuite.java:173)
at junit.framework.TestSuite.run(TestSuite.java:168)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Solution
Use an named class
public Test extends TestCase
{
public class AppMock
{
public void method()
{
System.out.println("JMocked");
}
}
public void test()
throws AppException, InformationalException, ClassNotFoundException
{
Mockit.redefineMethods(emeraldjava.impl.ApplicationCase.class, new AppMock());
UICApplicationCaseTest appCase = new UICApplicationCaseTest(getName());
assert(appCase.method(),..);
}
}
Sunday, 10 June 2007
Blogger with Google Analytics & Sitemap
Just a couple of quick links to two tutorials on setting your blog (or any website) up with statistics and indexing.
Blogger And Analytics outlines how you can see the hits your site recieves, using Google Analytics.
To ensure that the context of your site is index for the google search engine you should follow the Blogger and Sitemap tutorial, which uses the Google SiteMap.
Blogger And Analytics outlines how you can see the hits your site recieves, using Google Analytics.
To ensure that the context of your site is index for the google search engine you should follow the Blogger and Sitemap tutorial, which uses the Google SiteMap.
Saturday, 9 June 2007
Blogger & Google Code Prettify
I wanted to improve the look of my java source code examples that i have in my blog posts. I came across the google-code-prettify project. The main hassel is the java script and css files need to be included in the blog template. A bit of investigation and i noticed i could link the two required files from the project web site. [Granted, if they change the location of the files we're screwed.]
1: Add the java script file to the blog template.
The complete java script src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js
2: Link the css file to the blog template.
The complete css src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css
3: Update the blog template to call the prettyPrint() function when loaded.
In the blog template file add the call to the prettyPrint() function to the body onload tag.
4: Use the prettyprint command in your blog post.
Links
Duffblog 2.0: Google Code Prettify
1: Add the java script file to the blog template.
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript">
The complete java script src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js
2: Link the css file to the blog template.
<link rel="stylesheet" type="text/css" ref="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css"/>
The complete css src file path : http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css
3: Update the blog template to call the prettyPrint() function when loaded.
In the blog template file add the call to the prettyPrint() function to the body onload tag.
<body onload="prettyPrint();">
4: Use the prettyprint command in your blog post.
<pre class="prettyprint" id="xml">
your code
<pre>
Links
Duffblog 2.0: Google Code Prettify
Wednesday, 6 June 2007
JMockit
The business class we want to test
The object used by the service class
The test class
package emeraldjava.jmockit;
/**
* Service.
*/
public class Service {
public boolean doBusinessWork()
throws Exception
{
Workflow workflow = new Workflow();
if(workflow.startProcess()==1)
return true;
else
return false;
}
}
The object used by the service class
package emeraldjava.jmockit;
public class Workflow {
public long startProcess()
throws Exception
{
return 1;
}
}
The test class
package curam.uic.tools.jmockit;
import junit.framework.TestCase;
import mockit.Mockit;
public class ServiceTest extends TestCase {
public ServiceTest(String name)
{
super(name);
}
public void test()
throws Exception
{
Service service = new Service();
assertEquals("",true,service.doBusinessWork());
}
public void test2()
throws Exception
{
Service service = new Service();
Mockit.redefineMethods(Workflow.class, new Object() {
public long startProcess()
{
return 2;
}
});
assertEquals("",false,service.doBusinessWork());
}
public static class WorkflowMock
{
public long startProcess()
throws Exception
{
throw new Exception();
}
}
public void test3()
{
Service service = new Service();
Mockit.redefineMethods(Workflow.class, WorkflowMock.class);
try
{
service.doBusinessWork();
}
catch(Exception e)
{
assertNotNull("Exception thrown",e);
}
}
}