Thursday, July 3, 2014

Setting "java.library.path" programmatically

Requirement:

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:
http://blog.vogella.com/2010/07/27/osgi/


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.out.println(file.getAbsolutePath());
System.setProperty("java.library.path", file.getAbsolutePath());
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


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

Resources:
http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/
http://fahdshariff.blogspot.in/2011/08/changing-java-library-path-at-runtime.html

Generate java classes from xsd using JAXB

We can use JAXB to do this job.

More info:
https://jaxb.java.net/

JAXB bundles with JDK kit from 1.6 onwards.

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

Example:
C:\Program Files\Java\jdk1.6.0_30\bin>xjc D:\Modules\functionalModules.xsd
parsing a schema...
compiling a schema...
generated\FunctionalModule.java
generated\FunctionalModules.java
generated\ObjectFactory.java

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

Friday, May 16, 2014

Removing untracked files from local git branch

We can use git clean command to remove all untracked files from your local working branch.
> git clean -f

This will remove all untracked files forcefully.

To remove even the untracked directories which are present in the local branch.
>git clean -f -d



Wednesday, May 7, 2014

ObjectAid UML eclipse plug-in for UML class diagrams

You can download from:

Update site:

Repository ZIP file:

What all you can do with this ?
Class diagrams - Free
Sequence diagrams – Commercial license required

Get started:

How good is this ?
I found it’s very simple and clean tool without any hassles. You need to get started with one class and keep adding the references, it will build the class diagram nicely based on the references it has.

What is not possible ?
1.       I don’t see a way to generate class diagram for whole plug-in
2.       I don’t see a way to generate class diagram for bunch of classes/package at a time.
3.       Relationships is not so clear.
4.       I don’t find a way to create a new relationship or modify the existing one.








Tuesday, May 6, 2014

Eclipse is too slow, they try out these options

Are you feeling your eclipse is slow ? And, is it taking lot of time to open your eclipse ?

Based upon my experience I have put down some points that would help you out.

1.       Try to open your eclipse in clean mode.
    Command:  > eclipse –clean

What is does ?
Cached data used by the OSGi framework and eclipse runtime will be wiped clean. This will clean the caches used to store bundle dependency resolution and eclipse extension registry data. Using this option will force eclipse to reinitialize these caches.

http://www.eclipsezone.com/eclipse/forums/t61566.html

2.       Configuring suitable heap memory size in eclipse.ini file. Verify max heap size parameter (Xmx) and configure based on the application need.
Example:  -Xmx1024M

This is where your java objects will be stored.

3.       Make sure to configure sufficient permgen size in eclipse.ini file. Configure based on the your application need.
  
 Example: -
-XX:PermSize=256m
-XX:MaxPermSize=512m

This is where you classes and method definitions will be loaded after starting your application

4.       Close unnecessary projects in your workspace.
Example: You might have 10 plug-ins in your eclipse current workspace, but you might be using or working on only 2 plug-ins, and that work independent of other plug-ins.

5.       Try to avoid force closing eclipse.  It takes lot of time to initialize the previous state of eclipse based on the history indexes.

6.       Don't enable all third-party code enforcement tools by default.

Example:
  • Find bugs - run based upon need.
  • Google code analytics
  • Check style

 7.       You can remove Project build automatically option in eclipse and enable only based on the need.

8.  Remove automatic updates for eclipse plug-ins and third party plug-ins.
    You can find “Automatically find new updates and notify me” option in your eclipse.

8.       Once in a while try to switch all your plug-ins/projects in to new workspace and work.


As a programmer:
  • Don't keep so much of code in your Activator start() methods
  • Minimize the number of classes in the each plug-in
  • Don't run too many background processes in your application.
  • Don't create too many threads at a time. Make sure no.of threads should be less than or equal to number of processor cores in the system.


java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM


This problem occurs when we are trying to load 32 bit swt libraries (ex: swt.jar) on 64 bit Java

Example: When you are trying to open your 32 bit eclipse with 64 bit JRE, you will be facing this issue.

Another case would be, you would have packaged 32 bit swt libraries with your application, but you are trying to run your application on 64 bit JRE.

How to resolve ?
Make sure you will be using the same version either 32 bit/64 bit for eclipse and Java.


Error:
java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:197)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:174)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
at org.eclipse.ui.internal.Workbench.createDisplay(Workbench.java:687)
at org.eclipse.ui.PlatformUI.createDisplay(PlatformUI.java:161)
at org.eclipse.ui.internal.ide.application.IDEApplication.createDisplay(IDEApplication.java:145)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:88)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)

Finding a .log file in eclipse

Your .log file is located in a .metadata folder in your current workspace directory.
The following is the path if you are working on the default workspace.

Example:

Windows : C:\Users\username\Documents\<Studio Workspace>\.metadata\.log

Mac OS X: ~/Documents/<Studio Workspace>/.metadata/.log