JavaTools Twittering
JavaTools Community is twittering: http://twitter.com/javatools from JavaONE and we invite you to follow. We’ll have some interesting news on NetBeans (Platform) here…
JavaTools Community is twittering: http://twitter.com/javatools from JavaONE and we invite you to follow. We’ll have some interesting news on NetBeans (Platform) here…
You’ve probably heard a lot about project netigso already. This project allows you to run OSGi bundles in NetBeans Platform applications. Geertjan has blogged about how to create a new Bundle and how to create a Module Installer.
The main reason why I’m so exited about netigso is that you can reuse all the readymade bundles out there. Today I tried to get this to work. I created a new NetBeans Platform application with a simple bundle and built it (so I had the build directory in place). Then I created a second helloworld bundle using “the other IDE” to have an “alien bundle” to work with.
The Netigso Wiki has a few hints how to “clusterize” your bundle to use it in NetBeans, but I didn’t get it to work yet. So I decided to do a manual integration.
Update: Here’s how to clusterize your bundles. seems I simply missed the part about importing the cluster…
Basically everything you need to do should be to copy your bundle into the build directory under:
/build/cluster/modules/de.alienbundle.demo_1.0.0.jar
rename it to:
/build/cluster/modules/de-alienbundle-demo.jar
Create a file:
/build/cluster/config/modules/de-alienbundle-demo.xml
with this content:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE module PUBLIC “-//NetBeans//DTD Module Status 1.0//EN”
“http://www.netbeans.org/dtds/module-status-1_0.dtd”>
<module name=”de.alienbundle.demo”>
<param name=”autoload”>false</param>
<param name=”eager”>false</param>
<param name=”enabled”>true</param>
<param name=”jar”>modules/de-alienbundle-demo.jar</param>
<param name=”reloadable”>false</param>
</module>
…and that’s it, my first alien bundle! Now run the application and the installer is called:
hello from alien bundle!
INFO [org.netbeans.core.startup.NbEvents]: Turning on modules:
org.openide.util [7.22.0.1 1 netigso-157-on-090525]
org.openide.modules [7.10 netigso-157-on-090525]
org.openide.awt [7.8.0.1 netigso-157-on-090525]
org.openide.io [1.16 netigso-157-on-090525]
org.jdesktop.layout/1 [1.7.0.103 103 netigso-157-on-090525]
org.netbeans.api.progress/1 [1.13.0.1 1 netigso-157-on-090525]
org.openide.dialogs [7.10 netigso-157-on-090525]
org.openide.nodes [7.9.0.1 netigso-157-on-090525]
org.openide.windows [6.26 netigso-157-on-090525]
org.netbeans.core.io.ui/1 [1.0.1 1 netigso-157-on-090525]
org.netbeans.swing.outline [1.4 netigso-157-on-090525]
org.openide.explorer [6.18.0.1 1 netigso-157-on-090525]
org.openide.filesystems [7.21.0.1.1 1 netigso-157-on-090525]
org.netbeans.modules.editor.mimelookup/1 [1.11 netigso-157-on-090525]
org.openide.text [6.22 netigso-157-on-090525]
org.openide.actions [6.9.0.1 netigso-157-on-090525]
org.netbeans.bootstrap/1 [2.18 netigso-157-on-090525]
org.netbeans.core.startup/1 [1.15.0.1 netigso-157-on-090525]
org.netbeans.spi.quicksearch [1.1 netigso-157-on-090525]
org.netbeans.modules.queries/1 [1.14 netigso-157-on-090525]
org.openide.loaders [7.5 netigso-157-on-090525]
org.netbeans.swing.plaf [1.9 netigso-157-on-090525]
org.netbeans.core/2 [3.11.0.1 netigso-157-on-090525]
org.netbeans.modules.options.api/1 [1.12 netigso-157-on-090525]
org.netbeans.modules.masterfs/2 [2.16 netigso-157-on-090525]
de.eppleton.bundle2 [1.0 1.0]
org.netbeans.modules.settings/1 [1.18.0.1 netigso-157-on-090525]
org.netbeans.swing.tabcontrol [1.15 netigso-157-on-090525]
org.netbeans.core.windows/2 [2.14.0.1 netigso-157-on-090525]
org.netbeans.modules.applemenu/1 [1.10 netigso-157-on-090525]
org.netbeans.core.ui/1 [1.14.0.1 netigso-157-on-090525]
org.netbeans.modules.progress.ui [1.3.0.1 netigso-157-on-090525]
de.eppleton.demo [1.0 1.0]
de.alienbundle.demo [1.0.0 1.0.0]
org.netbeans.modules.print [7.0 netigso-157-on-090525]
org.netbeans.libs.jna/1 [1.2 netigso-157-on-090525]
org.netbeans.core.nativeaccess/1 [1.2 netigso-157-on-090525]
org.netbeans.modules.options.keymap [1.5 netigso-157-on-090525]
org.netbeans.modules.editor.mimelookup.impl/1 [1.4 netigso-157-on-090525]
org.netbeans.core.netigso [1.0 netigso-157-on-090525]
org.netbeans.core.output2/1 [1.11.0.1 1 netigso-157-on-090525]
Tomorrow at this time I’ll leave Munich and travel to the airport, which is quite a bit out of town. It’s a 40 minutes ride in the S-Bahn. Our former Prime Minister Edmund Stoiber tried to change this, but unfortunately nobody understood what he was talking about (here is why (in german)).
So usually that’s a long and boring ride, but not this time. Tomorrow I’ve got company. Sven Reimers is on the same flight to San Francisco. I hope to see a lot of fellow NB enthusiasts inside and outside of the Moscone center.
The latest edition of JavaSpektrum has some articles about NetBeans (in german):
Editorial: Am Anfang war Java – die Geschichte der Java-IDE in mehreren Akten
(= Editorial: In the beginning there was Java: The history of Java-IDEs )
Modulare Anwendung mit dem NetBeans-Lookup-Konzept, Heiko Böck
(= Modular Applications with the NetBeans Lookup Concept)
NetBeans RCP - Das bessere Swing-Application-Framework?, Toni Epple
(= NetBeans RCP - The better Swing Application Framework?)
NetBeans 6.X - die ultimative Java EE IDE?, Adam Bien
(NetBeans 6.X - The ultimate Java EE IDE?)
Another thing I recently discovered and found again in the Change History of FileSystem is the simplified access to the SystemFilesystem. Rather than having to type:
Repository.getDefault().getDefaultFileSystem().getRoot();
It’s now:
FileUtil.getConfigRoot();
and instead of:
Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(”foo/bar”);
it’s now:
FileUtil.getConfigFile(”foo/bar”);
Yesterday Geertjan sent me a link to a new feature of the NetBeans FileSystems API in response to my Tips about working with XML files. In 6.7 you can now easily get the content of a File as String, a List of Strings (asLines()), or byte [] ( asBytes() ):
FileObject fileObject = FileUtil.createData(new File(”demo/xml/test.txt”));
String text = fileObject.asText();
System.out.println(text);
Now that’s how reading files should have been like in Java 1.0…
If you have a FileObject for an XML File and you want to check, whether the content is valid, you can use CheckXMLCookie from XML Tools API to do so. It’s the same functionality as the “Check XML”-Action in the Editor providing a syntactic, non-validating chack:
FileObject fileObject = FileUtil.createData(new File(”demo/xml/test.xml”));
XMLDataObject dataObject = (XMLDataObject) DataObject.find(fileObject);
InputSource is = DataObjectAdapters.inputSource(dataObject);
CheckXMLSupport checkXMLSupport = new CheckXMLSupport(is);
boolean valid = checkXMLSupport.checkXML(new CookieObserver() {
public void receive(CookieMessage msg) {
System.out.println(”message ” + msg.getMessage());
}
});
System.out.println(valid ? “valid” : “invalid”);
After my last two tips about platform and XML, here’s a third way of getting hold of an XMLDocument using NetBeans:
Document d = XMLUtil.parse(
new InputSource(
new FileInputStream(
new File(”demo/xml/test.xml”)
)
)
, false, true, null, null);
In the last tip I’ve shown how to easily get hold of an org.w3c.Document for a File. You can also use this for XML Data from other input sources without having to write a real File to disk. Just use a Memory FileSystem. As an example I’m copying a real file into a virtual one, but obviously the data could come from any InputStream:
FileObject fileObject = FileUtil.createData(new File(”/demo/xml/test.xml”));
FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject virtualFile = fs.getRoot().createData(”demo”, “xml”);
InputStream in = fileObject.getInputStream();
OutputStream out = virtualFile.getOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
XMLDataObject dataObject = (XMLDataObject) DataObject.find(virtualFile);
Document d = dataObject.getDocument();
A little tip how to get hold of a org.w3c.Document from a FileObject using Datasystems API:
XMLDataObject dataObject = (XMLDataObject) DataObject.find(fileObject);
Document d = dataObject.getDocument();
In context of an XPath search:
try {
// get a FileObject somewhere
FileObject fileObject = FileUtil.createData(new File(”/demo/xml/test.xml”));
XMLDataObject dataObject = (XMLDataObject) DataObject.find(fileObject);
Document d = dataObject.getDocument();
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile(”//zick/file/bla/text()”);
Object result = expr.evaluate(d, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getNodeValue());
}
} catch (XPathExpressionException ex) {
Exceptions.printStackTrace(ex);
} catch (SAXException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}