【问题标题】:How to add maven dependencies as classpath libraries to Eclipse plugin Runtime?如何将 Maven 依赖项作为类路径库添加到 Eclipse 插件运行时?
【发布时间】:2015-10-21 15:22:37
【问题描述】:

我正在开发一个 Eclipse 插件,并且正在将其转换为 Maven 项目。我使用了“配置->转换为 Maven 项目”选项,并编写了 pom.xml 文件,其中包含适当的依赖项以及对 tycho 和 maven 插件的引用。

<properties>
    <tycho.version>0.23.0</tycho.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <sourceDirectory>src</sourceDirectory>
        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>${tycho.version}</version>
                <configuration>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <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>
                <target>
                    <artifact>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                    </artifact>
                </target>
                <environments>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>macosx</os>
                        <ws>cocoa</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

但是,maven 依赖库不会自动添加到项目的类路径中,即使我尝试将它们添加到 .classpath 文件中,例如 &lt;classpathentry kind="var" path="M2_REPO/net/sf/jung/jung-api/2.0.1/jung-api-2.0.1.jar"/&gt;(已配置 M2_REPO 类路径变量)我仍然收到 MANIFEST 文件中缺少类的异常。

是否可以在 eclipse 中设置项目根目录之外的类路径,如果可以,是否可以自动将 maven 依赖库添加到项目的类路径中?

【问题讨论】:

    标签: maven eclipse-plugin dependencies classpath tycho


    【解决方案1】:

    eclipse 插件仅将 osgi 包和插件作为其依赖项。如果您将依赖项作为普通 jar 提供,则不需要。清单文件将采用 eclipse 主页的 p2 存储库、目标定义文件或 eclipse 站点中可用的插件和包。所以我建议你将 maven 依赖 jar 转换为 osgi bundle 或插件,并将其作为依赖添加到 eclipse 插件中,这样你就不会在 maven 构建过程中遇到任何错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 2017-09-18
      • 2011-02-01
      • 2017-01-14
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      相关资源
      最近更新 更多