Thursday, 12 May 2016

Setting a proxy for the JVM

Use system properties:
-Dhttp.proxyHost=212.100.20.77 -Dhttp.proxyPort=8080 -Dhttps.proxyHost=212.100.20.77 -Dhttps.proxyPort=8080
Be careful that this affects all requests on this JVM and in particular can affect internal requests. localhost and 127.0.0.1 are included as nonProxy requests by default, and you can add further internal hosts as needed. Specific app/library specific control should be used where possible. Full details are here

Tuesday, 10 May 2016

Gradle Wrapper

Using the Gradle wrapper means that the initiator doesnt need Gradle installed locally and also ensures that the correct version of Gradle is always used. To setup a project with the wrapper
> gradle wrapper
All projects have this target (but dont run in child projects) To use the wrapper
> gradlew
This will then install Gradle locally, for example in USER_DIR/.gradle/wrapper

Source control

It is recommended you should put the generated files into source control.
  • gradlew
  • gradlew.bat
  • gradle

Proxy

> gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3128
Seemed to use https by default

Proxy settings in windows

To use a proxy from the windows command prompt, set the following env variables:
> set http_proxy=a.b.c.d:1111
> set https_proxy=a.b.c.d:1111
These will only be active for this 'session'. Note that many command-line apps will still need proxy settings configured directly (eg - Gradle)

Friday, 29 April 2016

YAML for config

Played about with YAML today using it instead of a properties file in a java command line application (a data loader).

It is more flexible than a property file (it can do nesting and arrays) but is less verbose and more readable than JSON or XML so is a great fit for configuration. It copes better with more complicated config and will be more future proof for an app.

I used the snakeyaml which is very lightweight and supports binding to a java object.

1. Import dependency

compile 'org.yaml:snakeyaml:1.17' 

2. Create a simple java bean configuration class

3. Load file and map to configuration class

Config cfg = new Yaml().loadAs(is, Config.class);

Hello world!

The inaugral hello world test!