Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java maven shade插件和自定义包装类型_Java_Maven_Osgi_Osgi Bundle_Maven Shade Plugin - Fatal编程技术网

Java maven shade插件和自定义包装类型

Java maven shade插件和自定义包装类型,java,maven,osgi,osgi-bundle,maven-shade-plugin,Java,Maven,Osgi,Osgi Bundle,Maven Shade Plugin,我正在尝试将OSGi捆绑包与它的内置依赖项打包在一起。我使用maven shade plugin 2.3包含一些依赖项,但在打包阶段失败,出现以下错误: [ERROR] The project main artifact does not exist. This could have the following [ERROR] reasons: [ERROR] - You have invoked the goal directly from the command line. This is

我正在尝试将OSGi捆绑包与它的内置依赖项打包在一起。我使用maven shade plugin 2.3包含一些依赖项,但在打包阶段失败,出现以下错误:

[ERROR] The project main artifact does not exist. This could have the following
[ERROR] reasons:
[ERROR] - You have invoked the goal directly from the command line. This is not
[ERROR]   supported. Please add the goal to the default lifecycle via an
[ERROR]   <execution> element in your POM and use "mvn package" to have it run.
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please
[ERROR]   remove this binding from your POM such that the goal will be run in
[ERROR]   the proper phase.
[ERROR] - You removed the configuration of the maven-jar-plugin that produces the main artifact.
[错误]项目主工件不存在。这可能有以下几点
[错误]原因:
[错误]-您已直接从命令行调用目标。这不是
支持[错误]。请通过
[ERROR]元素,并使用“mvn包”使其运行。
[错误]-您已将目标绑定到“打包”之前的生命周期阶段。请
[错误]从POM中删除此绑定,以便在中运行目标
[错误]正确的相位。
[错误]-您删除了生成主工件的maven jar插件的配置。
以下是我的项目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>ru.multicabinet.plugin</groupId>
<artifactId>testArtifact</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>bundle</packaging>

<dependencies>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.compendium</artifactId>
        <version>4.3.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.apache.felix.scr.annotations</artifactId>
        <version>1.9.6</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>

</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
            <version>1.15.0</version>
            <executions>
                <execution>
                    <id>generate-scr-scrdescriptor</id>
                    <goals>
                        <goal>scr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>

            <configuration>
                <remoteOBR>obr-repo</remoteOBR>
                <instructions>
                    <Bundle-Description>Test Plugin</Bundle-Description>
                    <Import-Package>
                        org.osgi.framework,
                        javax.net.ssl,
                        javax.mail,
                        javax.mail.internet,
                        javax.activation
                    </Import-Package>
                    <Bundle-SymbolicName>ru.multicabinet.plugin.license.testArtifact</Bundle-SymbolicName>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>commons-codec:commons-codec</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>


</project>

4.0.0
ru.multicabinet.plugin
遗嘱事实
1.0-快照
捆
org.osgi
org.osgi.core
4.3.1
org.osgi
org.osgi.compendium
4.3.1
朱尼特
朱尼特
4.4
org.apache.felix
org.apache.felix.scr.annotations
1.9.6
假如
javax.mail
邮件
1.4.7
javax.activation
激活
1.1.1
org.apache.felix
maven scr插件
1.15.0
生成scr脚本
可控硅
org.apache.felix
maven捆绑插件
真的
obr回购
测试插件
org.osgi.framework,
javax.net.ssl,
javax.mail,
javax.mail.internet,
javax.activation
ru.multicabinet.plugin.license.testArtifact
org.apache.maven.plugins
maven阴影插件
2.3
进程类
阴凉处
commons编解码器:commons编解码器
我怀疑我得到这个错误是因为我使用的是“bundle”打包类型,所以shade插件没有识别出有一个实际的jar文件,因此抱怨主工件。如何解决这个问题


感谢

我通过将项目的打包类型改回“jar”并配置maven bundle插件将osgi元数据注入到最终的jar工件中,而不必使用中所述的“bundle”打包来解决这个问题

将OSGi元数据注入jar包的maven bundle插件配置示例:

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>  
     <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    </archive> 
  </configuration>
</plugin>  
<plugin>   
   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <executions>
     <execution>
     <id>bundle-manifest</id>
     <phase>process-classes</phase>
     <goals>    
       <goal>manifest</goal>
     </goals>   
     </execution>
   </executions>
</plugin>

maven jar插件
${project.build.outputDirectory}/META-INF/MANIFEST.MF
org.apache.felix
maven捆绑插件
捆绑清单
进程类
显示

如果你想对一个包进行着色处理,你需要制作一个单独的模块,在这个模块中你可以创建一个着色的变体,但不像你在模块中已经意识到的那样,在模块中打包。@khmarbaise但是这个单独的包将丢失其中的所有osgi元数据,因为它不是一个包,所以它对我没有用处。我正在寻找一种方法,使它既成为一个有效的OSGi包,又包含我需要的所有依赖项。