Those guys have ported Quake via GWT to pure HTML and JavaScript. I am pretty sure it will behave well only on WebKit, yet it shows the new approach the web is going, “sadly” without Adobe Flash.
Every now and then I need to use the Velocity templating. And the first thing I always experience is that nasty failure.
SEVERE: ResourceManager : unable to find resource 'template.vm'
in any resource loader.
Exception in thread "main"
org.apache.velocity.exception.ResourceNotFoundException:
Unable to find resource 'template.vm'
...
Velocity is so picky and always complains about the .VM template not being found. And I always start fiddling around, making sure file name is correct, making sure the VM file is right file location, class path location and yet same cruel error ResourceNotFoundException…
The answer for “properly” configuring Velocity and making it happy is bellow:
Properties p = new Properties();
// Uncomment if template.vm is being loaded from file system
//p.setProperty( "resource.loader", "file" );
// absolute or relative path
//p.setProperty( "file.resource.loader.path", "./src" );
//p.setProperty( "file.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.FileResourceLoader" );// Uncomment if "template.vm" is being loaded from class path, jar, zip,..
//p.setProperty( "resource.loader", "class" );
//p.setProperty( "class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" );
VelocityEngine ve = new VelocityEngine();
ve.init(p);
Template t = ve.getTemplate("template.vm");
All said, I am not sure why Velocity team designed it in such a strict way. Instead the engine should be smart enough to find the template directly from Class path location or File resource. Why so difficult?
One year ago I was involved with Selenium as part of a web automated testing project. I discovered multiple limitations with the Selenium framework, mainly with its integration with existing CruiseControl architecture. Having some time lately, I explored the idea of Selenium4j, a framework translating Selenium HTML scripts to Java Junit tests. I hosted to project at
While Selenium IDE is great tool for creating HTML tests, the HTML scripts are not Java tests and as such are not usable outside of the Selenium IDE environment
Using the IDE to create the Java JUnit test works one way only – from HTML to Java. Re-using the java test within Selenium IDE proved to be unreliable and buggy
Using Selenium RC to invoke the HTML files is not practical solution as it allows only a limited configuration such as browser, server and a single suite. E.g.
Reuse the Selenium HTML suites for regression testing
To be able to integrate them within an automated environment (think CruiseControl f.i.)
Make the Selenium HTML tests configurable
WebDriver (Selenium2) solution?
Looking into WebDriver there is no analog of the Selenium IDE. The IDE is an amazing tool for recording the user clicks and it should be great if WebDriver solve the HTML automation integration. It seems that the later version of the IDE (1.0.5 as of writing) provides better support for the new Selenium2 API. Yet, the problem with HTML test integration is still on the table. As long as you record your script and export it to HTML, you are on your own. You need to manually use the IDE to translate the HTML scripts to the desired language (Java in my case), then you need to copy the source, paste it to you Eclipse/Netbeans, make sure compiles, configure it properly. In other words, it’s not fun. WebDriver should provide a solution that simplifies that process and at the end the recorded Selenium IDE script should be seamlessly integrated within an automated environment. In that context, Selenium4j is an example how HTML could be easily translated to a Java JUnit sources.
How does Selenium4j work?
In short Selenium4j translates the HTML tests to Java JUnit tests. It iterates through the HTML suite and tests, digest them and smartly discovers their Selenium commands. Each command is being subsequently transformed to a Java JUnit method. At the end of the transformation the HTML scripts are being translated to Java JUnit sources following same directory(package) structure as the suite and tests. In addition, Selenium4j have suite setup/teardown utilities as well as external configuration.
Interesting. I’ve build few Mathematics Applets 10 years ago. Yet, I can still discover their links on internet. I’ve just found my Spirals Applet being featured at comPADRE – a Physics and Astronomy community site.
Looking for a Maven2 EJB3 ready to run project? I came across this post. I gathered all the good ideas and grouped them together in ejb3-maven Google Code project.
The project consists of three sub-projects - ejb, war and ear.
The changes I’ve made:
Replaced hsqldb with MySQL, featuring out-of-container JPA unit testing.
Replaced TestNG with JUnit4
Encapsulated the repeatable CRUD methods in abstract BaseDAO supertype (code bellow)
Fixed the ejb-api not-found Maven dependency discovery by adding additional repository (ejb-api is not available at default http://download.java.net/maven/2/ so I supplement with additional jboss repository http://repository.jboss.com/maven2/).
Provided sample JNDI utilities helping with session bean discovery
All said, I am looking forward to a complete rails solution where by simply providing the table names, the framework will generate all the ADO classes (in our case JPA DAO classes and entities). Probably this will be my next challenge …
And the sample BaseDao implementation is:
public interface BaseDao<E extends Indexable>{
/**
* Dependency injection setter method.
* The method should be used at unit testing
* during out-of-container DI injection.
*/
void setEntityManager(EntityManager em);
/**
* Persists an instance of this new entity to the database
*/
E create(E entity);
/**
* Returns a database entity using the given primary key ID.
*/
E read(Serializable id);
/**
* Saves changes made to an entity.
*/
E update(E entity);
/**
* Deletes an entity
*/
void delete(E entity);
/**
* Returns all entities of E type. Probably this
* would work best with JPA Criteria..
*/
List list();
/**
* Returns the entity 'E' type to current
* DAO implementation
*/
Class getType();
}
interface Indexable {
/**
* @return the primary key id
*/
Long getId();
/**
* @param id the primary key id to set
*/
void setId(Long id);
}
class BaseDaoImp<E extends Indexable> implements BaseDao<E>{
/**
* The JPA entity manager to be used from all derived DAO classes
*/
@PersistenceContext(unitName = Globals.JTA_PERSISTENT_UNIT)
protected EntityManager em;
/**
* The SessionContext to be used from all derived DAO classes
*/
@Resource
protected SessionContext sc;
/**
* This method should be used only in out-of-container environment
* injecting a NON-"JTA" ("RESOURCE_LOCAL") EntityManager
*/
public void setEntityManager(EntityManager em) {
this.em = em;
}
public final E create(E entity) {
em.persist(entity);
em.flush();
return entity;
}
public final void delete(E entity) {
em.remove(entity);
em.flush();
}
public final E read(Serializable id) {
return em.find(getType(), id);
}
public boolean exists(Serializable id) {
return (null != read(id));
}
public E update(E entity) {
em.merge(entity);
em.flush();
return entity;
}
public List list() {
Query qry = em.createQuery("from " +
getType().getSimpleName());
return qry.getResultList();
}
}
Jboss keep changing their startup files and every time I end up looking for the right spot to attach my JPDA settings. Trying the latest and greatest jboss version 6 I was caught by surprise again searching for the right .bat/.sh file. Damn you JBoss
So to activate JBoss 6 remote debugging:
1. Open ~jboss/bin/run.conf.bat
2. Uncomment the following line: rem # Sample JPDA settings for remote socket debugging
set “JAVA_OPTS=%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n”
3. Go to jboss folder and fire it up. ~jboss6/run.sh
4. Pay attention. the following line should appear: Listening for transport dt_socket at address: 8787
3. Finally go back to Eclipse and attach the debug listener Eclipse / Run / Debug Configurations / Remote Java Application / New
I’ve always wondered why Java 5 was not consistent with @Override annotation type. Today after experiencing the compilation failure again I digged further. The problem:
abstract class Rectangle {
abstract double getArea();
}
// deriving from abstract class
class Square extends Rectangle {
@Overridedouble getArea() {
// ...
}
}
interface Shape {
double getArea();
}
// implementing an interface
class Square implements Shape {
@Override
// Java5 will complain about @Override
// "method does not override a method from its superclass"double getArea() {
// ...
}
}
Java compiler will complain about @Override being used yet no such method in parent “method does not override a method from its superclass”? Well, the compiler is wrong as there is such method in parent, but instead of a superclass it is a supertype of an interface.
I write this blog to talk about my adventures and achievements in software development of Java, Ajax, Web, Javascript, Databases as well as my thoughts and experiences in personal-development.