Thursday, July 31, 2014

Wednesday, July 16, 2014

Executing batch file through Java

Batch file has to perform below actions.

1. Change the directory for a given path
2. start the node sever
3. Exit the command window

>cd D:\nodev0.18
>node app.js console

FileName: Myfile.bat
Batch file defined with variable arguments like below.

cd %1
%2 app.js console

Java code for invocation:
String executePath = "cmd /c start Myfile.bat"

Executing windows commands through java

I wanted to start the node server programmatically.
>node app.js

Using Java:

String executePath = "cmd /c start node app.js"


Removing eclipse view title bar tab

public class Perspective implements IPerspectiveFactory {
  public void createInitialLayout(IPageLayout layout) {      
    String editorArea = layout.getEditorArea();

    layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea);      

A standalone view's title can optionally be hidden. If hidden, then any controls typically shown with the title (such as the close button) are also hidden. Any contributions or other content from the view itself are always shown (e.g. toolbar or view menu contributions, content description).


Thursday, July 3, 2014

Setting "java.library.path" programmatically


I have 6 dll files in my eclipse plug-in under lib/win64 folder. I wanted to load them dynamically during the launch of eclipse.

I have tried the eclipse way of bundling native-code in the plugin manifest, but somehow i could not achieve. So I have to go by manipulating the system path.

Eclipse bundle-native code mechanism:

try {
     //eclipse call
Bundle bundle= getBundle();
URL fileUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path("/"), null));
String location = fileUrl.getFile();
String libPath = location + "lib/win64";
File file = new File(libPath);
System.setProperty("java.library.path", file.getAbsolutePath());
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
} catch (NoSuchFieldException e) {
} catch (SecurityException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (IOException e) {

The Classloader has a static field (sys_paths) that contains the paths. If that field is set to null, it is initialized automatically. Therefore forcing that field to null will result into the reevaluation of the library path as soon as loadLibrary() is called


Generate java classes from xsd using JAXB

We can use JAXB to do this job.

More info:

JAXB bundles with JDK kit from 1.6 onwards.

You can find a service called 'xjc' in the <jdk directory>/bin folder.

C:\Program Files\Java\jdk1.6.0_30\bin>xjc D:\Modules\functionalModules.xsd
parsing a schema...
compiling a schema...

Java classes will be generatd with in the 'generated' folder of java bin directory.