本文介绍了使用指向本地p2存储库的tycho构建本地eclipse插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一些需要第三方插件和功能的Eclipse插件和功能。为了将这些依赖项包含在我的项目中,我创建了一个p2布局库。

I am creating some Eclipse plugin and features that require third-party plugins and features. In order to include these dependencies into my project, I created a p2 layout repository.

注意:我的p2工件不是Maven项目...但是,我使用Maven风格建筑。这是p2存储库的pom.xml

Note: My p2 artifacts are not Maven project... However, I am using Maven style building. Here is the pom.xml for the p2 repository

<properties>
    <tycho-version>0.18.0</tycho-version>
  </properties>

  <repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
  </repositories>

  <build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho.extras</groupId>
            <artifactId>tycho-p2-extras-plugin</artifactId>
            <version>${tycho-version}</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>publish-features-and-bundles</goal>
                    </goals>
                    <configuration>
                        <compress>false</compress>
                        <artifactRepositoryLocation>/mypath/target/repository</artifactRepositoryLocation>
                        <metadataRepositoryLocation>/mypath/target/repository</metadataRepositoryLocation>
                        <sourceLocation>/mypath/src</sourceLocation>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-p2-repository-plugin</artifactId>
            <version>${tycho-version}</version>
            <configuration>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>verify-repository</goal>
                        <goal>archive-repository</goal>
                    </goals>
                    <configuration>
                        <compress>false</compress>
                        <includeAllDependencies>true</includeAllDependencies>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-p2-publisher-plugin</artifactId>
          <version>${tycho-version}</version>
          <configuration>
            <publishArtifacts>true</publishArtifacts>
          </configuration>
        </plugin>
        <plugin><!-- enable the Tycho build extension -->
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho-version}</version>
            <extensions>true</extensions>
        </plugin>
    </plugins>
  </build>

上述构建成功,并创建(并验证)p2存储库。我在项目的目标/ 目录中获得以下结构

The above builds successfully, and creates (and verifies) a p2 repository. I get following structure in my target/ directory of the project

- Project
    ..
    ..
    - target
      - p2agent
         - org.eclipse.equinox.p2.core
         - org.eclipse.equinox.p2.engine
      - repository
        - features
        - plugins
          artifacts.xml
          content.xml
      <projectname>-<version>.zip <!-- This contains same things as repository directory here -->

现在,我使用Tycho构建我的插件和功能,并引用上面创建的p2存储库。我有我的插件和功能的以下项目结构

Now, I use Tycho for building my plugins and features and refer the p2 repository I created above. I have following project structure for my plugins and features

- bundle.parent
  - bundle.mainplugin
  - bundle.mainplugin.test.fragment
  - bundle.mainplugin.feature

这是我的bundle.parent pom.xml

Here is my bundle.parent pom.xml

<repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
        <repository>
                <id>third-party-eclipse-plugins</id>
                <layout>p2</layout>
                <url>file:///.../target/repository</url>
         </repository>
  </repositories>
  <modules>
    <module>../bundle.mainplugin</module>
    <module>../bundle.mainplugin.test.fragment</module>
    <module>../bundle.mainplugin.feature</module>
  </modules>
  <build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-maven-plugin</artifactId>
      <version>${tycho-version}</version>
      <extensions>true</extensions>
    </plugin>
  </plugins>
</build>

最后,我运行目标 mvn clean install 在父pom.xml上。不幸的是,当我的插件中的类扩展插件中的一些类时, mvn-compile 抛出编译问题。 (运行时也需要这些类)。这是错误:

Finally, I run goals mvn clean install on the parent pom.xml. Unfortunately, mvn-compile throws compilation issues when classes in my plugin extend some of the classes in plugins. (The classes are also required at run-time). Here is the error:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.18.0:compile (default-compile
) on project <Project Name>: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: copied.org.apache.maven.plugin.CompilationFailureException: Compilation failure
    at copied.org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:442)
    at org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:239)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

我的问题:

从编译器错误中,我相信Tycho不知何故不将这些第三方工件提供给我的课程有一个编译错误。有没有办法确定我的插件类是否存在于Tycho类路径中?

From the compiler errors, I believe Tycho is somehow not making these third-party artifacts available to my classes for which there is a compiler error. Is there a way to determine if my plugin classes exist in the Tycho classpath?

更新

检查了我想从

java -jar /home/.../eclipse-3.8.2/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -debug -consolelog -application org.eclipse.equinox.p2.director -repository file:///home/../target/repository -list

所有第三方软件包成功显示。

All third-party bundles showed up successfully.

推荐答案

Sebastian Zarnekow的回答给了我一个提示。

Sebastian Zarnekow's answer gave me a hint.

Error while building an xtext project with ant: Generation of the Grammar classes fails

从错误消息中可以推断,maven无法从注入创建语言模型。原因在上面的链接中解释:

As you can infer from the error message, maven fails to create language models from injection. The reason is explained in the link above:

解决方案是您需要给EMFGenerator一个新的声明模型目录应该在哪里。在**。mwe2文件中,替换以下代码

The solution is you need to give EMFGenerator a new declaration of where the model directory should be. In **.mwe2 file, replace the following code

fragment = ecore.EMFGeneratorFragment auto-inject {}

fragment = ecore.EMFGeneratorFragment auto-inject {
    javaModelDirectory = "/${projectName}/src-gen"
}

应该诀窍。

这篇关于使用指向本地p2存储库的tycho构建本地eclipse插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!