将 Maven tycho-p2-plugin 与 SWT 一起使用

发布于 2024-09-07 09:26:48 字数 62 浏览 4 评论 0原文

如何使用 Eclipse P2 存储库和 Maven tycho-p2-plugin 构建 SWT 应用程序?

How do I build an SWT application using the Eclipse P2 repository and the Maven tycho-p2-plugin?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冧九 2024-09-14 09:26:56

第谷允许您构建和构建编译基于 eclipse 的东西,包括插件、功能和 RCP 应用程序。在官方项目页面上有很多很好的教程,但就我而言,我使用了示例项目( http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp04-rcp )。

但是,如果您不需要构建一些插件或 RCP 应用程序,我认为您不需要 tycho:您只需导入 SWT 作为普通的 Maven 依赖项并以这种方式构建您的应用程序...

Tycho allows you to build & compile eclipse-based stuff, including plugins, features, and RCP applications. On the official project page there are a tons of good tutorial, but in my case I used the sample project ( http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp04-rcp ).

However, if you do not need to build some plugins or a RCP application, I think you do not need tycho: you just can import SWT as a normal maven dependency and build your app that way...

江湖彼岸 2024-09-14 09:26:55

我发现了问题。背景:我正在构建 Xtext 为 DSL 生成的编辑器插件。

该插件依赖于 org.eclipse.swt;version=3.7.0打包eclipse-plugin。我列出了我的父 POM 中的所有必要环境

p2 存储库是我硬盘上的本地镜像,我通过导出目​​标定义(*.target 文件)来填充它。

问题是导出目标定义将创建看起来很像 p2 存储库的东西,但存在细微的差异。

例如,您必须在目标定义文件中定义目标环境(Linux/Windows/Mac、x86/x86_64、win32/cocoa/gtk)。如果您不指定任何内容,Eclipse 将使用当前平台。如果使用“*”,则所有 SWT 片段都将被省略。

这意味着:导出包含所有 SWT 片段(plugins/ 文件夹中的 30 个插件),它们在 contents.jar 中提到但是 artifact.jar 仅列出与您当前平台匹配的单个 SWT 片段(即捆绑包加上源代码)。

这对第谷来说还不够。

解决方案:使用以下小脚本创建正确的 p2 存储库:

# Where you exported the Target Definition
dir="$HOME/3.7.1-from-target-platform"

# Where the result should be written. Must be != dir
dest="$HOME/3.7.1-from-target-platform-fixed"

# Make sure subsequent invocations don't try to merge old stuff
rm -rf "$dest"

# Prepend "file:" to create a URL from the path
dest="file:$dest"

echo "Merging $dir..."
./eclipse -nosplash \
    -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \
    -metadataRepository "$dest" \
    -artifactRepository "$dest" \
    -repositoryName "3.7.1 Indigo Repository" \
    -source "$dir" \
    -compress -append -publishArtifacts

在正常运行的 Eclipse 安装中运行此脚本。

I found the problem. Background: I'm building the editor plugin which Xtext generates for DSLs.

The plugin depends on org.eclipse.swt;version=3.7.0. The packaging is eclipse-plugin. I'm listing all the necessary environments in my parent POM.

The p2 repository is a local mirror on my hard disk which I fill by exporting a Target Definition (*.target file).

The problem is that exporting a Target Definition will create something that looks a lot like a p2 repo but there are subtle differences.

For example, you have to define a target environment (Linux/Windows/Mac, x86/x86_64, win32/cocoa/gtk) in the Target Definition file. If you don't specify anything, Eclipse will use the current platform. If you use "*", all SWT fragments will be omitted.

This means: The export contains all the SWT fragments (30 plugins in the plugins/ folder), they are mentioned in the contents.jar but the artifact.jar only lists the single SWT fragment which matches your current platform (i.e. the bundle plus the sources).

This is not enough for Tycho.

Solution: Create a proper p2 repo using this small script:

# Where you exported the Target Definition
dir="$HOME/3.7.1-from-target-platform"

# Where the result should be written. Must be != dir
dest="$HOME/3.7.1-from-target-platform-fixed"

# Make sure subsequent invocations don't try to merge old stuff
rm -rf "$dest"

# Prepend "file:" to create a URL from the path
dest="file:$dest"

echo "Merging $dir..."
./eclipse -nosplash \
    -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \
    -metadataRepository "$dest" \
    -artifactRepository "$dest" \
    -repositoryName "3.7.1 Indigo Repository" \
    -source "$dir" \
    -compress -append -publishArtifacts

Run this inside of a working Eclipse installation.

江南烟雨〆相思醉 2024-09-14 09:26:54

您可以定义“target-platform-configuration”插件的目标环境。无论您正在为多个环境构建 RCP 或功能,您都可以让您的功能包含这些主机的 swt 片段。

        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho-version}</version>
            <configuration>
                <resolver>p2</resolver>
                <environments>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>solaris</os>
                        <ws>gtk</ws>
                        <arch>sparc</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>

feature.xml 中的片段

   <plugin
         id="org.eclipse.swt"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.gtk.linux.x86"
         os="linux"
         ws="gtk"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.win32.win32.x86"
         os="win32"
         ws="win32"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>

You can define the target environments for 'target-platform-configuration' plugin. Whatever you are building RCP or features for multiple environments, you can let your feature to include the fragments of swt for these hosts.

        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho-version}</version>
            <configuration>
                <resolver>p2</resolver>
                <environments>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>solaris</os>
                        <ws>gtk</ws>
                        <arch>sparc</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>

Snippet in feature.xml

   <plugin
         id="org.eclipse.swt"
         download-size="0"
         install-size="0"
         version="0.0.0"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.gtk.linux.x86"
         os="linux"
         ws="gtk"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>

   <plugin
         id="org.eclipse.swt.win32.win32.x86"
         os="win32"
         ws="win32"
         arch="x86"
         download-size="0"
         install-size="0"
         version="0.0.0"
         fragment="true"
         unpack="false"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文