Friday, December 28, 2007

Debian java packaging and jclassinfo

I've become more and more interested in packaging Java programs recently, and I find that it is not easy for several reasons:

  • There are at least half a dozen java implementation, some free, others non-free, with slightly different standard libraries. I find it all very confusing and error-prone.
  • A fair amount of Java packages depend Sun's Swing graphical user interface, and some others depend on Sun's XML parsing (at least as I understand it); they must therefore go to contrib
  • Java programs need script wrappers, often rather ugly, even more hackish and definitely not reusable/reused
  • There is currently no way to find dependencies of a Java package

I've nearly finished to package jclassinfo, a very useful tool that could bring an answer to some of the problems above, by extracting dependency information from class files. With its help, it could be possible to write something like dh_shlibdeps for Java classes. This would bring a real solution to the dependency problem, and possibly help as well for the main/contrib fight. More information later.

4 comments:

Egon Willighagen said...

Regarding the XML parsing... there is the gnujaxp parser in main, and updating the source code to use that XML library for parsing as backup, is fairly trivial. The CDK [1] used code at some point to support three different libs: Xerces, Sun-JAXP and GNU-JAXP.

1.http://cdk.sf.net/

Egon Willighagen said...

See http://cdk.svn.sourceforge.net/viewvc/cdk/trunk/cdk/src/org/openscience/cdk/io/CMLReader.java?revision=5211&view=markup

boolean success = false;
127 // If JAXP is prefered (comes with Sun JVM 1.4.0 and higher)
128 if (!success) {
129 try {
130 javax.xml.parsers.SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance();
131 spf.setNamespaceAware(true);
132 javax.xml.parsers.SAXParser saxParser = spf.newSAXParser();
133 parser = saxParser.getXMLReader();
134 logger.info("Using JAXP/SAX XML parser.");
135 success = true;
136 } catch (Exception e) {
137 logger.warn("Could not instantiate JAXP/SAX XML reader: ", e.getMessage());
138 logger.debug(e);
139 }
140 }
141 // Aelfred is first alternative.
142 if (!success) {
143 try {
144 parser = (XMLReader)this.getClass().getClassLoader().
145 loadClass("gnu.xml.aelfred2.XmlReader").
146 newInstance();
147 logger.info("Using Aelfred2 XML parser.");
148 success = true;
149 } catch (Exception e) {
150 logger.warn("Could not instantiate Aelfred2 XML reader!");
151 logger.debug(e);
152 }
153 }
154 // Xerces is second alternative
155 if (!success) {
156 try {
157 parser = (XMLReader)this.getClass().getClassLoader().
158 loadClass("org.apache.xerces.parsers.SAXParser").
159 newInstance();
160 logger.info("Using Xerces XML parser.");
161 success = true;
162 } catch (Exception e) {
163 logger.warn("Could not instantiate Xerces XML reader!");
164 logger.debug(e);
165 }
166 }
167 if (!success) {
168 logger.error("Could not instantiate any XML parser!");
169 }

Vincent Fourmond said...

Oops... I'm sorry then. XML parsing is in a much better shape on the free side that I thought. Nevertheless, Swing is still a big showstopper, at least for Debian at the moment.

Pudding Art said...

Good readding this post