Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

Springframework provides lots of ways to inject values into your code. What do you do when you need access to a value of something contained in a .properties file. This is so easy, but I rarely use it and always forget how to use it. This is how you define a properties:

<util:properties id="commonProperties" location="classpath:common-dev.properties"/>

The contents of the properties file is:

hostUrl=my.host.com

To inject it into a class:

    @Value("#{commonProperties.hostUrl}")
    private String hostUrl;

March 14th, 2014

Posted In: Java, Spring

Tags: , ,

Leave a Comment

I found a very useful link
http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/

I added the following to my .profile and typed setjdk 1.7 at the command prompt. Problem solved.

function setjdk() {  
  if [ $# -ne 0 ]; then  
   removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'  
   if [ -n "${JAVA_HOME+x}" ]; then  
    removeFromPath $JAVA_HOME  
   fi  
   export JAVA_HOME=`/usr/libexec/java_home -v $@`  
   export PATH=$JAVA_HOME/bin:$PATH  
  fi  
 }  
 function removeFromPath() {  
  export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")  
 }

I have the following JDKs setup on my Mac with OSX 10.10.5 in /Library/Java/JavaVirtualMachines.

drwxr-xr-x  3 root  wheel  102 Jul 14 17:52 1.6.0.jdk
drwxr-xr-x  3 root  wheel  102 Jul  2 20:01 jdk1.8.0_45.jdk
drwxr-xr-x  3 root  wheel  102 Nov 13  2014 jdk1.8.0_25.jdk
drwxr-xr-x  3 root  wheel  102 Oct 28  2013 jdk1.7.0_45.jdk

As you can see from the following, it does work

dimac0001:~ norrisshelton$ setjdk 1.6
cdimac0001:~ norrisshelton$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468-11M4833)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$ setjdk 1.7
cdimac0001:~ norrisshelton$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$
cdimac0001:~ norrisshelton$ setjdk 1.8
cdimac0001:~ norrisshelton$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Go to the Oracle JDK download page to get the latest version of java. The page is currently located at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

March 3rd, 2014

Posted In: Bash, OS/X

Tags: , , ,

Leave a Comment

The benefit of having a local Maven repository is that only one developer suffers the delay of the network traffic requests to repo1. If you have a local maven repository and your developers have mirrors setup in their settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>artifactory</id>
            <mirrorOf>*</mirrorOf>
            <url>http://artifactory.cdinteractive.com:8080/artifactory/repo</url>
            <name>Artifactory</name>
        </mirror>
    </mirrors>
</settings>

March 3rd, 2014

Posted In: Maven

Tags: , , , , ,

One Comment

LinkedIn Auto Publish Powered By : XYZScripts.com