|
|
||
Mandy Chung's BlogJuly 2008 ArchivesSupport for the module keywordPosted by mandychung on July 25, 2008 at 12:10 PM | Permalink | Comments (0)Very soon, in a week or two, the Java compiler (javac), packaging tool (jam), and the Java module system implementation in the OpenJDK Modules project will support the new The engineering team have built a special workaround to enable ourselves to build the Java module system while waiting for the language support. With the javac and jam tool support (thanks to Jonathan Gibbons and Kumar Srinivasan), you can now experience developing, building and packaging of a JAM module as JSR 277 spec defines. The language support for JSR 277 consists of two parts: module membership and module accessibility. The module accessibility support requires both the javac and JVM support which will go in next (stay tuned!). This blog is to help you get started to build and play with JAM modules using the JDK built from the Modules project with the module membership support. Module Membership Declaration There are two different ways to use the 1) To declare module membership in the individual source file of a class (recommended):
public class HelloWorld { 2) To declare module membership in package-info.java:
The Compile a module Since the module keyword is a new feature, you will need to run javac with -source 7 option: Module Compilation Unit A file called This
The You can download this sample aplication containing the hello, com.foo.OrderProcessingService, and com.bar.PrintService modules and try it out. Package a JAM Module The JDK provides a new JAM module packaging tool called "jam". To build the hello module: The jam command is similar to the jar command. The jam tool analyzes the list of input files and the module-info.class and generates the JAM module metadata (META-INF/MANIFEST.MF entry in the jam file). This metadata will be used by the Java Module System at runtime to enforce the versioning constraint and resolve the import dependency. To build the other two JAM modules provided in the sample application, Launch a Module Application Once you build the JAM modules, you can run the module application as follows: The -jam option is similar to the -jar option but launching a JAM module. Another way to launch the application: The -repository option specifies the source location of the JAM modules and the -module option specifies the module name containing the main entry point. Exercises There are few things you can try out:
Let us know what you think. Feedback and Questions Please send your feedback and questions to modules-dev@openjdk.java.net. We are working to post a JDK binary built from the Modules project once the module membership change is integrated (stay tuned). OSGi Repository for Java Module SystemPosted by mandychung on July 24, 2008 at 08:57 AM | Permalink | Comments (0)The draft specification for supporting OSGi bundles in the Java Module System is currently under discussion in the JSR 277 Expert Group. To enable the EG and the community to provide feedback, we have included an OSGi repository prototype in the OpenJDK Modules project. The prototype currently supports only Apache Felix OSGi implementation for proof-of-concept. There are open issues to be resolved. The out-of-the-box support is yet to be designed and implemented. Supporting other OSGi implementations is to be investigated. We hope that this prototype enables the community to begin participating and provide feedback for OSGi interoperability support. We are working on posting a JDK binary built from the modules-dev project to make it ready for you to try out and experiment the JAM modules development as well as the OSGi support. In the meantime, you can clone the source from the Modules mercurial repository and build the JDK. The OSGi repository for the Java Module System The OSGi repository is packaged as <JAVA_HOME>/lib/osgi-repo.jar. To build the JDK with the OSGi repository, do the following (refer to the OpenJDK build instructions for details):
Note: We will remove the build dependency of the jar files for the OSGi core API and Felix in a future implementation. Setting up the OSGi repository The modules-dev implementation provides a repository configuration file (<JAVA_HOME>/lib/module/repository.properties) to set up the repositories created at VM startup. To set up the OSGi repository:
You can either update the <JAVA_HOME>/lib/module/repository.properties or override the repository properties file by specifying this system property in the command line:
Known bug: The VM does not exit when the Felix container has been started unless System.exit() is explicitly. The OSGi repository starts the Felix container during initialization which started a non-daemon thread ("FelixDispatchQueue" thread). Since the FelixDispatchQueue thread is still running, the program will not terminate. OSGi Repository Initialization When the OSGi repository is being initialized during the VM initialization, it will first load the configuration properties file that is "conf/config.properties" under the parent directory of the directory where felix.jar is located; if it doesn't exist, the default configuration properties will be loaded. Then it will load and start the Felix OSGi framework specified in the "osgi.container" property. All bundles in the source location of the OSGi repository will be automatically installed and started as the OSGi repository initialization. To start Felix, the bundle cache profile name or directory is required to be specified to indicate where the installed bundles will be cached. If there is no config.properties set up, you can set this system property at VM startup:
Develop a JAM module to use an OSGi bundle A JAM module that imports an OSGi bundle expresses its dependency in the same way as importing a JAM module. For example, each JAM module has a module-info.java file to express its module name, version, and its import dependency.
// hello/module-info.java
@Version("2.0")
@ImportModules({
@ImportModule(name="java.se"),
@ImportModule(name="com.foo.xml", version="[1.0, 3.0)"),
@ImportModule(name="com.bar.parser", version="2.0+")
})
@MainClass("hello.Main");
module hello;
This "hello" module imports two modules, "com.foo.xml" and "com.bar.parser" and they are specified in the @ImportModule annotation regardless of whether they are OSGi bundles or JAM modules. Say "com.foo.xml" is an OSGi bundle whereas "com.bar.parser" is a JAM module. To successfully resolve the imports, we will need to configure the OSGi repository as an ancestor of the repository for the "hello" module. The source location of the OSGi repository is where the "com.foo.xml" and other OSGi bundles are located. To launch this "hello" module application, it can be as simple as follows:
You can refer to the documentation in the Modules project for how to create and launch a JAM module in details. Questions and Feedback Please send your questions and feedback to modules-dev@openjdk.java.net. [Comment is closed for this blog because I will not be able to respond to any blog comment the next few weeks (on vacation).] | ||
|
|