【问题标题】:Can't get biojava to work in a Maven Netbeans application无法让 biojava 在 Maven Netbeans 应用程序中工作
【发布时间】:2016-02-02 09:06:48
【问题描述】:

让 BioJava 在使用 Maven 构建的 Netbeans RCP 应用程序中工作时遇到问题。我创建了一个 Maven 模块作为包装器,包括在 POM 中公开的 org.biojava.* 和 org.forester.* 包。然后,在另一个模块中,我将包装器设置为依赖项,并使用 BioJava 食谱中的一些基本示例进行测试。

每当我尝试从 BioJava 实例化某个类的对象时,应用程序都会冻结,我必须使用 Windows 任务管理器将其终止。

这是包装器的 pom 文件:

    <?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>

这是我尝试开始工作的一些代码。这只是一个非常粗略的示例,从 TopComponent 中的按钮调用。输入和输出只是文本字段。

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();


}     

这是阅读器类:

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;
    }

}

在 (Netbeans) IDE 中,在自动完成中找到并使用了类,并且项目成功构建,在每种情况下都表明主要依赖项设置正确。

【问题讨论】:

  • 嗨 Henk,您应该发布一些您使用的代码,尝试获取一个有错误的最小示例。这样,如果人们碰巧有经验,他们就可以提供帮助。
  • 这是个好主意,Jaap,你是对的。对不起我的懒惰。
  • 很抱歉帮不了你,我对maven、netbeans或biojava了解不多……
  • 我做了很多跟踪,发现程序在运行构造函数时冻结(或者,当我通过反射调试它时,在 ConstructorAccessor 内部 Constructor @987654326 @ 叫做)。我仍然对此感到非常困惑......

标签: java maven netbeans netbeans-platform biojava


【解决方案1】:

首先检查包装模块的清单以查看是否正确生成了所有条目,尤其是在您定义 useOSGiDependencies==true 之后。可能是 biojava jar 包含 osgi 标头,然后您没有将 jar 包装在模块中,而是声明了对 osgi 插件的依赖。

然而,应用程序的锁定很奇怪,如果运行时依赖项有问题,我会预料到会出现早期的“不满足的依赖项”错误。您可能想要创建一个线程转储并检查发生了什么。也许你有一个僵局。或者由于您的操作 (jButton1ActionPerformed) 是从 AWT 调用的,因此整个阅读过程可能只需要时间并且您的 UI 线程被锁定。

【讨论】:

  • 感谢回复,我去看看。 Biojava 需要有 osgi 头文件的 slf4j。不幸的是,我并不完全清楚何时将模块用作 osgi 或仅用作 jar。我已经尝试关闭 osgidependencies,但这似乎没有什么不同,只是包装器无法编译。设置为 'on' 使模块再次编译。缓慢:我尝试在常规的 Swing 应用程序中执行相同的代码,并且它可以工作(确实锁定了 gui)但在常规时间范围内。调试时,当我尝试实例化一个对象时,似乎一切都锁定了。
【解决方案2】:

我做了很多搜索,发现真正的罪魁祸首是 slf4j,它在整个 BioJava 中都使用过。 我不知道为什么它会冻结平台应用程序,但我可以通过在其中创建一个 slf4j 记录器来导致我的模块无法安装。 我在网上看到了一个包装器模块的解决方案,结果证明为org.slf4j:slf4j-api:x.y.zorg.slf4j:slf4j-jdk14:x.y.z 创建一个包装器就足够了。将org.slf4j.* 添加到公共包中。这是 POM:

<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>group</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0.0</version>
</parent>
<artifactId>slf4jwrapper</artifactId>
<packaging>nbm</packaging>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>nbm-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <publicPackages>
                    <publicPackage>org.slf4j.*</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.netbeans.api</groupId>
        <artifactId>org-netbeans-api-annotations-common</artifactId>
        <version>${netbeans.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.7</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

包装器应该在 BioJava 依赖模块中使用,但它也应该适用于依赖 slf4j 的其他模块。

【讨论】:

    猜你喜欢
    • 2016-05-18
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多