How to install jshell via Homebrew

At the time of this writing, Java 9 is in beta. I installed because I wanted to check out jshell, Java’s new REPL (read-evaluate-print-loop). On top of the below, I brew-installed jenv (a must for managing different JDK versions).


$ brew install Caskroom/versions/java9-beta
$ jenv add /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
$ jenv shell oracle64-9-ea
$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+102-2016-01-21-003129.javare.4316.nc)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+102-2016-01-21-003129.javare.4316.nc, mixed mode)
$ jshell
|  Welcome to JShell -- Version 9-ea
|  Type /help for help

-> "Hello JDK 9!"
|  Expression value is: "Hello JDK 9!"
|    assigned to temporary variable $1 of type String

I also did the following to get jshell to work:

1. Added to ~/.bash_profile


eval "$(jenv init -)"

2. Added my hostname in /etc/hosts


amp-macbook    127.0.0.1

Cheers, and enjoy learning lambdas!

SpringBoot: Making use of @Value properties from YAML files for Cucumber tests

In case you use:
1. SpringBoot to build your web applications using Java
2. Test it with Cucumber
3. Use YAML files for configurable property values

You can use the YamlPropertiesFactoryBean to make use of @Value for your test configuration.

application.yml:


myapp:
  base:
    url: some_url

cucumber.xml (or application context .xml):


<context:component-scan base-package="cucumber.runtime.java.spring"/>
    <context:annotation-config/>

    <bean id="yamlProperties"
          class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
        <property name="resources" value="classpath:application.yml"/>
    </bean>

    <context:property-placeholder properties-ref="yamlProperties"/>

Java code (snipped):


@ContextConfiguration(locations = {"classpath:cucumber.xml"})
public class TestSteps {

    @Value("${myapp.base.url}")
    private String baseUrl;
...

The spring bean, yamlProperties, will take care of all the necessary wiring, so all you have to do is make use of the @Value annotation. The benefit of this is you can create properties for various environments (in your YAML file) and be able to automate running your tests against any environment using spring profiles.

Hope this helps.