Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

SCA/SCA Component/SCA Java Run and Debug Tuscany

< SCA

Introduction

This tutorial explains how you can run an SCA Java project created with SCA Tools on Apache Tuscany.
There are three simple steps to perform:

  • Create a master launch configuration for Apache Tuscany.
  • Instantiate this configuration for the composite to deploy.
  • Optionaly, modify the generated configuration (for advanced use).


For this tutorial, we will use the "Simple Weather Sample" provided by SCA Tools.
It is an SCA project that you can create by selecting File > New > Examples > SCA > SCA Examples and then by choosing the Weather - Simple weather sample.


Three simple steps

Create a master launch configuration

The first thing to do is to create a master launch configuration.
For this example, we use Apache Tuscany 1.4.


Go into Window > Preferences > SCA Tools > Run / Debug.
Click Add.... In the dialog that shows up, type in "Tuscany 1.4". That will be the name of our master launch configuration.

SCA Java Run and Debug Tuscany1.gif


Click OK.
You should see the argument line is filled with ${composite_name}.
When this master launch configuration is instantiated (applied) for a composite, this variable will be replaced by the composite file name.

SCA Java Run and Debug Tuscany2.gif


And you should see the classpath contains a reference to the org.eclipse.stp.sca.deployment plug-in.

SCA Java Run and Debug Tuscany3.gif


In the Classpath tab, click Add library..., select all the librairies of Apache Tuscany 1.4 and click Open.

SCA Java Run and Debug Tuscany4.gif


In the Launch tab, copy org.eclipse.stp.sca.deployment.mains.TuscanyMain1x in the Main class field.
This class is provided by the org.eclipse.stp.sca.deployment plug-in and just deploys the composite.

SCA Java Run and Debug Tuscany6.gif


Click OK to save this configuration.


Run the composite with this configuration

In the package explorer, find the simpleWeather.composite file.
Make a right-click on it and select Run as... > SCA application. If you have created only one master configuration, it should automatically be launched.


SCA Java Run and Debug runAs.gif


Otherwise, in the dialog that shows up, select the "Tuscany 1.4" configuration.
You should get the following console display.

SCA Java Run and Debug runAsOnThisPlatformConsole.gif


You made it run without modifying the project classpath.
Type in 'q' to stop the main application.


Modify the launch configuration

Let's suppose you want to add special arguments to the configuration, or try on another JRE.
Go into Run > Run configurations... and select your configuration in the SCA category. Its name looks like < compositeName > - < masterLaunchConfigurationName >


You can now edit its properties, save it and run it again.

SCA Java Run and Debug Tuscany5.gif


Go further

Let's now suppose we want to test this project on another version of Tuscany.
Create a new master launch configuration and call it "Tuscany 1.2".
Put the same main class than "Tuscany 1.4" and add the libraries of Tuscany 1.2 in the Classpath tab.


SCA Java Run and Debug Tuscany2 1.gif


Right-click on simpleWeather.composite and select Run as... > SCA application.
In the selection dialog, select "Tuscany 1.2".

SCA Java Run and Debug Tuscany2 2.gif


The composite is launched on Tuscany 1.2. You should have this console display (not the same than the one for the 1.4 version).
Type in 'q' to stop the main application.

SCA Java Run and Debug Tuscany2 3.gif


If you want to edit this configuration, you can proceed in the same way you did previously.

SCA Java Run and Debug Tuscany2 4.gif


A configuration is saved for every couple ( compositeFile, masterLaunchConfiguration ).
If it exists, it will be reused. Otherwise, it is created and saved.


Caution

When you run an SCA Java application, you can terminate it using the "terminate button" (a red square button on the top right corner of the console).
If you terminate the Tuscany main application in this way, there are chances that the Jetty launched by Tuscany is not stopped. It can be a source of problems if you want to deploy your composite on another version of Tuscany.

This is why you should definitely terminate the main application by typing in 'q' in the console, so that the main terminates normally.


SCA Domain Manager support

If you are familiar with Apache Tuscany, you have probably heard about the SCA Domain Manager.
This is a great application that allows you to deploy and manages composites inside a same domain.
You can find more details and an example in this article of IBM.


If you have already used the Eclipse tooling of Apache Tuscany, you may have seen there is support to depoy a composite to Tuscany through the domain manager. Except this tooling is limited to one version of Tuscany (there is only Tuscany classpath library ). In fact, there is no problem in using the domain manager with the mechanism introduced in this tutorial. The only missing thing is the main class (which can be widely inspired from what is in the Tuscany tools).

The reason why we did not add it directly in the Tuscany main class is that it would probably be better welcome if it came from someone involved in the Tuscany project.


Links to visit


Appendix: the main method for Tuscany

public static void main( String[] args ) throws Exception {
 
	if( args.length != 1 )
		throw new IllegalArgumentException( 
			"<Usage>\n\tTuscanyMain1x.main( new String[] { <compositeFileName> });" ); //$NON-NLS-1$
 
	Object scaDomain = null;
	Class<?> scaDomainClass = null;
	try {
		System.out.println( "Deploying " + args[ 0 ] + "..." ); //$NON-NLS-1$ //$NON-NLS-2$
		scaDomainClass = Class.forName( "org.apache.tuscany.sca.host.embedded.SCADomain" ); //$NON-NLS-1$
		Method newInstanceMethod = scaDomainClass.getMethod( "newInstance", new Class[] { String.class }); //$NON-NLS-1$
		scaDomain = newInstanceMethod.invoke( scaDomainClass, new Object[] { args[ 0 ]});
 
		// Wait...
		System.out.println( "\nType in 'q' followed by 'enter' to end this application." ); //$NON-NLS-1$
		char c;
		while(( c = (char) System.in.read()) != 'q' ) {
			System.out.println( c );
		}
 
	} catch( Exception e ) {
		e.printStackTrace();
 
	} finally {
		if( scaDomain != null ) {
			System.out.println( "Undeploying " + args[ 0 ] + "..." ); //$NON-NLS-1$ //$NON-NLS-2$
			Method closeMethod = scaDomainClass.getMethod( "close", new Class[ 0 ]); //$NON-NLS-1$
			closeMethod.invoke( scaDomain, new Object[ 0 ]);
			scaDomain = null;
			System.out.println( "Done." ); //$NON-NLS-1$
		}
	}
}

Back to the top