JDriven Blog

Grails Goodness: Using Wrapper for Running Grails Commands Without Grails Installation

Posted on by  
Hubert Klein Ikkink

Since Grails 2.1 we can create a Grails wrapper. The wrapper allows developer to run Grails commands in a project without installing Grails first. The wrapper concept is also available in other projects from the Groovy ecosystem like Gradle or Griffon. A wrapper is a shell script for Windows, OSX or Linux named grailsw.bat or grailsw and a couple of JAR files to automatically download a specific version of Grails. We can check in the shell scripts and supporting files into a version control system and make it part of the project. Developers working on the project simply check out the code and execute the shell script. If there is no Grails installation available then it will be downloaded. To create the shell scripts and supporting files someone on the project must run the wrapper command for the first time. This developer must have a valid Grails installation. The files that are generated can then be added to version control and from then one developers can use the grailsw or grailsw.bat shell scripts.

$ grails wrapper
| Wrapper installed successfully
$

Continue reading →

Quickly experiment with AngularJS (and Jasmine) using these Plunks

Posted on by  
Emil van Galen

When experimenting with AngularJS features I often create a so-called Plunk on http://plnkr.co/. Although this site provides built-in templates for AngularJS, I found it useful to create my own since:

  • The “1.0.x (stable)” / “1.0.2 + Jasmine” templates use old versions of AngularJS;
  • “1.0.2 + Jasmine” template solely outputs Jasmine results but no AngularJS content.

Continue reading →

How to create (singleton) AngularJS services in 4 different ways

Posted on by  
Emil van Galen

Next to creating controllers and directives, AngularJS also supports “singleton” services. Services, like on the server-side, offer a great way for separating logic from your controllers. In AngularJS anything that’s either a primitive type, function or object can be a service. Although the concept of service is quite straight forward, the declaration of them in AngularJS isn’t:

  • There are 4 different ways to declare a service.
    • Registering a existing value as a service
    • Registering a factory function to create the singleton service instance
    • Registering a constructor function to create the singleton service instance
    • Registering a service factory which can be configured
  • Only 1 of them is extensively documented

Continue reading →

Grails Goodness: Set Property Values of Spring Beans in resources.groovy

Posted on by  
Hubert Klein Ikkink

We can configure Spring beans using several methods in Grails. We can for example add them to grails-app/conf/spring/resources.xml using Spring’s XML syntax. But we can also use a more Groovy way with grails-app/conf/spring/resources.groovy. We can use a DSL to define or configure Spring beans that we want to use in our Grails application. Grails uses BeanBuilder to parse the DSL and populate the Spring application context. To define a bean we use the following syntax beanName(BeanClass). If we want to set a property value for the bean we use a closure and in the closure we set the property values. Let’s first create a simple class we want to configure in the Spring application context:

// File: src/groovy/com/mrhaki/spring/Person.groovy
package com.mrhaki.spring

import groovy.transform.ToString

@ToString
class Person {
    String name
    Date birthDate
}

Continue reading →

Grails Goodness: Injecting Grails Services into Spring Beans

Posted on by  
Hubert Klein Ikkink

One of the underlying frameworks of Grails is Spring. A lot of the Grails components are Spring beans and they all live in the Spring application context. Every Grails service we create is also a Spring bean and in this blog post we see how we can inject a Grails service into a Spring bean we have written ourselves. The following code sample shows a simple Grails service we will inject into a Spring bean:

// File: grails-app/services/com/mrhaki/sample/LanguageService.groovy
package com.mrhaki.sample

class LanguageService {

    List<String> languages() {
        ['Groovy', 'Java', 'Clojure', 'Scala']
    }

}

Continue reading →

Auto inject dependencies in JUnit using Mockito

Posted on by  
Sjoerd Schunselaar

While writing unit tests, you often have to mock dependencies like services or controllers. Often  a constructor is used to autowire the dependencies as shown in the example below. In the Test class I instantiated the ContactService using a contactRepository Mock object

@Service
public class ContactServiceImpl implements ContactService {

private final ContactRepository contactRepository;

    @Autowired
    public ContactServiceImpl(final ContactRepository contactRepository) {
    this.contactRepository = contactRepository;
    }

    public void saveContact(final Contact contact) {
    contactRepository.save(contact);
    }
}

Continue reading →

Compare JAR files content; decompiling class files

Posted on by  
Willem Cheizoo

When I was recently working on a large restructuring and refactoring where I also replaced Ant by Maven, it was really necessary to compare the complete content of two different JAR files. It was required to know that the result of the restructuring and refactoring hadn't changed the artifacts, thus the JAR files. In the JAR files were different Class files present. When I compared the content of the two JAR files (with a binary compare) all the content was radically changed. This was partly because the compiler compiled the Class files at a different timestamp.

Since I wanted the best possible comparison between the two JAR files I needed to compare all Class files in the JAR by decompiling and comparing. This should give me a clearer and more honest picture of the differences. For this action I used Beyond Compare. By using an additional File Format (Java Class to Source) I was able to completely compare the decompiled Class files of the two JARS.

Continue reading →

Using URL Scheme for Telephone Numbers in HTML

Posted on by  
Hubert Klein Ikkink

We can use the tel: URL scheme for phone numbers in HTML. Just like the mailto: URL scheme will open the default mail application will the tel: start a telephone call. If the HTML page is viewed on a mobile phone and we select a link with the tel: scheme we can immediately call the number following the scheme. On a desktop computer a VOIP call will be initiated.

We can use hyphens in the phone number for readability, they will be ignored when the call is made. For example the imaginary phone number 123456789 in the Netherlands can be used as shown in the following HTML snippet:

Continue reading →

javax.xml.bind.JAXBException: "package" doesn't contain ObjectFactory.class or jaxb.index

Posted on by  
Albert van Veen

Once in a while we have those small issues which still can take some hours of our day. For example last week I was configuring a Spring JAXB2Marshaller using the context below: <bean id="jaxb2Marshaller"> <property name="contextPaths"> <list value-type="java.lang.String"> <value>nl.jdriven.myproject.package.with.a.very.long.name </value> <value>nl.jdriven.myproject</value> </list> </property> </bean> However when running my JUnit test using this context the following exception occurred:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jaxb2Marshaller' defined in class path resource \[test-savings-online-direct-export.xml\]: Invocation of init method failed; nested exception is org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: " nl.jdriven.myproject.package.with.a.very.long.name
                                                  " doesnt contain ObjectFactory.class or jaxb.index

Continue reading →

The Quick & Dirty Fraud

Posted on by  
Arthur Arts

If you have a car, then every once in a while, you probably have your vehicle checked to see if it's still up to safety and environmental standards. So you take your car to the garage and have it checked. Now, the garage will do some tests and eventually you'll get a nice paper showing what kind of maintenance they have done.

Nowadays, cars are complex, computerized machines. (The days of dad lying under the car to do some fixing with some elemental tools are all but gone.) This means that as a customer, you will have to rely on the professional capabilities and integrity of the garage. You'll have to trust that if the garage says the car is fixed and okay, it really is fixed and okay. Now imagine that you went to the garage, received the paper that your car is okay, go on the road, and your car breaks down. What would be your reaction? You'd probably hold the garage responsible for this, as they are the experts and you paid them to do a good job. What would your reaction be if they told you that they didn't have time to correctly solve your cars problems and did a 'quick fix', without them telling you?

Continue reading →

shadow-left