gpt4 book ai didi

java - 在 Maven2 中使用 Sigar 的问题

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

我在将 Sigar 与 Maven2 结合使用时遇到错误。我知道它找不到 native 库(dll 或 .so),因为我知道我无法将 native 库复制到我的 WEB-INF/lib 目录中...我的问题是“如何将 lib 文件目录复制到我的 WAR 文件中的 WEB-INF/lib 使用 Maven?

我要复制的目录是:${basedir}/lib/我要复制到的目录是:${webapp.output}/WEB-INF/lib(我想?)

这里是错误:

java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getLoadAverage()

这是我的 pom 文件:

<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>

<groupId>com.testing</groupId>
<artifactId>TestAgent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>TestAgent</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.35</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>org.hyperic</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sigar.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>platform</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>

<build>
<testSourceDirectory>src/test/java</testSourceDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<!-- <configuration> section added to pick up the WEB-INF/web.xml inside WebContent -->
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
</resource>
</webResources>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library EclipseLink (JPA 2.0)</name>
</repository>
</repositories>
</project>

最佳答案

您可以配置 Maven war 插件来复制额外的文件/文件夹,如图所示 here .像下面这样的东西。

    <configuration>
<webResources>
<resource>
<directory>lib</directory>
<!-- override the destination directory for this resource -->
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
</configuration>

关于java - 在 Maven2 中使用 Sigar 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11731634/

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