简体   繁体   English

需要Apache commons-lang3作为使用Tycho构建的Eclipse插件的依赖项

[英]Need Apache commons-lang3 as dependency of an Eclipse plugin built with Tycho

I'm having one of those nights... I'm developing an Eclipse plugin using Tycho (the Maven extension), and at some point I wanted simply to use the class StringUtils from org.apache.commons . 我度过了一个夜晚……我正在使用Tycho(Maven扩展)开发Eclipse插件,在某个时候,我只想使用org.apache.commons StringUtils类。 After some research, the only way that I could find is the following code in my pom.xml parent file: 经过一番研究,我唯一可以找到的方法是在pom.xml父文件中的以下代码:

  <dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho.version}</version>
        <extensions>true</extensions>
      </plugin>

      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <version>${tycho.version}</version>
        <configuration>
            <pomDependencies>consider</pomDependencies>
          <environments>
            <environment>
              ...

This didn't work, and any other solution that I tried didn't work either. 这是行不通的,我尝试过的任何其他解决方案也都行不通。 I'm using Maven for the first time, so maybe I'm missing something (or a lot of things)... Does anyone have an idea? 我是第一次使用Maven,所以也许我错过了一些(或很多东西)...有人有想法吗? I'd be very thankful :o) 我会非常感激:o)

Your configuration looks correct. 您的配置看起来正确。 So if it doesn't work, you are probably missing the dependency declaration in the MANIFEST.MF. 因此,如果它不起作用,则可能是缺少MANIFEST.MF中的依赖项声明。 To do this, eg add Require-Bundle: org.apache.commons.lang3 in that file. 为此,例如在该文件中添加Require-Bundle: org.apache.commons.lang3

Background: A dependency in the POM doesn't automatically mean for Tycho that your bundle also automatically has this dependency. 背景:POM中的依赖关系并不自动代表Tycho您的捆绑软件也自动具有此依赖关系。 It only means that the artifact will be added to the target platform (given that pomDependencies=consider is configured and the artifact is an OSGi bundle - both is true in your case). 这仅意味着将工件添加到目标平台(假设已配置pomDependencies=consider且工件为OSGi捆绑软件-两种情况均适用)。 Once it is in the target platform, it can be used to resolve the dependencies declared in your bundle's MANIFEST.MF. 将其放入目标平台后,就可以用来解析在软件包的MANIFEST.MF中声明的依赖项。

It sounds like you need to "upgrade" to using a target platform to define your target. 听起来您需要“升级”到使用目标平台来定义目标。

How are you achieving this dependency in your development environment? 您如何在开发环境中实现这种依赖性? If you are not using a target platform, you are inheriting whatever plug-ins are installed in your development (that is the default target platform). 如果您没有使用目标平台,那么您将继承开发中安装的任何插件(这是默认目标平台)。

Create Target Platform 创建目标平台

First create a target platform. 首先创建目标平台。 I recommend using the Target Platform Definition DSL and Generator to create and edit the target platform. 我建议使用目标平台定义DSL和生成器来创建和编辑目标平台。

The tpd file will look something like this for orbit tpd文件在轨道上看起来像这样

target "name"

with source requirements

location "http://download.eclipse.org/tools/orbit/downloads/drops/R20150519210750/repository/" mars-orbit {
    org.apache.commons.lang3
}

location "http://download.eclipse.org/releases/mars" mars-release {
    org.eclipse.platform.feature.group
    org.eclipse.equinox.executable.feature.group
    org.eclipse.e4.rcp.feature.group
    org.eclipse.ui.trace
    org.eclipse.pde.feature.group
}

This example uses the already created OSGi bundles for third-parties. 本示例将已创建的OSGi捆绑软件用于第三方。 You can choose which release of orbit and browse all the available packages on the Orbit Site . 您可以选择哪个版本的轨道,并浏览“ 轨道站点”上的所有可用软件包。 You can also use auto-completion in the tpd editor. 您也可以在tpd编辑器中使用自动完成功能。

Tycho Using Target Platform 第谷使用目标平台

Place the target file in a new plug-in. target文件放置在新的插件中。 Name the target file the same as the plug-in. 将目标文件命名为与插件相同的名称。 (eg com.example.releng.targetplatform.target is the name of the target file in this example.) (例如,在此示例中, com.example.releng.targetplatform.target是目标文件的名称。)

In this project, a pom that looks like this: 在此项目中,一个pom如下所示:

<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>
  <artifactId>com.example.releng.targetplatform</artifactId>
  <packaging>eclipse-target-definition</packaging>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>com.example.releng</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../com.example.releng</relativePath>
  </parent>
</project>

You can configure (in your releng pom.xml) the target configuration like this: 您可以这样配置目标文件(在releng pom.xml中):

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <target>
            <artifact>
                <groupId>eGui</groupId>
                <artifactId>com.example.releng.targetplatform</artifactId>
                <version>1.0.0-SNAPSHOT</version>
            </artifact>
        </target>
    </configuration>
</plugin>

Tutorial 讲解

Have a look at Code & Me's excellent tutorial on Tycho, it goes into more detail and over many steps goes from new project to a complete Tycho. 看看Code&Me关于Tycho 的出色教程 ,它会更详细地介绍,从新项目到完整的Tycho都要经过很多步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Apache commons-lang3 中的 MethodUtils 调用私有静态方法 - Invoke private static method with MethodUtils from Apache commons-lang3 无法解析org.apache.commons:commons-lang3:3.0对等方未通过身份验证的gradle 2.2.1 - Could not resolve org.apache.commons:commons-lang3:3.0 peer not authenticated gradle 2.2.1 在使用Tycho构建的Eclipse插件中加载Antlr jar的加载程序约束违规 - Loader Constraint Violation loading Antlr jar in Eclipse plugin built with Tycho 如何使用 commons-lang3 实现 RecursiveToStringStyle 和 JSON_STYLE - How have RecursiveToStringStyle and JSON_STYLE using commons-lang3 即使在Struts 2.3.24中添加commons-lang3库之后,也不会出现NoClassDefFoundError - NoClassDefFoundError even after adding commons-lang3 library in Struts 2.3.24 将WAR部署到Wildfly 14时,commons-lang3的ClassNotFoundException - ClassNotFoundException for commons-lang3 when deploying WAR to Wildfly 14 Java:无法解析导入org.apache.commons.lang [Eclipse] - Java: The import org.apache.commons.lang cannot be resolved [Eclipse] 在更多的eclipse插件中使用apache.commons.lang - Using apache.commons.lang in more eclipse plugins Maven Tycho插件和Eclipse Babel - Maven Tycho Plugin and Eclipse Babel Apache Commons Lang异常 - Apache Commons Lang Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM