使用loci.plugins(生物形式)生成SLF4J version_mismatch错误

时间:2017-11-22 23:13:47

标签: java maven slf4j imagej

我正在尝试为czi文件构建一个imagej插件。要调试插件我有一个主要的'打开imagej并打开图像的功能。要打开czi图像,我需要使用loci bioformat插件。

public static void main(String[] args) {
    // set the plugins.dir property to make the plugin appear in the Plugins menu
    Class<?> clazz = Confocal_Montage.class;
    String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
    String pluginsDir = url.substring("file:".length(), url.length() - clazz.getName().length() - ".class".length());
    System.out.println(pluginsDir);
    System.setProperty("plugins.dir", pluginsDir);

    // start ImageJ
    new ImageJ();

    // open the sample czi file 
    try {
        ImagePlus[] imps = BF.openImagePlus(System.getProperty("user.dir")+"\\0min_sonicate1.czi");
        for (ImagePlus imp :imps) imp.show();
    }
    catch(IOException exc){
        IJ.error("sorry an error occurred: " + exc.getMessage());
    }
    catch(FormatException exc){
        IJ.error("Sorry an error occured: " + exc.getMessage());
    }

    // run the plugin
    IJ.runPlugIn(clazz.getName(), "");
}

但是当我尝试运行调试器(VSCode)时遇到此错误

SLF4J: The requested version 1.5.10 by your slf4j binding is not compatible with [1.6, 1.7]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/String;
    at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:246)
    at ome.scifio.common.IniParser.parseINI(IniParser.java:144)
    at ome.scifio.common.IniParser.parseINI(IniParser.java:101)
    at loci.common.IniParser.parseINI(IniParser.java:97)
    at loci.plugins.prefs.OptionsList.<init>(OptionsList.java:66)
    at loci.plugins.in.ImporterOptions.<init>(ImporterOptions.java:158)
    at loci.plugins.BF.openImagePlus(BF.java:78)
    at com.mycompany.imagej.Confocal_Montage.main(Confocal_Montage.java:77)

我在Maven + SLF4J: Version conflict when using two different dependencies that require two different SLF4J versions中尝试了解决方案。将slf4j版本1.7.5的依赖项添加到我的pom中,但是当我这样做时,我得到了这个错误。

log4j:WARN No appenders could be found for logger (ome.scifio.common.IniParser).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NumberFormatException: null
    at java.base/java.lang.Integer.parseInt(Integer.java:614)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at loci.formats.in.ZeissCZIReader.translateExperiment(ZeissCZIReader.java:1870)
    at loci.formats.in.ZeissCZIReader.translateMetadata(ZeissCZIReader.java:965)
    at loci.formats.in.ZeissCZIReader.initFile(ZeissCZIReader.java:540)
    at loci.formats.FormatReader.setId(FormatReader.java:1333)
    at loci.plugins.in.ImportProcess.initializeFile(ImportProcess.java:482)
    at loci.plugins.in.ImportProcess.execute(ImportProcess.java:146)
    at loci.plugins.BF.openImagePlus(BF.java:95)
    at loci.plugins.BF.openImagePlus(BF.java:80)
    at com.mycompany.imagej.Confocal_Montage.main(Confocal_Montage.java:77)

我的maven依赖树看起来像这样

[INFO] --- maven-dependency-plugin:3.0.0:tree (default-cli) @ File_To_Montage ---
[INFO] com.mikedavies:File_To_Montage:jar:0.1.0-SNAPSHOT
[INFO] +- net.imagej:ij:jar:1.51h:compile
[INFO] +- loci:loci_plugins:jar:5.0.0-beta1:compile
[INFO] |  +- loci:bio-formats:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:mdbtools-java:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:metakit:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:poi-loci:jar:5.0.0-beta1:compile
[INFO] |  |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  |  +- loci:turbojpeg:jar:5.0.0-beta1:compile
[INFO] |  |  \- edu.ucar:netcdf:jar:4.0.03:compile
[INFO] |  +- loci:loci-legacy:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:scifio-devel:jar:5.0.0-beta1:compile
[INFO] |  |  +- xalan:serializer:jar:2.7.1:runtime
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.3.04:runtime
[INFO] |  |  \- xalan:xalan:jar:2.7.1:runtime
[INFO] |  +- loci:ome-xml:jar:5.0.0-beta1:compile
[INFO] |  +- loci:scifio:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:jai_imageio:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:lwf-stubs:jar:5.0.0-beta1:compile
[INFO] |  |  +- loci:specification:jar:5.0.0-beta1:compile
[INFO] |  |  |  +- junit:junit:jar:4.12:test
[INFO] |  |  |  |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  |  |  \- org.testng:testng:jar:6.8:compile
[INFO] |  |  |     +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] |  |  |     +- com.beust:jcommander:jar:1.27:compile
[INFO] |  |  |     \- org.yaml:snakeyaml:jar:1.6:compile
[INFO] |  |  +- org.scijava:native-lib-loader:jar:2.1.4:compile
[INFO] |  |  +- com.esotericsoftware.kryo:kryo:jar:shaded:2.21:compile
[INFO] |  |  \- org.perf4j:perf4j:jar:0.9.13:compile
[INFO] |  +- com.jgoodies:forms:jar:1.2.1:compile
[INFO] |  \- log4j:log4j:jar:1.2.14:compile
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.5.10:test
[INFO]    \- org.slf4j:slf4j-api:jar:1.7.21:compile

开始我的Pom.xml看起来像这样

<?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>org.scijava</groupId>
        <artifactId>pom-scijava</artifactId>
        <version>14.0.0</version>
    </parent>

    <groupId>com.mycompany</groupId>
    <artifactId>File_To_Montage</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <url>mycompany.com</url>
    <repositories>
        <repository>
            <id>imagej.public</id>
            <url>http://maven.imagej.net/content/groups/public</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>net.imagej</groupId>
            <artifactId>ij</artifactId>
        </dependency>
        <dependency>
            <groupId>loci</groupId>
            <artifactId>loci_plugins</artifactId>
            <version>5.0.0-beta1</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency> 

    </dependencies>

关于如何解决这个问题的任何想法都会很棒,它会把我推到墙上

1 个答案:

答案 0 :(得分:1)

想出来,所以对于遇到这个问题的其他人来说,有两个问题。第一个是我确实需要包含slf4j依赖项(简单和api)和scijava-log-slf4j(不确定我是否需要所有这些但是它们都可以使用它们全部声明)。

    <dependency>
        <groupId>org.scijava</groupId>
        <artifactId>scijava-log-slf4j</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
    </dependency>

因为这些依赖关系已经在scijava pom中管理,所以不需要包含版本号。 我还在loci中包含了一个排除:loci_plugins依赖

        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>

这摆脱了slf4j问题和警告,但留下了NumberFormatException。

Exception in thread "main" java.lang.NumberFormatException: null
    at java.base/java.lang.Integer.parseInt(Integer.java:614)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at loci.formats.in.ZeissCZIReader.translateExperiment(ZeissCZIReader.java:1870)
    at loci.formats.in.ZeissCZIReader.translateMetadata(ZeissCZIReader.java:965)
    at loci.formats.in.ZeissCZIReader.initFile(ZeissCZIReader.java:540)
    at loci.formats.FormatReader.setId(FormatReader.java:1333)
    at loci.plugins.in.ImportProcess.initializeFile(ImportProcess.java:482)
    at loci.plugins.in.ImportProcess.execute(ImportProcess.java:146)
    at loci.plugins.BF.openImagePlus(BF.java:95)
    at loci.plugins.BF.openImagePlus(BF.java:80)
    at com.mycompany.imagej.Confocal_Montage.main(Confocal_Montage.java:77)

这取决于我正在使用的生物形式的版本,该版本已在以后的版本中修复。不幸的是,后来的版本不在maven中央存储库上,而是在OpenMicroscopy存储库中,这意味着将它包含在pom中

<repository>
    <id>OpenMicroscopy</id>
    <url>http://maven.imagej.net/content/groups/public</url>
</repository>

以及bioformats插件的依赖

<dependency>
    <groupId>ome</groupId>
    <artifactId>bioformats_package</artifactId>
    <version>5.3.3</version>
    <type>pom</type>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>

ch.qos.logback:logback-classic排除是因为它中的重复类和org.slf4j:slf4j-simple,并且它有效!