带有依赖项或 uberjar 程序集的 ImageJ 插件在 FiJi 插件中不可用

问题描述

我正在编写 ImageJ/Fiji 插件。当我使用以下 pom.xmluberjar.xml 构建我的项目时,我得到以下 jar 文件

MyFirstPlg-0.1.0.jar
MyFirstPlg-0.1.0-sources.jar
MyFirstPlg-0.1.0-uberjar.jar
MyFirstPlg-0.1.0-jar-with-dependencies.jar

如果我一次将每个 jar 文件复制/粘贴到斐济的插件中,并在重新启动斐济后检查是否可以在插件中看到我的插件

MyFirstPlg-0.1.0.jarMyFirstPlg-0.1.0-uberjar.jar:我可以看到我的插件但缺少依赖项,所以它会引发错误对于依赖,例如java.lang.NoClassDefFoundError: org/tensorflow/ndarray/ndarray。虽然,根据大小 MyFirstPlg-0.1.0-uberjar.jar 是最大的,我认为它具有所有依赖项。

MyFirstPlg-0.1.0-sources.jarMyFirstPlg-0.1.0-jar-with-dependencies.jar:我在插件中没有看到我的插件.

我想知道在我的 pom.xml 和 uberjar.xml 文件中缺少什么导致了这个问题。我已在 Maven 网页中检查了程序集 here,但找不到我遗漏的内容

顺便说一句;如果我在 Eclipse 中将我的插件作为 Java 应用程序运行,它不会引发任何错误并按预期工作。

以下是 pom.xml 文件的主要部分。我策划了认所需的部分;例如,邮件、scm、许可证、贡献者等

<?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>
    
    <!-- scijava is required and put in parent,I donot kNow why! -->
    <!-- but is required for; org.scijava.* -->
    <parent>
        <groupId>org.scijava</groupId>
        <artifactId>pom-scijava</artifactId>
        <version>26.0.0</version>
        <relativePath />
    </parent>
        
    <!-- this is my project @R_232_4045@ion -->
    <groupId>org.mic.imageseg</groupId>
    <artifactId>MyFirstPlg</artifactId>
    <version>0.1.0</version>
    
    <!-- here mailing list,contributers,license,scm,etc,defaults required -->
    
    <repositories>
        <repository>
            <id>scijava.public</id>
            <url>https://maven.scijava.org/content/groups/public</url>
        </repository>
    </repositories>
    
    
    <build>
    <resources>
     <resource>
       <directory>src/models</directory> <!-- I have some tensorflow model to be included in the jar file -->
     </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
        <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase> 
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <descriptors> 
              <descriptor>src/assembly/uberjar.xml</descriptor>  <!-- this where my uberjar.xml file located.-->
            </descriptors>
        <includes>
            <include>
                <groupId>net.imagej</groupId>
                <artifactId>imagej</artifactId>
            </include>
            <include>
                <groupId>org.tensorflow</groupId>
                <artifactId>tensorflow-core-platform</artifactId>
                <version>0.3.1</version>
            </include>
        </includes>
        </configuration>
        </plugin>
    </plugins>
    </build>
    
    <!-- here goes dependencies -->
    <dependencies>
        <dependency>
            <groupId>net.imagej</groupId>
            <artifactId>imagej</artifactId>
        </dependency>
        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow-core-platform</artifactId>
            <version>0.3.1</version>
        </dependency>
    </dependencies>
    
</project>

这是我的 uberjar.xml,它位于 src/assembly 文件夹中。

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
    <id>uberjar</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <unpack>false</unpack>
          <scope>runtime</scope>
          <useProjectArtifact>true</useProjectArtifact>
        </dependencySet>
      </dependencySets>
      <fileSets>
        <fileSet>
          <directory>${project.build.outputDirectory}</directory>
          <outputDirectory>\</outputDirectory>
        </fileSet>
      </fileSets>
</assembly>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)