2017-11-25 244 views
1

我想使用maven bundle插件將tibjms.jar和javax.jms-api-2.0.jar捆綁到一個包中。由於tibjms.jar不是在Maven回購我第一次把它添加到我的本地回購:如何在maven中捆綁第三方jar?

mvn install:install-file -Dfile=/home/riyafa/Documents/Workspace/Support/NNINSURANCESUB-17/tibco/libs/jms-2.0.jar -DgroupId=com.tibco -DartifactId=tibjms -Dversion=4.4.0 -Dpackaging=jar -DgeneratePom=false 

然後,我創建了以下POM文件,並建立了它:

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

    <groupId>org.riyafa</groupId> 
    <artifactId>tibco</artifactId> 
    <packaging>bundle</packaging> 
    <version>1</version> 

    <dependencies> 
     <dependency> 
      <groupId>com.tibco</groupId> 
      <artifactId>tibjms</artifactId> 
      <version>4.4.0</version> 
      <type>jar</type> 
     </dependency> 

     <dependency> 
      <groupId>javax.jms</groupId> 
      <artifactId>javax.jms-api</artifactId> 
      <version>2.0</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <version>3.3.0</version> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
         <Bundle-Name>${project.artifactId}</Bundle-Name> 
         <Export-Package> 
          com.tibco.tibjms.*, 
          com.tibco.tibjms.naming.*, 
          com.tibco.tibjms.naming.tibjmsnaming.*, 
         </Export-Package> 
         <Import-Package> 
          *, 
          !javax.jms.*, 
         </Import-Package> 

         <Embed-Dependency> 
          javax.jms-api;scope=compile|runtime;inline=false; 
         </Embed-Dependency> 
        </instructions> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

構建成功,但我只看到生成的jar中的javax.jms-api-2.0.jar: enter image description here

我想捆綁兩個罐子。當其中一個罐子是一個thirparty罐子時,我怎麼能做到這一點?我也嘗試添加jar到pom文件作爲外部庫,它不起作用。

回答

1

難道你沒有忘記爲tibjms添加EmbedDependency?您還可以嵌入所有的編譯和運行時depenedencies:

<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> 

請注意,javax.jms-api已經打包成捆。如果tibco工件的唯一用途是將tibjmsjms-api捆綁在一起,則可以考慮完全跳過它,而是將tibjms作爲捆綁包進行打包。然後,您可以將tibjmsjms-api作爲單獨的捆綁包進行部署。

+0

謝謝!我希望它們在單個包中,因爲我希望由jms-api公開的方法僅對tibjms.jar可見,因爲它與另一個jar衝突。 –

+0

關於能見度的好處! – gjoranv

相關問題