gpt4 book ai didi

java - 使用loci.plugins(生物格式)时出现SLF4J version_mismatch错误

转载 作者:行者123 更新时间:2023-11-30 06:24:40 32 4
gpt4 key购买 nike

我正在尝试为 czi 文件构建一个 imagej 插件。为了调试插件,我有一个“main”函数,可以打开 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中的解决方案IE。将 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>

任何关于如何解决这个问题的想法都会很棒,它让我陷入困境

最佳答案

弄清楚了,所以对于其他偶然发现这个问题的人来说,有两个问题。首先,我确实需要包含 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>

以及生物格式插件的依赖项

<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,瞧,它有效!

关于java - 使用loci.plugins(生物格式)时出现SLF4J version_mismatch错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47445270/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com