BowerStudios.com

  • My Lab
  • Family
  • Friends
  • Professional
  • About
Home » The Lab » Programming

Java

Installing JVM Applications on Linux

daniel —Tue, 02/26/2013 - 4:10pm

In my continuing quest to understand and properly use the Linux File System, I've updated the installation location of my java applications (compilers, tools, etc). If you're just doing Groovy development, you may want to look into the gvmtool tool instead as it works quite well. I've held off for now because I want to specify the location of these apps.

An older version of this article goes into greater detail, but doesn't quite use the best file locations. This article should be seen as an update/addition to the previous.

User Installed apps should be installed to /usr/local/lib. I've created symlinks to track the current version that I'm using. I've then installed symlinks in /usr/local/bin to the appropriate executable in /usr/local/lib

Here's a copy of /etc/environment:
#SDKS/COMPILERS
GROOVY_HOME="/usr/local/lib/groovy"
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
SCALA_HOME="/usr/local/lib/scala"
#
#APPS
GROOVYSERV_HOME="/usr/local/lib/groovyserv"
LIQUIBASE_HOME="/usr/local/lib/liquibase"
JASYPT_HOME="/usr/local/lib/jasypt"
#
#BUILD TOOLS
ANT_HOME="/usr/local/lib/ant"
GRADLE_HOME="/usr/local/lib/gradle"
MAVEN_HOME="/usr/local/lib/maven"
#
#FRAMEWORKS
GRAILS_HOME="/usr/local/lib/grails"
GRIFFON_HOME="/usr/local/lib/griffon"
#
#PATH (See also .bashrc)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/lib/groovy/bin:/usr/local/lib/jasypt/bin:/usr/local/lib/scala/bin"

Note that I've added groovy, jasypt, and scala to the path as they have a number of executables with them. Java does as well, but we're letting the os package manager manage it.

/usr/local/bin should then look like this:
22:06:27 daniel@defiant:/usr/local/bin $ ll
drwxr-xr-x 3 daniel daniel 4.0K Feb 26 22:06 ./
drwxr-xr-x 11 root root 4.0K Nov 1 09:39 ../
lrwxrwxrwx 1 root root 50 Feb 26 15:28 apacheDirectoryStudio -> ../lib/apacheDirectoryStudio/ApacheDirectoryStudio*
lrwxrwxrwx 1 root root 33 Feb 26 16:41 clipcomrade -> ../lib/clipcomrade/clipcomrade.sh*
lrwxrwxrwx 1 root root 33 Feb 26 15:32 datacleaner -> ../lib/DataCleaner/datacleaner.sh*
lrwxrwxrwx 1 root root 16 Feb 26 16:16 ggts -> ../lib/ggts/GGTS*
-rwxr-xr-x 1 root root 36 Feb 26 22:03 grails*
-rwxr-xr-x 1 root root 38 Feb 26 22:03 griffon*
lrwxrwxrwx 1 root root 34 Feb 26 15:26 groovyclient -> ../lib/groovyserv/bin/groovyclient*
lrwxrwxrwx 1 root root 34 Feb 26 15:26 groovyserver -> ../lib/groovyserv/bin/groovyserver*
lrwxrwxrwx 1 root root 30 Feb 26 15:36 hermes -> ../lib/HermesJMS/bin/hermes.sh*
lrwxrwxrwx 1 root root 26 Feb 26 15:31 ireport -> ../lib/iReport/bin/ireport*
lrwxrwxrwx 1 root root 42 Feb 26 15:34 java6 -> /usr/lib/jvm/java-6-openjdk-amd64/bin/java*
lrwxrwxrwx 1 root root 26 Feb 26 15:34 liquibase -> ../lib/liquibase/liquibase*
lrwxrwxrwx 1 root root 19 Feb 26 15:39 luke -> ../lib/luke/luke.sh*
-rwxr-xr-x 1 root root 44 Feb 26 22:00 squirrelsql*
lrwxrwxrwx 1 root root 36 Sep 20 10:51 sslCertsForJvmManager -> /code/java/bin/sslCertsForJvmManager/
lrwxrwxrwx 1 root root 21 Feb 26 15:44 umlet -> ../lib/umlet/umlet.sh*

The contents of some of the shell scripts ( where symlink wouldn't work due to path issues)
grails: /usr/local/lib/grails/bin/grails $@
griffon: /usr/local/lib/griffon/bin/griffon $@
squirrelsql: /usr/local/lib/squirrel-sql/squirrel-sql.sh

/usr/local/lib looks like this:
22:12:34 daniel@defiant:/usr/local/lib $ ll
drwxr-xr-x 47 root root 4.0K Feb 26 21:55 ./
drwxr-xr-x 11 root root 4.0K Nov 1 09:39 ../
drwxr-xr-x 11 root root 4.0K Dec 18 22:57 android-sdk-linux_x86/
lrwxrwxrwx 1 root root 16 Sep 18 00:54 ant -> apache-ant-1.8.2/
drwxr-xr-x 6 root root 4.0K Sep 18 00:54 apache-ant-1.8.2/
lrwxrwxrwx 1 root root 50 Sep 18 00:54 apacheDirectoryStudio -> ApacheDirectoryStudio-linux-x86_64-1.5.3.v20100330/
drwxr-xr-x 5 root root 4.0K Sep 18 16:20 ApacheDirectoryStudio-linux-x86_64-1.5.3.v20100330/
drwxr-xr-x 9 root root 4.0K Sep 18 00:54 apache-tomcat-6.0.29/
drwxr-xr-x 9 root root 4.0K Sep 18 00:54 apache-tomcat-6.0.32/
drwxr-xr-x 10 root root 4.0K Dec 12 13:04 apache-tomcat-6.0.36/
drwxrwxr-x 2 root root 4.0K Feb 26 22:01 clipcomrade/
drwxr-xr-x 6 root root 4.0K Feb 26 16:48 DataCleaner/
lrwxrwxrwx 1 root root 18 Feb 26 14:39 ggts -> ggts-3.1.0.RELEASE/
drwxr-xr-x 9 root root 4.0K Feb 26 21:30 ggts-3.1.0.RELEASE/
lrwxrwxrwx 1 root root 10 Jan 30 22:52 gradle -> gradle-1.4/
drwxr-xr-x 9 root root 4.0K Sep 18 00:58 gradle-1.0/
drwxr-xr-x 9 root root 4.0K Sep 18 00:58 gradle-1.2/
drwxr-xr-x 9 root root 4.0K Dec 15 22:37 gradle-1.3/
drwxr-xr-x 9 root root 4.0K Jan 30 22:51 gradle-1.4/
lrwxrwxrwx 1 root root 12 Jan 16 12:05 grails -> grails-2.2.0/
drwxr-xr-x 12 root root 4.0K Sep 18 00:58 grails-1.3.7/
drwxr-xr-x 12 root root 4.0K Oct 19 16:14 grails-2.0.0/
drwxr-xr-x 12 root root 4.0K Sep 18 00:58 grails-2.0.4/
drwxr-xr-x 13 root root 4.0K Sep 18 00:58 grails-2.1.1/
drwxr-xr-x 13 root root 4.0K Dec 7 23:34 grails-2.1.2/
drwxr-xr-x 13 root root 4.0K Jan 16 12:05 grails-2.2.0/
lrwxrwxrwx 1 root root 13 Sep 18 00:58 griffon -> griffon-1.0.0/
drwxr-xr-x 13 root root 4.0K Sep 18 00:58 griffon-1.0.0/
lrwxrwxrwx 1 root root 12 Jan 18 12:16 groovy -> groovy-2.0.5/
drwxr-xr-x 6 root root 4.0K Oct 3 14:28 groovy-1.8.8/
drwxr-xr-x 8 root root 4.0K Sep 24 20:56 groovy-2.0.4/
drwxr-xr-x 8 root root 4.0K Jan 16 13:02 groovy-2.0.5/
drwxr-xr-x 8 root root 4.0K Jan 16 13:02 groovy-2.0.6/
lrwxrwxrwx 1 root root 15 Sep 18 00:58 groovyserv -> groovyserv-0.10/
drwxr-xr-x 4 root root 4.0K Sep 18 00:58 groovyserv-0.10/
drwxrwxr-x 9 root root 4.0K Sep 18 00:58 HermesJMS/
lrwxrwxrwx 1 root root 13 Feb 26 14:40 iReport -> iReport-4.6.0/
drwxr-xr-x 8 root root 4.0K Sep 18 00:58 iReport-3.7.1/
drwxr-xr-x 8 root root 4.0K Sep 18 00:58 iReport-4.0.0/
drwxr-xr-x 8 root root 4.0K Sep 18 00:58 iReport-4.6.0/
lrwxrwxrwx 1 root root 12 Jan 22 12:19 jasypt -> jasypt-1.9.0/
drwx------ 5 root root 4.0K Jan 22 12:18 jasypt-1.9.0/
lrwxrwxrwx 1 root root 15 Dec 16 21:40 liquibase -> liquibase-2.0.5/
drwxr-xr-x 4 root root 4.0K Dec 16 21:45 liquibase-2.0.5/
drwxrwxr-x 2 root root 4.0K Feb 26 21:36 luke/
lrwxrwxrwx 1 root root 11 Sep 18 00:59 maven -> maven-3.0.3/
drwxr-xr-x 6 root root 4.0K Sep 18 00:59 maven-3.0.3/
lrwxrwxrwx 1 root root 17 Sep 18 00:59 scala -> scala-2.8.0.final/
drwxr-xr-x 9 root root 4.0K Sep 18 00:59 scala-2.8.0.final/
lrwxrwxrwx 1 root root 27 Feb 26 14:40 squirrel-sql -> squirrel-sql-3.4.0-optional/
drwxr-xr-x 8 root root 4.0K Sep 18 00:59 squirrel-sql-3.4.0-optional/
lrwxrwxrwx 1 root root 41 Oct 17 23:03 tcserver -> vfabric-tc-server-developer-2.7.2.RELEASE/
lrwxrwxrwx 1 root root 20 Nov 14 16:28 tomcat -> apache-tomcat-6.0.36/
drwxr-xr-x 8 root root 4.0K Feb 26 22:06 umlet/
drwxr-xr-x 10 root root 4.0K Oct 17 23:10 vfabric-tc-server-developer-2.7.2.RELEASE/

These additions to /home/user/.bashrc round out the install:
function alert {
notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e 's/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//')"
play -q /home/user/music/aSound.wav
}
#20121012 Java utility aliases
function mvnr {
mvn properties:read-project-properties "$@"
}
function mvn {
echo 'try mvnr if needing project properties?'
$MAVEN_HOME/bin/mvn "$@"
alert
}
function gradle {
echo 'try gradled for faster gradle startup as daemon'
$GRADLE_HOME/bin/gradle "$@"
alert
}
function gradled {
$GRADLE_HOME/bin/gradle --daemon "$@"
alert
}
function ant {
$ANT_HOME/bin/ant "$@"
alert
}

I've also written more info on using notifiy-send.

  • Groovy
  • Java
  • Read more about Installing JVM Applications on Linux
  • Log in to post comments

Use a Typed Number class in a Spring xml file

daniel —Thu, 02/14/2013 - 11:55pm

I was configuring a bean, and needed to input an integer. Surprisingly it didn't like this
<entry key="port" value="8888" ></entry>

I needed this:
<entry key="port" value="#{new Integer(8888)}" ></entry>

Thanks to axtavt on stackoverflow.com

  • Java
  • Read more about Use a Typed Number class in a Spring xml file
  • Log in to post comments

Look at all the methods and fields used in a jvm .class file

daniel —Thu, 02/14/2013 - 11:32pm

You can look at various bits of info (methods and such) about a class by using:
javap MyClass.class

I used this to discover some info about what version of a class had actually made it to production.

I absorbed this tiny little bit from Charles Nutter's presentation at Codemash 2013 during his "JVM Bytecode for Dummies" session

  • Groovy
  • Java
  • Read more about Look at all the methods and fields used in a jvm .class file
  • Log in to post comments

Reading and Writing to a properties file - Groovy Example

daniel —Tue, 01/22/2013 - 4:57pm

Create the properties object, and load it from the file system:
Properties props = new Properties()
File propsFile = new File('/usr/local/etc/test.properties')
props.load(propsFile.newDataInputStream())

Take a peek:
println props.getProperty('porcupine')

Write a new random value and persist it to the file system:
Integer rand = new Random().next(4)
props.setProperty('porcupine', rand.toString())
props.store(propsFile.newWriter(), null)

Peek again:
props.load(propsFile.newDataInputStream())
println props.getProperty('porcupine')

  • Groovy
  • Java
  • Read more about Reading and Writing to a properties file - Groovy Example
  • Log in to post comments

Download Java from the command line

daniel —Wed, 01/16/2013 - 10:25am

The java download page is a bit annoying in that they require you to accept a license agreement before you can download the executable. This makes it a bit difficult to download via wget on a headless box.

Luckily, stackoverflow comes to the rescue.

  • Linux
  • Java
  • Read more about Download Java from the command line
  • Log in to post comments

Rounding on the JVM

daniel —Mon, 01/07/2013 - 11:46am

My typical method for rounding numbers failed me when accessing an industrial device, and I was puzzled as to why.

BigInteger checksum(final BigInteger checksum, final BigDecimal val){
  return checksum + Math.round(val)
}

What I didn't realize was that there were multiple ways of performing tie breaking when doing rounding. Wikipedia has a nice article defining Tie breaking

I needed to define the Rounding Mode
BigInteger newSum = checksum + val.setScale(0, RoundingMode.HALF_EVEN)

Useful links:

  • This post clued me in as to what to do: Stackoverflow by Grodriguez
  • Rounding Modes
  • BigDecimal.setScale
  • Nice stack overflow post regarding the difference between setScale and round
  • Additional detail on the difference between setScale and round fromaraklefestel referenced by the stack overflow post above
  • Groovy
  • Java
  • Read more about Rounding on the JVM
  • Log in to post comments

Hints for determining the location of cacerts

daniel —Thu, 12/20/2012 - 4:57pm

stackoverflow

  • Groovy
  • Java
  • Read more about Hints for determining the location of cacerts
  • Log in to post comments

HttpSession setMaxInactiveInterval() for a specific user/role with Spring Security

daniel —Thu, 12/20/2012 - 2:32pm

Nice summary of setMaxInactiveInterval by BalusC on stackoverflow

I found it helpful in conjunction with this answer by sourcedelica

The idea being, that we can automatically log users with certain roles out of the application automatically after a certain amount of time.

As implemented in Grails with Spring Security:

Create a class MyAppAuthenticationSuccessHandler:
class MyAppAuthenticationSuccessHandler extends AjaxAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
final Authentication authentication) throws ServletException, IOException {
if(authentication?.authorities){
authentication.authorities.each{ GrantedAuthority grantedAuth ->
if(grantedAuth.authority.equals("ROLE_OPS_USER")){
// For Ops users, timeout after 10 minutes
request.session.setMaxInactiveInterval(10*60)
}
}
}
super.onAuthenticationSuccess(request, response, authentication);
}
}

In resources.groovy:

authenticationSuccessHandler(MyAppAuthenticationSuccessHandler) {
requestCache = ref('requestCache')
defaultTargetUrl = SpringSecurityUtils.securityConfig.successHandler.defaultTargetUrl // '/'
alwaysUseDefaultTargetUrl = SpringSecurityUtils.securityConfig.successHandler.alwaysUseDefault // false
targetUrlParameter = SpringSecurityUtils.securityConfig.successHandler.targetUrlParameter // 'spring-security-redirect'
ajaxSuccessUrl = SpringSecurityUtils.securityConfig.successHandler.ajaxSuccessUrl // '/login/ajaxSuccess'
useReferer = SpringSecurityUtils.securityConfig.successHandler.useReferer // false
redirectStrategy = ref('redirectStrategy')
}

  • Groovy
  • Java
  • Read more about HttpSession setMaxInactiveInterval() for a specific user/role with Spring Security
  • Log in to post comments

More Useful SSL links for the jvm (Java, Groovy, Scala, etc)

daniel —Tue, 12/11/2012 - 10:52am

  • Create and Use Self-Signed Certificates - Particularly this bit (modified for my env) about exporting a key from your keystore, and importing it into the trust store:
    Export the certificate
    keytool -export -rfc -alias tomcat -file tomcat.cer -keystore .keystore -keypass changeit -storepass changeit
    Import the "self" certificate into the truststore
    keytool -import -v -trustcacerts -alias tomcat -file tomcat.cer -keystore /etc/ssl/certs/java/cacerts -storepass changeit
  • Adding self-signed https certificates to java keystore
  • Configure Java to use a specific Truststore
    -Djavax.net.ssl.trustStore="C:\ca.keystore"
    -Djavax.net.ssl.trustStorePassword="password"
  • Groovy
  • Java
  • Read more about More Useful SSL links for the jvm (Java, Groovy, Scala, etc)
  • Log in to post comments

how-do-i-search-for-elements-whose-collection-contains-another-element-in-grails

daniel —Mon, 11/26/2012 - 1:32pm

On StackOverflow

More info about the elements function in the Hibernate docs

  • Groovy
  • Java
  • Read more about how-do-i-search-for-elements-whose-collection-contains-another-element-in-grails
  • Log in to post comments

Pages

  • « first
  • ‹ previous
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • …
  • next ›
  • last »
Subscribe to RSS - Java

Navigation

  • Search
  • Recent content
  • Contact Me
  • Mail
  • Pass Hasher
  • Bower Studios Admin

Quotes

daniel —Mon, 02/26/2007 - 12:19pm

Fish and visitors smell in three days.

  • Log in to post comments
  • daniel's quotes

Popular content

Last viewed:

  • Get the file system sizes of the top n tables in a postgres database
  • Contact Me
  • A note about setting up your network.
  • Using SSL with an IP address instead of DNS
  • Compare two Objects

Copyright 2021 Daniel Bower
  • My Lab
  • Family
  • Friends
  • Professional
  • About