gpt4 book ai didi

java - maven-shade-plugin 和自定义打包类型

转载 作者:行者123 更新时间:2023-12-01 19:56:53 24 4
gpt4 key购买 nike

我正在尝试打包一个 OSGi bundle 及其内置依赖项。我使用 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.

这是我的项目的 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>

我怀疑我收到此错误是因为我使用“捆绑”打包类型,因此阴影插件无法识别存在实际的 jar 文件,因此提示主要 Artifact 。如何解决这个问题?

谢谢

最佳答案

我设法通过将项目的打包类型更改回“jar”并配置maven捆绑插件将osgi元数据注入(inject)最终的jar Artifact 来解决这个问题,而不必使用“bundle”打包,如maven bundle plugin documentation中所述。 .

用于将 OSGi 元数据注入(inject) jar 包的示例 Maven 捆绑插件配置:

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

关于java - maven-shade-plugin 和自定义打包类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262032/

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