maven - 在 Jenkins 插件中使用外部 dll 库

标签 maven tomcat jenkins jenkins-plugins jacob

要使用外部 com 对象,我必须将 Jacob jar 和 dll 库包含到我的 Jenkins 插件中。我找到了 jacob_excel_reader plugin它使用 Jacob,但解决方案并不令我满意。开发人员将 jar 依赖添加到 pom.xml文件:

<dependency>
  <groupId>com.jacob</groupId>
  <artifactId>jacob</artifactId>
  <version>1.17-M2</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/lib/jacob.jar</systemPath>
</dependency>

并通过参数整合dll文件:

-Djava.library.path=${workspace_loc:jacob_excel_reader}\lib

这是集成 dll 的唯一方法吗?我尝试了另一种方法,但我中途卡住了,我绝对需要你的帮助!

首先,我将 jar 和 dll 文件的依赖项添加到 pom.xml :

<dependency>
  <groupId>net.sf.jacob-project</groupId>
  <artifactId>jacob</artifactId>
  <version>1.14.3</version>
</dependency>
<dependency>
  <groupId>net.sf.jacob-project</groupId>
  <artifactId>jacob</artifactId>
  <version>1.14.3</version>
  <classifier>x86</classifier>
  <type>dll</type>
</dependency>

并配置将dll文件复制到target/APPNAME/WEB-INF/lib :

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-dependencies</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <excludeTransitive>true</excludeTransitive>
            <includeArtifactIds>jacob</includeArtifactIds>
            <includeTypes>dll</includeTypes>
            <failOnMissingClassifierArtifact>true</failOnMissingClassifierArtifact>
            <silent>false</silent>
            <outputDirectory>target/APPNAME/WEB-INF/lib</outputDirectory>
            <overWriteReleases>true</overWriteReleases>
            <overWriteSnapshots>true</overWriteSnapshots>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

当我运行 mvn package默认测试会抛出警告:

SEVERE: Failed Inspecting plugin C:\...\AppData\Local\Temp\hudson7697228528744044800tmp\the.jpl
java.util.zip.ZipException: error in opening zip file

但它会将 dll 和 jar 文件复制到 target/APPNAME/WEB-INF/lib . 为什么它也复制 jar 文件以及导致 ZipException 的原因是什么?

在插件执行期间,插件抛出:

FATAL: no jacob-1.14.3-x86 in java.library.path
java.lang.UnsatisfiedLinkError: no jacob-1.14.3-x86 in java.library.path

找不到dll文件,为什么?我可以添加target/APPNAME/WEB-INF/lib吗?到 java.library.path 不使用上面的参数?

最佳答案

一般来说,您需要做的是掌握 DLL 所在的路径,然后给 Jacob 提示在哪里可以找到该路径。

关于第一步,这可行:

String relativeWebPath = "/WEB-INF/lib/";
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);

或者,例如,如果您的 DLL 文件打包在 JAR 中,您必须先将其解压缩到已知位置。

InputStream in = SomeClassInTheJAR.class.getResourceAsStream("/jacob-1.17-x86.dll");
File fileOut = new File(tempDir + "/jacob-1.17-x86.dll");
String absoluteDiskPath = tempDir;

OutputStream out = FileUtils.openOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();

关于第二步,让Jacob知道DLL路径,这样做:

System.setProperty(com.jacob.com.LibraryLoader.JACOB_DLL_PATH, absoluteDiskPath);

但是,它并不比命令行标志好多少。只是不同 ... 似乎没有“简单”(即开箱即用)的方式来从一般的 WebApp 中加载 DLL,或者特别是从 Jenkins 插件中加载 DLL。

关于maven - 在 Jenkins 插件中使用外部 dll 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19378259/

相关文章:

java - tomcat web应用程序的并行编程

java web app - 无法检索不是来自根文件夹的页面

tomcat - 具有两个 tomcat 服务器的 CORS 设置

docker - Openshift Jenkins(2)— docker :未找到命令

intellij 和 tomcat 上的 java ee maven 项目无法解析为类型

maven - 如何将 AngularJS 2 与 Magnolia CMS 结合使用

java - 在 Eclipse 中创建新 Maven 项目并将其带到 Github 的工作流程

java - 如何创建我的项目使用的所有 jar 的内部远程存储库?

windows - 除非已为构建用户打开交互式登录,否则 Jenkins Windows slave 上的 cmake 失败

docker - docker 中的Jenkins从属无法使用JNLP4连接