Can not use biojava in a Maven Netbeans application

advertisements

I have a problem getting BioJava to work in a Netbeans RCP application, built using Maven. I've created a Maven module as a wrapper, including org.biojava.* and org.forester.* packages as public in the POM. Then, from another module I set the wrapper as a dependency, and use some of the basic examples from the BioJava cookbook for testing.

Whenever I try to instantiate some object of a class from BioJava, the application freezes and I have to kill it using the Windows task manager.

Here's the wrapper's pom file:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>nl.hecklab.bioinformatics</groupId>
        <artifactId>Spider-parent</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>BiojavaWrapper</artifactId>
    <version>4.1.0</version>
    <packaging>nbm</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>nbm-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <useOSGiDependencies>true</useOSGiDependencies>
                    <publicPackages>
                        <publicPackage>org.biojava.*</publicPackage>
                        <publicPackage>org.forester.*</publicPackage>
                    </publicPackages>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <useDefaultManifestFile>true</useDefaultManifestFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.biojava</groupId>
            <artifactId>biojava-alignment</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

Here's some code I try to get to work. This is just a very coarse example, called from a button in a TopComponent. Input and output are just text fields.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    Reader r = new Reader(new File("D:\\current\\fastafile.fasta"));
    for (ProteinSequence a : r.getSequences()) {
        input.append(a.toString());
    }
    Profile<ProteinSequence, AminoAcidCompound> profile = Alignments.getMultipleSequenceAlignment(r.sequences);
    output.setText(String.format("Clustalw:%n%s%n", profile));

    ConcurrencyTools.shutdown();

}

Here's the reader class:

public class Reader {

    List<ProteinSequence> sequences = new ArrayList<>();

    public Reader(File fastaFile) {

        try {

            FileInputStream inStream = new FileInputStream(fastaFile);
            FastaReader<ProteinSequence, AminoAcidCompound> fastaReader
                    = new FastaReader<>(
                            inStream,
                            new GenericFastaHeaderParser<ProteinSequence, AminoAcidCompound>(),
                            new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet()));
            LinkedHashMap<String, ProteinSequence> b = fastaReader.process();

            sequences.addAll(b.values());
        } catch (IOException ex) {
            Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public List<ProteinSequence> getSequences() {
        return sequences;
    }

}

In the (Netbeans) IDE, the classes are found and used in autocompletion, and the project builds successfully, in each case indicating that principally the dependencies are set up correctly.


First of all check the wrapper module's manifest to see if all entries are correctly generated, especially since you define useOSGiDependencies==true. It could be that the biojava jars contain osgi headers and then you are not wrapping the jars in module, but declare a dependency on osgi plugin.

However locking of the app is weird, if there was something wrong with the runtime dependencies I would have expected an early 'unsatisfied dependencies' error. You might want to create a thread dump and check what's going on. Maybe you have a deadlock. Or since your action (jButton1ActionPerformed) is called from AWT, maybe the whole reading thing just takes time and your UI thread is locked.