0

我正在写一个 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 文件复制/粘贴到 FiJi 的插件中,并检查我是否可以在重新启动 FiJi 后在插件中看到我的插件;

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 网页以进行组装,但找不到我所缺少的。

顺便提一句; 如果我在 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 information -->
    <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>
4

0 回答 0