使用Maven构建时,缺少必需的Eclipse插件中的类

时间:2015-04-13 01:51:43

标签: maven tycho

我想用Tycho做最简单的Maven构建,但是无法让它工作。我的项目只有一个pom.xml文件,没有父节点或兄弟节点POM。

当我运行mvn clean install时,我收到很多编译错误,例如:

[ERROR] /dir/file.java:[8,33] package org.eclipse.core.commands does not exist

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

    <groupId>com.mygroup</groupId>
    <artifactId>myartifact</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <name>myartifact</name>
    <description>Maven stuff</description>

    <properties>
        <tycho.version>0.20.0</tycho.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <luna-repo.url>http://download.eclipse.org/releases/luna</luna-repo.url>
        <kepler-repo.url>http://download.eclipse.org/releases/kepler</kepler-repo.url>
    </properties>

    <repositories>
        <repository>
            <id>luna</id>
            <url>${luna-repo.url}</url>
            <layout>p2</layout>
        </repository>
        <repository>
            <id>kepler</id>
            <url>${kepler-repo.url}</url>
            <layout>p2</layout>
        </repository>
    </repositories>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <pde>true</pde>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <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>
                    <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>
        </plugins>
    </build>
</project>

这就是我的清单文件的样子:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: pluginname
Bundle-SymbolicName: pluginname;singleton:=true
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Activator: com.mygroup.pluginname.ui.Activator
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.core.resources,
 org.eclipse.ui.ide,
 org.apache.commons.io;bundle-version="2.0.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .

我真的不知道我在这里失踪了什么。

2 个答案:

答案 0 :(得分:4)

您的项目未指定包装类型,因此默认为jar。对于jar项目,Tycho没有做任何事情,所以你所有其他正确的配置都没有效果。

要激活Tycho,您需要添加配置

<packaging>eclipse-plugin</packaging>

然后,Tycho将根据您在OSGi清单中声明的​​依赖关系来解析构建类路径。


请注意,Tycho没有使用maven-compiler-plugin,因此在激活Tycho后,此配置无效。另外,我没有将maven-eclipse-plugin与Tycho结合使用的经验。我建议使用M2Eclipse在Eclipse中导入项目,而不是那个插件。

答案 1 :(得分:-1)

您需要为源代码中使用的库集添加依赖项。

Maven没有被告知获取或管理它们,因此Eclipse不知道它们存在。当您尝试在源代码中导入它们并进行编译时,它会产生您看到的错误。

例如:

<dependencies>
    ...
    <dependency>
        <groupId>org.eclipse.core</groupId>
        <artifactId>commands</artifactId>
        <version>3.3.0-I20070605-0010</version>
    </dependency>
    ...
</dependencies>

请参阅eclipse repository了解其他图书馆所需的信息。

编辑:要修复SWT编译错误,请按照SWT-repo project's webpage上显示的步骤操作。 win32 Intel x86 / x64架构的一个示例:

<dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
    <version>4.4</version>
</dependency>

根据您的平台更改您的。

相关问题