Maven - Include dependent libs in jar without unpacking dependencies?

后端 未结 3 455
Happy的楠姐
Happy的楠姐 2021-01-03 21:19

We\'re trying to build a client jar that includes unpacked dependent jar\'s. And the manifest should have class-path entries to the dependent jars. T

3条回答
  •  被撕碎了的回忆
    2021-01-03 22:07

    You can add your dependencies as jar files to your jar:

    assembly-descriptor.xml

    
        uberjar
        
            jar
        
        false
        
            
                false
                runtime
                false
            
        
        
            
                ${project.build.outputDirectory}
                .
            
        
    
    

    pom.xml

    
        org.apache.maven.plugins
        maven-assembly-plugin
        2.6
        
            
                make-uberjar
                package
                
                    single
                
                
                    src/main/assemble/assembly-descriptor.xml
                
            
        
    
    

    But unfortunately you can't use the Class-Path header in manifest.mf, see Adding Classes to the JAR File's Classpath:

    Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

提交回复
热议问题