将 Maven tycho-p2-plugin 与 SWT 一起使用
题
如何使用 Eclipse P2 存储库和 Maven tycho-p2-plugin 构建 SWT 应用程序?
解决方案
您可以定义“目标平台 - 配置”插件的目标环境。无论您是为多种环境构建的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>
pronage.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"/>
其他提示
我发现了问题。背景:我正在构建 Xtext 为 DSL 生成的编辑器插件。
该插件依赖于 org.eclipse.swt;version=3.7.0
. 。这 packaging
是 eclipse-plugin
. 。我是 列出我的父 POM 中的所有必要环境.
p2 存储库是我硬盘上的本地镜像,我通过导出目标定义(*.target 文件)来填充它。
问题是导出目标定义将创建看起来很像 p2 存储库的东西,但存在细微的差异。
例如,您必须在目标定义文件中定义目标环境(Linux/Windows/Mac、x86/x86_64、win32/cocoa/gtk)。如果您不指定任何内容,Eclipse 将使用当前平台。如果使用“*”,则所有 SWT 片段都将被省略。
这意味着:导出包含所有 SWT 片段(30 个插件) plugins/
文件夹),它们在 contents.jar
但是 artifact.jar
仅列出与您当前平台匹配的单个 SWT 片段 (IE。捆绑包加上来源)。
这对第谷来说还不够。
解决方案:使用这个小脚本创建一个合适的 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 安装中运行它。
Tycho允许您构建和编译基于Eclipse的东西,包括插件,功能和RCP应用程序。在官方项目页面上,有大量的好教程,但就我而言,我使用了示例项目( http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/tree/itp04-rcp ).
但是,如果您不需要构建一些插件或RCP应用程序,我认为您不需要Tycho:您只能将SWT导入正常的Maven依赖性,并以这种方式构建您的应用程序...