Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps
More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps [message #138849] Wed, 01 July 2009 12:51 Go to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi,


i modified the ConfigIniCreator.java file that comes with the RAP demo deploy feature to add some more convenient features:

- uses relative paths to the build feature so it can be used on any machine with the same workspace content
- automatically converts windows to unix path separator chars so it can be used without change on unix and windows machines
- sorts the list of plugins to have a lexicographical sorted plugin list in the resulting config.ini
- automatically determines whether a plug-in (bundle) jar file is a fragment and thus not adding a @start tag to this bundle
- after creation on the config it automatically outputs the content in the config.ini file so there is no need to copy&paste it

there is no big magic behind it, but someone who uses a copied and adjusted version of the rap demo feature to deploy the RAP app
on a i.e. tomcat (like i do) might find this ideas a bit inspiring :)
the file is commented at the points where you need to adjust the paths etc. my deploy feature is placed in the workspace right next
to the other plug-ins, this is important to determine the relative paths. moreover my deploy feature has the same structure as
the rap demo feature. the xml script are located in the scripts folder etc.

the next litte ant script simply builds a .war file of the folder that has been filled by the webappBuilder.xml ant script. so
the procedure of deploying a RAP app on a tomcat can be as simply as this:

- adjust the feature to include the needed plug-ins and fragments
- run the webappBuilder.xml script (adjust the paths)
- run the ConfigIniCreator.java file (adjust the paths/settings)
- run the warBuilder.xml script (adjust the paths)

the resulting .war file can then be uploaded / placed in the tomcat webapp folder, done and done :P. that's how i do it however.

here are the contents of the two files, feedback, improvements, other ideas are always welcomed!!


ConfigIniCreater.java:




import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

/**
* This tool creates the content of a simple config.ini file. Run this after the
* ANT build scripts (webappBuilder.xml and the pde.exportFeatures) have
* finished. After that, replace the content of the config.ini file in the build.
* <p>
* Note: this is not meant to be a high end deployment tool or the only
* possibility of how the content of your config.ini should look like if you are
* creating a RAP WAR. This should simplify the task to get a minimalistic
* runtime configuration that works...
*/
public class ConfigIniCreator {

/**
* Name of the project directory
*/
private static final String PROJECT_DIR_NAME = "modulhandbuch";

/**
* Relative or absolute path to the BUILD_DIR of the project
*/
private static final String BUILD_DIR = ".\\build\\" + PROJECT_DIR_NAME;

/**
* Relative or absolute path to the plug-in directory of the deploy build
*/
private static String PLUGIN_PATH = BUILD_DIR + "\\WEB-INF\\eclipse\\plugins";

/**
* Relative or absolute path to the config.ini of the deploy build
*/
private static String CONFIG_PATH = BUILD_DIR + "\\WEB-INF\\eclipse\\configuration\\config.ini";

/**
* Name of the framework bundle, this bundle needs to be excluded from the config.ini
*/
private static final String FRAMEWORK_BUNDLE = "org.eclipse.osgi_";

/**
* Name of the Equinox Servletbridge Extension bundle
*/
private static final String EXTENSION_BUNDLE = "org.eclipse.equinox.servletbridge.extensionbundle";

/**
* Name of the fragment host attribute in the MANIFEST.MF of a jar file,
* is used to determine whether a jar file is a fragment bundle.
*/
private static final String FRAGMENT_MANIFEST_ATTRIBUTE = "Fragment-Host";

/**
* Default start level of the OSGi bundles
*/
private static final String DEFAULT_OSGI_STARTLEVEL = "4";

/**
* Creates the config.ini file respecting the files in the PLUGIN_PATH.
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// On no-windows systems, the file separator will be replaced with the
// proper one
if (!File.separator.equals("\\")) {
PLUGIN_PATH = PLUGIN_PATH.replace('\\', File.separatorChar);
CONFIG_PATH = CONFIG_PATH.replace('\\', File.separatorChar);
}

File file = new File(PLUGIN_PATH);

// The launch-configuration is being created based on the plug-ins in the deploy build
String filename = null;
String bundlename = null;
int underscorePos = 0;
File[] fileList = file.listFiles();

// Sort the file array to have a lexicographically ordered config.ini
Arrays.sort(fileList, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
}
});

StringBuffer buffer = new StringBuffer();
buffer.append("# Eclipse Runtime Configuration File\n");
buffer.append("osgi.bundles=");

for (int i = 0; i < fileList.length; i++) {
filename = fileList[i].getName();

if (filename.endsWith(".jar") && !filename.startsWith(FRAMEWORK_BUNDLE)) {
// Remove version number
underscorePos = filename.lastIndexOf("_");
bundlename = filename.substring(0, underscorePos);

// Append bundle name
buffer.append(bundlename);

// Add the start command. Fragments must not be started!
if (!isFragment(fileList[i])) {
if (filename.startsWith("org.eclipse.equinox.common_")) {
buffer.append("@2:start");
} else {
buffer.append("@start");
}
}

buffer.append(",\\\n ");

if ((i + 1) >= fileList.length) {
buffer.append(EXTENSION_BUNDLE);
}
}
}

buffer.append("\n");
buffer.append("osgi.bundles.defaultStartLevel=" + DEFAULT_OSGI_STARTLEVEL + "\n");

// The config string will be automatically written in the config.ini, it
// is not necessary to manually copy and paste the string in the file
FileOutputStream fileStream = new FileOutputStream(CONFIG_PATH);
OutputStreamWriter outStream = new OutputStreamWriter(fileStream);

outStream.write(buffer.toString());

// Clean up
outStream.flush();
fileStream.flush();
outStream.close();
fileStream.close();

// Print the status
System.out.print(buffer);
System.out.println();
System.out.println("File: " + CONFIG_PATH + " successfully written");
}

/**
* This method checks the META-INF/MANIFEST.MF of the provided JAR file to
* determine whether the bundle JAR file is a fragment bundle.
*
* @param file the JAR file to be checked
* @return true if the JAR file is a fragment bundle, false otherwise
* @throws IOException
*/
public static boolean isFragment(File file) throws IOException {
JarFile jarfile = new JarFile(file);
Manifest manifest = jarfile.getManifest();

if (manifest != null) {
Attributes attributes = manifest.getMainAttributes();
return attributes.containsKey(new Attributes.Name(FRAGMENT_MANIFEST_ATTRIBUTE));
} else {
return false;
}
}

}





warBuilder.xml:



<?xml version="1.0" encoding="UTF-8"?>
<!-- ============================================================ ===============
This Ant-Script packs the project build directory to a .war file which
can be deployed on e.g. a Apache Tomcat Servlet-Container.
Step one is to execute the webappBuilder.xml Ant-Script. Step two is to
execute the ConfigIniCreator.java file to create the proper config.ini file.
Step three is to make all necessary changes to any files in the resulting
project build dir. Step four is to run this Ant-Script to create a .war file.
The project can then be deployed by copying the project build directory
directly into the webapp folder of the Tomcat Server or by using the .war
file and the Tomcat Manager for example.
The properties in the init target need to be adjusted to the correct names
and paths!
============================================================ ============ -->
<project name="project" default="default" basedir=".">
<description>
This Ant-Script creates a .war file from the project build directory
after the webappBuilder.xml assembled the directory and all configurations
to the files in the build directory have been made
</description>

<!-- =================================
target: init
================================= -->
<target name="init">
<property name="project.name" value="modulhandbuch"/>
<property name="project.dir" value="${basedir}/.."/>
<property name="build.dir" value="${project.dir}/build"/>
<property name="source.dir" value="${build.dir}/${project.name}"/>
<property name="dest.file" value="${build.dir}/${project.name}.war"/>
</target>

<!-- =================================
target: default
================================= -->
<target name="default" depends="buildWar"/>

<!-- =================================
target: prepare
================================= -->
<target name="prepare" depends="init">
<delete file="${dest.file}" quiet="true"/>
</target>

<!-- =================================
target: warBuild
================================= -->
<target name="buildWar" depends="prepare">
<zip destfile="${dest.file}" basedir="${source.dir}" defaultexcludes="true" update="false"/>
</target>

</project>



HTH,
ben
Re: More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps [message #138866 is a reply to message #138849] Wed, 01 July 2009 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

one more remark: the problem is, is seems that the pde.exportFeature of the webappBuilder.xml can only be run asynchronously. if it could be run synchronously, all of the
steps could be packed in a single ant script, because the config.ini creation and the war build need to be done in the correct order and after the pde.exportFeature
has finished. i could not figure out a way until now to do this, maybe someone else already found a solution or has an even better solution?!

greetings,
ben



Ben W. schrieb:
> Hi,
>
>
> i modified the ConfigIniCreator.java file that comes with the RAP demo
> deploy feature to add some more convenient features:
>
> - uses relative paths to the build feature so it can be used on any
> machine with the same workspace content
> - automatically converts windows to unix path separator chars so it can
> be used without change on unix and windows machines
> - sorts the list of plugins to have a lexicographical sorted plugin list
> in the resulting config.ini
> - automatically determines whether a plug-in (bundle) jar file is a
> fragment and thus not adding a @start tag to this bundle
> - after creation on the config it automatically outputs the content in
> the config.ini file so there is no need to copy&paste it
>
> there is no big magic behind it, but someone who uses a copied and
> adjusted version of the rap demo feature to deploy the RAP app
> on a i.e. tomcat (like i do) might find this ideas a bit inspiring :)
> the file is commented at the points where you need to adjust the paths
> etc. my deploy feature is placed in the workspace right next
> to the other plug-ins, this is important to determine the relative
> paths. moreover my deploy feature has the same structure as
> the rap demo feature. the xml script are located in the scripts folder etc.
>
> the next litte ant script simply builds a .war file of the folder that
> has been filled by the webappBuilder.xml ant script. so
> the procedure of deploying a RAP app on a tomcat can be as simply as this:
>
> - adjust the feature to include the needed plug-ins and fragments
> - run the webappBuilder.xml script (adjust the paths)
> - run the ConfigIniCreator.java file (adjust the paths/settings)
> - run the warBuilder.xml script (adjust the paths)
>
> the resulting .war file can then be uploaded / placed in the tomcat
> webapp folder, done and done :P. that's how i do it however.
>
> here are the contents of the two files, feedback, improvements, other
> ideas are always welcomed!!
>
>
> ConfigIniCreater.java:
>
>
>
>
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStreamWriter;
> import java.util.Arrays;
> import java.util.Comparator;
> import java.util.jar.Attributes;
> import java.util.jar.JarFile;
> import java.util.jar.Manifest;
>
> /**
> * This tool creates the content of a simple config.ini file. Run this
> after the
> * ANT build scripts (webappBuilder.xml and the pde.exportFeatures) have
> * finished. After that, replace the content of the config.ini file in
> the build.
> * <p>
> * Note: this is not meant to be a high end deployment tool or the only
> * possibility of how the content of your config.ini should look like if
> you are
> * creating a RAP WAR. This should simplify the task to get a minimalistic
> * runtime configuration that works...
> */
> public class ConfigIniCreator {
>
> /**
> * Name of the project directory
> */
> private static final String PROJECT_DIR_NAME = "modulhandbuch";
>
> /**
> * Relative or absolute path to the BUILD_DIR of the project
> */
> private static final String BUILD_DIR = ".\\build\\" + PROJECT_DIR_NAME;
>
> /**
> * Relative or absolute path to the plug-in directory of the deploy
> build
> */
> private static String PLUGIN_PATH = BUILD_DIR +
> "\\WEB-INF\\eclipse\\plugins";
>
> /**
> * Relative or absolute path to the config.ini of the deploy build
> */
> private static String CONFIG_PATH = BUILD_DIR +
> "\\WEB-INF\\eclipse\\configuration\\config.ini";
>
> /**
> * Name of the framework bundle, this bundle needs to be excluded
> from the config.ini
> */
> private static final String FRAMEWORK_BUNDLE = "org.eclipse.osgi_";
>
> /**
> * Name of the Equinox Servletbridge Extension bundle
> */
> private static final String EXTENSION_BUNDLE =
> "org.eclipse.equinox.servletbridge.extensionbundle";
>
> /**
> * Name of the fragment host attribute in the MANIFEST.MF of a jar file,
> * is used to determine whether a jar file is a fragment bundle.
> */
> private static final String FRAGMENT_MANIFEST_ATTRIBUTE =
> "Fragment-Host";
>
> /**
> * Default start level of the OSGi bundles
> */
> private static final String DEFAULT_OSGI_STARTLEVEL = "4";
>
> /**
> * Creates the config.ini file respecting the files in the PLUGIN_PATH.
> *
> * @param args
> * @throws IOException
> */
> public static void main(String[] args) throws IOException {
> // On no-windows systems, the file separator will be replaced
> with the
> // proper one
> if (!File.separator.equals("\\")) {
> PLUGIN_PATH = PLUGIN_PATH.replace('\\', File.separatorChar);
> CONFIG_PATH = CONFIG_PATH.replace('\\', File.separatorChar);
> }
>
> File file = new File(PLUGIN_PATH);
>
> // The launch-configuration is being created based on the
> plug-ins in the deploy build
> String filename = null;
> String bundlename = null;
> int underscorePos = 0;
> File[] fileList = file.listFiles();
>
> // Sort the file array to have a lexicographically ordered
> config.ini
> Arrays.sort(fileList, new Comparator<File>() {
> @Override
> public int compare(File o1, File o2) {
> return
> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
> }
> });
>
> StringBuffer buffer = new StringBuffer();
> buffer.append("# Eclipse Runtime Configuration File\n");
> buffer.append("osgi.bundles=");
>
> for (int i = 0; i < fileList.length; i++) {
> filename = fileList[i].getName();
>
> if (filename.endsWith(".jar") &&
> !filename.startsWith(FRAMEWORK_BUNDLE)) {
> // Remove version number
> underscorePos = filename.lastIndexOf("_");
> bundlename = filename.substring(0, underscorePos);
>
> // Append bundle name
> buffer.append(bundlename);
>
> // Add the start command. Fragments must not be started!
> if (!isFragment(fileList[i])) {
> if
> (filename.startsWith("org.eclipse.equinox.common_")) {
> buffer.append("@2:start");
> } else {
> buffer.append("@start");
> }
> }
>
> buffer.append(",\\\n ");
>
> if ((i + 1) >= fileList.length) {
> buffer.append(EXTENSION_BUNDLE);
> }
> }
> }
>
> buffer.append("\n");
> buffer.append("osgi.bundles.defaultStartLevel=" +
> DEFAULT_OSGI_STARTLEVEL + "\n");
>
> // The config string will be automatically written in the
> config.ini, it
> // is not necessary to manually copy and paste the string in the
> file
> FileOutputStream fileStream = new FileOutputStream(CONFIG_PATH);
> OutputStreamWriter outStream = new OutputStreamWriter(fileStream);
>
> outStream.write(buffer.toString());
>
> // Clean up
> outStream.flush();
> fileStream.flush();
> outStream.close();
> fileStream.close();
>
> // Print the status
> System.out.print(buffer);
> System.out.println();
> System.out.println("File: " + CONFIG_PATH + " successfully
> written");
> }
>
> /**
> * This method checks the META-INF/MANIFEST.MF of the provided JAR
> file to
> * determine whether the bundle JAR file is a fragment bundle.
> *
> * @param file the JAR file to be checked
> * @return true if the JAR file is a fragment bundle, false otherwise
> * @throws IOException
> */
> public static boolean isFragment(File file) throws IOException {
> JarFile jarfile = new JarFile(file);
> Manifest manifest = jarfile.getManifest();
>
> if (manifest != null) {
> Attributes attributes = manifest.getMainAttributes();
> return attributes.containsKey(new
> Attributes.Name(FRAGMENT_MANIFEST_ATTRIBUTE));
> } else {
> return false;
> }
> }
>
> }
>
>
>
>
>
> warBuilder.xml:
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
> ============================================================ ===============
> This Ant-Script packs the project build directory to a .war file which
> can be deployed on e.g. a Apache Tomcat Servlet-Container.
> Step one is to execute the webappBuilder.xml Ant-Script. Step two is to
> execute the ConfigIniCreator.java file to create the proper
> config.ini file.
> Step three is to make all necessary changes to any files in the
> resulting
> project build dir. Step four is to run this Ant-Script to create a
> .war file.
> The project can then be deployed by copying the project build directory
> directly into the webapp folder of the Tomcat Server or by using the
> .war
> file and the Tomcat Manager for example.
> The properties in the init target need to be adjusted to the correct
> names
> and paths!
>
> ============================================================ ============
> -->
> <project name="project" default="default" basedir=".">
> <description>
> This Ant-Script creates a .war file from the project build directory
> after the webappBuilder.xml assembled the directory and all
> configurations
> to the files in the build directory have been made
> </description>
>
> <!-- =================================
> target: init
> ================================= -->
> <target name="init">
> <property name="project.name" value="modulhandbuch"/>
> <property name="project.dir" value="${basedir}/.."/>
> <property name="build.dir" value="${project.dir}/build"/>
> <property name="source.dir" value="${build.dir}/${project.name}"/>
> <property name="dest.file"
> value="${build.dir}/${project.name}.war"/>
> </target>
>
> <!-- =================================
> target: default
> ================================= -->
> <target name="default" depends="buildWar"/>
>
> <!-- =================================
> target: prepare
> ================================= -->
> <target name="prepare" depends="init">
> <delete file="${dest.file}" quiet="true"/>
> </target>
>
> <!-- =================================
> target: warBuild
> ================================= -->
> <target name="buildWar" depends="prepare">
> <zip destfile="${dest.file}" basedir="${source.dir}"
> defaultexcludes="true" update="false"/>
> </target>
>
> </project>
>
>
>
> HTH,
> ben
Re: More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps [message #138889 is a reply to message #138849] Wed, 01 July 2009 14:28 Go to previous messageGo to next message
Hans K. is currently offline Hans K.Friend
Messages: 10
Registered: July 2009
Junior Member
>i modified the ConfigIniCreator.java file that comes with the RAP demo deploy
>feature to add some more convenient features:

Where do I get this RAP demo deploy feature?

I have checked out RAP from the rap update site and imported the
org.eclipse.rap.demo into my workspace. Nowhere do I find
ConfigIniCreator.java.

regards,
Hans
Re: More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps [message #138901 is a reply to message #138889] Wed, 01 July 2009 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: benjamin.wolff.web.de

Hi Hans,

you should make yourself familiar with CVS and checking out projects from a CVS repository, how this is done is described here:

http://www.eclipse.org/rap/cvs.php

there you find projects that are not distributed with the target-platform or tooling. using the CVS HEAD projects it is ensured that
you always work with the latest development status of the plug-ins. you can, for example, check out all rap projects from CVS in
your workspace and thus working with the latest additions/bug fixes etc. of RAP. but beware that there could also be new bugs that
are not present in the main release.

as mentioned in the RAP development guide about WAR deployment you should check out the prerequisitas provided in this file:

http://help.eclipse.org/galileo/topic/org.eclipse.rap.help/h elp/html/advanced/servletbridge-anon.psf

this is a team project set file. right-click in your workspace, choose 'import' select team project set and select the .psf file (download it somewhere).
the projects are then downloaded (checked-out) in your workspace. and voila, there are the mysterious projects =))


HTH,
ben




Hans K. schrieb:
>> i modified the ConfigIniCreator.java file that comes with the RAP demo
>> deploy feature to add some more convenient features:
>
> Where do I get this RAP demo deploy feature?
>
> I have checked out RAP from the rap update site and imported the
> org.eclipse.rap.demo into my workspace. Nowhere do I find
> ConfigIniCreator.java.
>
> regards,
> Hans
>
>
Re: More convenient ConfigIniCreator.java and a warBuilder.xml for deploying RAP apps [message #138924 is a reply to message #138901] Wed, 01 July 2009 14:55 Go to previous message
Hans K. is currently offline Hans K.Friend
Messages: 10
Registered: July 2009
Junior Member
Thanks. This makes things clearer.

I had tried getting org.eclipse.rap.demo.feature from /cvsroot/technology
instead of /cvsroot/rt.

I hope I have more success when I continue on this tomorrow.

regards
Hans
Previous Topic:Does RAP support auto-completion of text fields?
Next Topic:Display.syncExec() does not work
Goto Forum:
  


Current Time: Sun Nov 28 00:08:37 GMT 2021

Powered by FUDForum. Page generated in 0.02740 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top