How to create a Plugin which holds all the libraries (jars) required by a RCP Application?
Plugin:
1. test.core.lib
2. testPluginA
Library: junit.jar
Procedure:
1. Create Plugin: test.core.lib - A non-UI contributing plugin. This plugin would have only one class: Activator.
2. Create folder:lib on test.core.lib project. Copy junit.jar to lib folder.
3. Modify Plugin.xml of test.core.lib, Open Runtime tab, add this jar in classpath and expose all the packages of this jar.
4. Create Plugin: testPluginA - A UI contributing plugin. This plugin would have a default view, perspective and application classes.
5. Modify Plugin.xml of testPluginA - Open Dependency tab, add dependency on test.core.lib plugin.
6. Create a ViewTest class which extends junit.framework.TestCase. Add a test method like :
public static void testMessageHelloWorld(){
System.out.println("Test Class invoked showing message: Hello World");
}
7. Open View class, call this method in View's createPartControl() method.
8. Run testPluginA as eclipse application.
9. The following message should be displayed in console:
"Test Class invoked showing message: Hello World".
Tuesday, May 20, 2008
Thursday, May 15, 2008
Simple Steps to create and work with Eclipse Extension Point
Follwing is a sample extension point which shows simple steps to define and work with Extension Points/define custom Extension Points.
Requirement: A simple Hello World message display when an event is triggered.
Plugins:
testcore - defines a plugin extension point called eventhandler.
testplugin1 - contributes to the extension point - eventhandler.
testplugin2 - contributes to the extension point - eventhandler.
Step A: Create Extension Point: EventHandler
open plugin.xml of plugin:testcore.
1. Open Extension points tab, Click Add, which opens a New Extension Point Dialog, Give the following entries as shown in the below picture.
2. Click Enter and u will be opened eventhandler.exsd. Click on Definition tab and u should be opened with the below screen.
fig 2: ExtenionPoint eventhandler definition
fig 3: Extension Point Attribute: "id" definition

package testcore.eventhandler;
public interface IEventHandler {
public void handleEvent(String message);
}
2c) Open Runtime tab, Add testcore.eventhandler package for IEventHandler to be visible to other plugins
3. Open plugin.xml of Plugin: testplugin1.
3a) Open Dependencies tab, Add testcore plugin as a dependency.
3b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:
3c) Create Plugin1EventHandler class in testplugin1.eventhandler package.
package testplugin1.eventhandler;
import testcore.eventhandler.IEventHandler;
public class Plugin1EventHandler implements IEventHandler {
public Plugin1EventHandler() {
// TODO Auto-generated constructor stub
}
public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin1EventHandler:"+message);
}
}
4. Open plugin.xml of Plugin: testplugin2.
4a) Open Dependencies tab, Add testcore plugin as a dependency.
4b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:
4c) Create Plugin2EventHandler class in testplugin1.eventhandler package.
package testplugin2.eventhandler;
import testcore.eventhandler.IEventHandler;
public class Plugin2EventHandler implements IEventHandler {
public Plugin2EventHandler() {
// TODO Auto-generated constructor stub
}
public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin2EventHandler:"+message);
}
}
5. Open Activator class of testcore plugin and do the following in start method.
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("testcore.eventhandler");
if (point == null) return;
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++){
IConfigurationElement[] configElements = extensions[i]
.getConfigurationElements();
for(IConfigurationElement configElement : configElements){
System.out.println(configElement.getAttribute("class"));
IEventHandler eventHandler = (IEventHandler) configElement
.createExecutableExtension("class");
eventHandler.handleEvent("Hello World");
}
}
}
6. Run testcore as Eclipse Application. Add testplugin1 and testplugin2 to its run time class path. You should see the following messages:
testplugin1.eventhandler.Plugin1EventHandler
in Plugin1EventHandler:Hello World
testplugin2.eventhandler.Plugin2EventHandler
in Plugin2EventHandler:Hello World
which shows the contributor plugins : testplugin1 and testplugin2 's EventHandler's getting called.
Requirement: A simple Hello World message display when an event is triggered.
Plugins:
testcore - defines a plugin extension point called eventhandler.
testplugin1 - contributes to the extension point - eventhandler.
testplugin2 - contributes to the extension point - eventhandler.
Step A: Create Extension Point: EventHandler
open plugin.xml of plugin:testcore.
1. Open Extension points tab, Click Add, which opens a New Extension Point Dialog, Give the following entries as shown in the below picture.
fig 4: Extension Point Attribute: "class" definition
2b. Create IEventHandler class in package testcore.eventhandler with following details:package testcore.eventhandler;
public interface IEventHandler {
public void handleEvent(String message);
}
2c) Open Runtime tab, Add testcore.eventhandler package for IEventHandler to be visible to other plugins
3. Open plugin.xml of Plugin: testplugin1.
3a) Open Dependencies tab, Add testcore plugin as a dependency.
3b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:
3c) Create Plugin1EventHandler class in testplugin1.eventhandler package.
package testplugin1.eventhandler;
import testcore.eventhandler.IEventHandler;
public class Plugin1EventHandler implements IEventHandler {
public Plugin1EventHandler() {
// TODO Auto-generated constructor stub
}
public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin1EventHandler:"+message);
}
}
4. Open plugin.xml of Plugin: testplugin2.
4a) Open Dependencies tab, Add testcore plugin as a dependency.
4b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:
4c) Create Plugin2EventHandler class in testplugin1.eventhandler package.
package testplugin2.eventhandler;
import testcore.eventhandler.IEventHandler;
public class Plugin2EventHandler implements IEventHandler {
public Plugin2EventHandler() {
// TODO Auto-generated constructor stub
}
public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin2EventHandler:"+message);
}
}
5. Open Activator class of testcore plugin and do the following in start method.
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("testcore.eventhandler");
if (point == null) return;
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++){
IConfigurationElement[] configElements = extensions[i]
.getConfigurationElements();
for(IConfigurationElement configElement : configElements){
System.out.println(configElement.getAttribute("class"));
IEventHandler eventHandler = (IEventHandler) configElement
.createExecutableExtension("class");
eventHandler.handleEvent("Hello World");
}
}
}
6. Run testcore as Eclipse Application. Add testplugin1 and testplugin2 to its run time class path. You should see the following messages:
testplugin1.eventhandler.Plugin1EventHandler
in Plugin1EventHandler:Hello World
testplugin2.eventhandler.Plugin2EventHandler
in Plugin2EventHandler:Hello World
which shows the contributor plugins : testplugin1 and testplugin2 's EventHandler's getting called.
Tuesday, May 6, 2008
Basic Authentication in Sun AppServer
Follow the below steps to configure a particular user with https enabled web app:
1. In the sun-web.xml of the webapp:
<sun-web-app>
<context-root>/test</context-root>
<security-role-mapping>
<role-name>my-role</role-name>
<principal-name>user1</principal-name>
<group-name>my-group</group-name>
</security-role-mapping>
</sun-web-app>
2. In the web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Site</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>my-role</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>
<security-role>
<role-name>my-role</role-name>
</security-role>
</web-app>
3. In Sun App Server admin console:
Under Configuration-->Security-->Realms-->File --> Manage Users
User: user1
Password: xxxx
Confirm Password: xxxx
Group List: my-role
Under Configuration-->Security-->Realms-->Certificate
Property: assign-groups : my-role
Under Configuration-->HTTP Listeners
Add new https listener with port 443 and enable all authentication and ssl'S in that.
Now launch your web app. It should pop up a username and pwd dialog box for basic authentication.
1. In the sun-web.xml of the webapp:
<sun-web-app>
<context-root>/test</context-root>
<security-role-mapping>
<role-name>my-role</role-name>
<principal-name>user1</principal-name>
<group-name>my-group</group-name>
</security-role-mapping>
</sun-web-app>
2. In the web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Site</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>my-role</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>
<security-role>
<role-name>my-role</role-name>
</security-role>
</web-app>
3. In Sun App Server admin console:
Under Configuration-->Security-->Realms-->File --> Manage Users
User: user1
Password: xxxx
Confirm Password: xxxx
Group List: my-role
Under Configuration-->Security-->Realms-->Certificate
Property: assign-groups : my-role
Under Configuration-->HTTP Listeners
Add new https listener with port 443 and enable all authentication and ssl'S in that.
Now launch your web app. It should pop up a username and pwd dialog box for basic authentication.
Sunday, March 30, 2008
Easy Creation, Export and Import of SSL Certificates for Sun AppServer
Following are the easy steps to create, export and import SSL Certificates.
1. Open Command Prompt, Point to ${Sun_HOME}/AppServer9/Domains/Domain1/config folder.
2. Run: keytool -genkey -alias aliasname -keyalg RSA -keystore keystore.jks
2. Create "aliasname.cer" in Sun/AppServer9/Domains/Domain1/config folder.
3. Run: keytool -export -alias aliasname-file aliasname.cer -keystore keystore.jks
4. Run: keytool -import -v -trustcacerts -alias aliasname -file aliasname.cer -keystore cacerts.jks
Sunday, February 3, 2008
SWT Editable Dialog Cell Editor
A SWT Editable Dialog Cell Editor with Cut, Copy, Paste and Delete Editor, A Dialog Button[File Dialog] and A Clear Cell button.
File Dialog Button - Clicking this would pop up a file Dialog.
Clear Cell Button - Clicking this would clear the field.
File Dialog Button - Clicking this would pop up a file Dialog.
Clear Cell Button - Clicking this would clear the field.
Thursday, January 3, 2008
JAXB - XJC Task Cannot Resolve '' to a(n) element declaration component
JAXB XJC Task ignores the second import statement in xsds. Hence multiple imports would not get read and hence classes would not be generated. Once the reference of those non-generated classes are invoked, XJC throws "Cannot resolve '' to a(n) element declaration component".
Solution:
1. Pass "-nv" argument to XJC Task
For Ant:






For Maven:
Solution:
1. Pass "-nv" argument to XJC Task
For Ant:







Subscribe to:
Posts (Atom)