You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将含软链接的第三方JNI库上传至本地Nexus仓库

Alright, let's tackle this problem step by step. Since you can't modify the original foo.jar or the .so files, we need to work around the soft link issue first (because soft links won't work reliably in a Nexus repository) and then get everything uploaded properly.

Soft links are environment-specific—once you upload them to Nexus and download them elsewhere, the link target won't exist. So we need to replace the soft link with an actual copy of the file:

  • Make a duplicate of libfoo.so.1.0 and rename it to libfoo.so. Now you have two standalone files instead of a link and its target, which will work across environments.

Option 1: Package JAR and SO Files into a Single Artifact

If you want all related files to live as one unit in Nexus, this is the way to go:

  1. Create a temporary Maven project with this structure:

    temp-foo-project/
    ├── pom.xml
    └── src/
        └── main/
            └── resources/
                └── META-INF/
                    └── native/
                        ├── libfoo.so
                        └── libfoo.so.1.0
    

    (You don't need any Java code here—this project just wraps the existing files.)

  2. Add this pom.xml to the project, adjusting paths and Nexus details to match your setup:

    <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.your-org</groupId>
        <artifactId>foo-with-native</artifactId>
        <version>1.0.0</version>
        <packaging>jar</packaging>
    
        <dependencies>
            <!-- Pull in the original foo.jar as a system dependency -->
            <dependency>
                <groupId>com.foo-group</groupId>
                <artifactId>foo</artifactId>
                <version>1.0.0</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/path/to/your/foo.jar</systemPath>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <!-- Package everything into a single JAR -->
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.4.2</version>
                    <executions>
                        <execution>
                            <id>assemble-all</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptorRefs>
                                    <descriptorRef>jar-with-dependencies</descriptorRef>
                                </descriptorRefs>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Deploy to Nexus -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>3.0.0-M2</version>
                    <configuration>
                        <repositoryId>nexus-thirdparty</repositoryId>
                        <url>http://your-nexus-url/repository/thirdparty/</url>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    
  3. Run this command to build and upload the artifact to Nexus:

    mvn clean deploy
    

    Note: Make sure your Maven settings.xml has credentials for the nexus-thirdparty repository ID.

Option 2: Upload JAR and SO Files as Separate Artifacts

If you prefer to manage the Java library and native libraries independently, you can upload them separately:

  1. Upload the original foo.jar:
    Use Maven's deploy-file command directly:

    mvn deploy:deploy-file \
      -DgroupId=com.foo-group \
      -DartifactId=foo \
      -Dversion=1.0.0 \
      -Dpackaging=jar \
      -Dfile=/path/to/your/foo.jar \
      -DrepositoryId=nexus-thirdparty \
      -Durl=http://your-nexus-url/repository/thirdparty/
    
  2. Upload the native libraries:
    Package the two .so files into a JAR (or ZIP) and upload it as a separate artifact:

    # First, package the SO files into a JAR
    jar cvf foo-native-1.0.0.jar libfoo.so libfoo.so.1.0
    
    # Then upload to Nexus
    mvn deploy:deploy-file \
      -DgroupId=com.foo-group \
      -DartifactId=foo-native \
      -Dversion=1.0.0 \
      -Dpackaging=jar \
      -Dfile=foo-native-1.0.0.jar \
      -DrepositoryId=nexus-thirdparty \
      -Durl=http://your-nexus-url/repository/thirdparty/
    

    Later, when using the library, just add dependencies on both foo and foo-native in your project's pom.xml.

Key Notes

  • Always replace soft links with actual file copies—this avoids broken links when downloading from Nexus to other environments.
  • Double-check your Nexus repository settings to ensure it allows uploads to the third-party repo, and that your Maven settings.xml has the correct username/password for the repository ID.
  • When using the library in your project, you'll need to ensure the native libraries are on the java.library.path or use a JNI loader that can find them (like from the META-INF/native directory if you used Option 1).

内容的提问来源于stack exchange,提问作者Ramón J Romero y Vigil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:16:20