Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, December 10, 2012

JDK Installation - Ubuntu Distribution

1) Download the bin file from http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html (JDK 5.0 Update 13, Linux self-extracting file) to /usr/local/ or another directory.

Change permisions using chmod.
chmod +x jdk-1_5_0_12-linux-i586.bin

2 ) Then we need to configure JAVA

We have 2 options here, use the console or a GUI.

A) Console approach.

sudo update-alternatives --install /usr/bin/java java /home/psabbate/dev/java/jdk1.7.0_XX/bin 70

Command: update-alternatives 
Installation Param: --install
Link Path: /usr/bin/java
Link Name: java
JDK Path: /home/psabbate/dev/java/jdk1.7.0_XX/bin
Priority: 70 (The higher, the best)
Then execute
sudo update-alternatives --config java

B) GUI approach

Use galternatives

sudo aptitude install galternatives
sudo galternatives

Search “java” and go to the JDK directory.

3 ) Enviroment Variables:

Please Edit
sudo vi /etc/bash.bashrc:

Add at the bottom of the file
export JAVA_HOME=(JDK Path)
export PATH=$JAVA_HOME/bin:$PATH

Wednesday, October 17, 2012

How do I run a batch file from my Java Application?

Sometimes we want to run a batch file from our Java Application. This batch could be either a .bat file or a .sh file, it depends on which operating system are we using.

After some research ... I created a class that do the job.

Basically, we have 4 parameters.


  • programAbsolutePath: Where is the batch file to execute?
  • parameters: Which are the parameters of the batch file?
  • environmentVariables: If you want to override some environment variables
  • baseDirectory: Which will be the base directory of the batch?. This could be usefull when the batch file use relative paths in its process.

This class only executes batches for unix/windows. If you want to use it in other Operating Systems you should specify which are the execution path (like EXEC_WINDOWS and EXEC_UNIX constants)

That's all.

Friday, August 10, 2012

How to inject Spring properties using annotations?


I started to change a couple of projects from xml configuration to annotations and it wasn't trivial.
One of these items was the injection of properties using annotations.

First of all, we need a property configurer


The configuration file is a common property file.

application.title = My Application Title

In my case, I want to define a configuration bean, so I put in one place all the configurations. But you can use the same approach injecting the properties in your specific beans.

Hope it help you ...