26 Mar 2013

How to fix the PermGen Space (Out of Memory) Error in Eclipse

Problem: PermGen Space (Out of Memory)

Cause: PermGen is the permanent generation of objects in the VM (Class names, internalized strings, objects that will never get garbage-collected).
The memory limit is too small that the Eclipse quickly runs out of memory, causing the aforesaid error.

Solution: Increase the permanent generation space available to Eclipse by adding the following in eclipse.ini
-XX:MaxPermSize=256m

-vm C:\Program Files\Java\jdk1.7.0_15\jre\bin\server -startup plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502 -product org.eclipse.epp.package.jee.product --launcher.defaultAction openFile --launcher.XXMaxPermSize 256M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 256m --launcher.defaultAction openFile -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms40m -Xmx512m -XX:MaxPermSize=256m

21 Mar 2013

java.lang.NullPointerException: A null service reference is not allowed.

Problem: When trying to get a service from the BundleContext, NullPointerException is found.

public class Activator implements BundleActivator { ServiceReference helloServiceReference; public void start(BundleContext context) throws Exception { System.out.println("Hello World!!"); helloServiceReference= context.getServiceReference(HelloService.class.getName()); HelloService helloService =(HelloService)context.getService(helloServiceReference); System.out.println(helloService.sayHello()); } public void stop(BundleContext context) throws Exception { System.out.println("Goodbye World!!"); context.ungetService(helloServiceReference); } } org.osgi.framework.BundleException: Exception in com.javaworld.sample.helloworld.Activator.start() of bundle com.javaworld.sample.HelloWorld. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381) at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:389) at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1131) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544) at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340) Caused by: java.lang.NullPointerException: A null service reference is not allowed. at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:586) at com.javaworld.sample.helloworld.Activator.start(Activator.java:20) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711) at java.security.AccessController.doPrivileged(AccessController.java:251) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702) ... 12 more

Cause:

  1. The ServiceReference can be null if no HelloService is registered, resulting in NullPointerException on line 6.
  2. The HelloService object cannot be got, due to missing permissions, possible timing issues if the HelloService unregisters between lines 5 and 6, causing NullPointerException on line 6.
  3. The HelloService may have become unusable, resulting in any RuntimeException subclass, most likely IllegalStateException on line 6.

Solution: Use ServiceTracker instead.

References

  1. OSGi Service

Missing Constraint: Import-Package: org.osgi.framework

Figure 1: Missing Constraint: Import-Package
Problem: When running a configuration to run a bundle, error message is shown.
Missing Constraint: Import-Package: org.osgi.framework;version="1.3.0"
Solution: Include the bundle in the "Run Configuration".
Figure 2: Add Bundles

13 Mar 2013

Missing XDoclet library in Eclipse

Problem: The XDoclet library is missing in Eclipse
Figure 1: Missing library: xdoclet
Solution: Go to http://sourceforge.net/projects/xdoclet/files/xdoclet/1.2.1/ and download the zip xdoclet-lib-1.2.1.zip. Unzip it somewhere on your pc and in eclipse point the XDoclet Home to the extracted directory which contains all the jar files. Click apply to save the change.
Figure 2: Library Found

8 Mar 2013

Fix the warning in Structured Data Testing Tool: Missing required field "updated"

To fix the Warning: Missing required field "updated" in Structured Data Testing Tool:
  • Blogger
    1. Go to Dashboard - Template
    2. Backup the template
      1. Click the "Backup/Restore" button.
      2. Click the "Download Full Template" button.
      3. Click the "Close" button.
    3. Edit the template
      1. Click the "Edit HTML" button.
      2. Check the box next to 'Expand Widget Templates'. Find the following code:
        <a class='timestamp-link' expr:href='data:post.url' rel='bookmark' title='permanent link'> <abbr class='published' expr:title='data:post.timestampISO8601' itemprop='datePublished'> <data:post.timestamp/> </abbr></a> Add "updated" to the class "'timestamp-link" and "published".
        <a class='timestamp-link updated' expr:href='data:post.url' rel='bookmark' title='permanent link'> <abbr class='published updated' expr:title='data:post.timestampISO8601' itemprop='datePublished'> <data:post.timestamp/> </abbr></a>
      3. Click the "Save" button.