首页 > 其他分享 >Eclipse + Maven+Tycho 打包知识整理

Eclipse + Maven+Tycho 打包知识整理

时间:2024-09-13 15:49:41浏览次数:1  
标签:插件 target eclipse Eclipse tycho Maven Tycho test org

环境:
Eclipse:2023-06(4.28.0)
Maven: 3.9.5
Tycho: 4.0.8
JRE: 17

需要创建下面几种工程


- org.test.root //父工程,用来统一配置tycho插件,以及要构建的模块
	| - org.test.feature //feature插件工程,可以有多个,打包出来后的featrue插件
		| - category.xml  //配置feature所关联的插件
		| - pom.xml       //配置父节点及featrue插件版本号、类型为eclipse-feature等
	| - org.test.bunle    //正常的plug-in插件,可以有多个(包括RCP application插件)
		| - pom.xml      //配置父节点及plugin插件版本号、类型为eclipse-plugin等
	| - org.test.target  //.target文件所在的插件,
		| - pom.xml      //配置父节点及target插件版本号、类型为eclipse-target-definition
		| - test.target  //用来配置tycho构建eclipse时所需要的所有的插件,包括 eclipse platform、p2、第三方jar等
	| - org.test.repository  //将所有插件打包成可执行的exe以及更新站点
		| - pom.xml          //配置父节点及repository插件版本号、类型为eclipse-repository
		| - test.product      //.product文件
	| - pom.xml //父工程节点配置,配置tycho 版本号以及需要构建的模块

上面工程各目录POM
org.test.root

<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 https://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<version>1.0.0-SNAPSHOT</version>
	<groupId>test.root</groupId>
	<artifactId>org.test.root</artifactId>
	<packaging>pom</packaging>
	<name>Root Project</name>

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

	<modules>
		<module>org.test.target</module>
		<module>org.test.feature</module>
		<module>org.test.bundle</module>
		<module>org.test.repository</module>
	</modules>

	<build>
		<plugins>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>target-platform-configuration</artifactId>
				<version>${tycho-version}</version>
				<configuration>
					<target>
						<artifact>
							<groupId>test.target</groupId>
							<artifactId>org.test.target</artifactId>
							<version>1.0.0.qualifier</version>
						</artifact>
					</target>
					<environments>
						<environment>
							<os>win32</os>
							<ws>win32</ws>
							<arch>x86_64</arch>
						</environment>
						<environment>
							<os>linux</os>
							<ws>gtk</ws>
							<arch>x86_64</arch>
						</environment>
						<environment>
							<os>macosx</os>
							<ws>cocoa</ws>
							<arch>x86_64</arch>
						</environment>
					</environments>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-maven-plugin</artifactId>
				<version>${tycho-version}</version>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.11.0</version> <!-- 使用适合的版本 -->
				<configuration>
					<source>17</source>
					<target>17</target>
					<compilerArgs>
						<arg>-Xlint:-deprecation</arg> <!-- 忽略弃用警告 -->
					</compilerArgs>
					<compilerArgument>-Xlint:unchecked</compilerArgument>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

org.test.featrue

<project>
	<parent>
		<artifactId>org.test.root</artifactId>
		<groupId>test.root</groupId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>
	
	<artifactId>org.test.feature</artifactId>
	<packaging>eclipse-feature</packaging>
	<name>testfeatrue</name>
	<groupId>test.feature</groupId>
	<version>1.0.0-SNAPSHOT</version>
</project>

org.test.bundle

<project>
	<parent>
		<artifactId>org.test.root</artifactId>
		<groupId>test.root</groupId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>
	
	<artifactId>org.test.bundle</artifactId>
	<packaging>eclipse-plugin</packaging>
	<name>testbundle</name>
	<groupId>test.bundle</groupId>
	<version>1.0.0-SNAPSHOT</version>
</project>

org.test.target

<project>
	<parent>
		<artifactId>org.test.root</artifactId>
		<groupId>test.root</groupId>
		<version>1.0.0-SNAPSHOT</version>
	</parent>
	
	<artifactId>org.test.bundle</artifactId>
	<packaging>eclipse-target-definition</packaging>
	<name>testbundle</name>
	<groupId>test.bundle</groupId>
	<version>1.0.0-SNAPSHOT</version>
</project>

org.test.repository

<project>
<modelVersion>4.0.0</modelVersion>

	<groupId>studio.repository</groupId>
	<artifactId>org.test.repository</artifactId>
	<packaging>eclipse-repository</packaging>
	<name>Studio Product</name>
	
	<parent>
		<version>1.0.0-SNAPSHOT</version>
		<groupId>test.root</groupId>
		<artifactId>org.test.root</artifactId>
	</parent>

	<build>
		<plugins>
			<plugin>
				<groupId>org.eclipse.tycho</groupId>
				<artifactId>tycho-p2-director-plugin</artifactId>
				<version>${tycho-version}</version>
				<configuration>
					<formats>
						<win32>zip</win32>
						<linux>tar.gz</linux>
						<macosx>tar.gz</macosx>
					</formats>
				</configuration>
				<executions>
					<execution>
						<id>materialize-products</id>
						<goals>
							<goal>materialize-products</goal>
						</goals>
					</execution>
					<execution>
						<id>archive-products</id>
						<goals>
							<goal>archive-products</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

将上面的pom配置好后,在root下面的pom上右键 Run as... > mvn build
image
image
后面直接Run as...>mvn build 即可,不用每次mvn clean 然后mvn verify

注意事项:

  1. 开发环境如果要用.target中配置的jar,需要配置一下首选项,默认是选中Running Platform的,修改为
    image

  2. jdk11以上的版本javax的包可能不在jdk中了,需要单独引用,在.target文件中添加,且在需要引用的插件中导入此包的依赖
    image

  3. 一般报这个错 Missing requirement: org.test.bundle 1.0.0.qualifier requires 'osgi.bundle; org.eclipse.equinox.event 1.6.200' but it could not be found,说明.target文件中配置的包中不存这个插件,需要检查下是不是没有勾选

  4. 每个工程下面都要加个pom.xml 太繁锁,有个简单的方法,在最顶层的工程目录下创建一个.mvn文件夹,文件夹下面创建一个extensions.xml,xml中的内容如下:

<extensions>
	<extension>
		<groupId>org.eclipse.tycho</groupId>
		<artifactId>tycho-build</artifactId>
		<version>4.0.8</version>
	</extension>
</extensions>

这样其他子模块的maven工程就不用配置pom.xml了,执行mvn命令时会自动识别并使用配置中的tycho版本进行构建

注意:上面这个方法会额外在工程下生成一个.tychoxxx的文件。目前没有使用这样的配置,而是每个工程都添加pom.xml的方式

刚开始接触时走了不少弯路,摸索了一段时间以上方式应该可以满足打包了,后续的上线部署暂时还不涉及未研究

参考资料:
Tycho使用相关

使用Tycho构建OSGi插件项目_manifest.mf tycho-CSDN博客

Tycho:用Maven构建Eclipse Plugin项目 | 心内求法 (holbrook.github.io)

Maven Tycho for building Eclipse plug-ins, OSGi bundles and Eclipse applications with the command line - Tutorial (vogella.com)

Tycho 打包例程:

e4-tutorial/org.eclipse.e4.tutorial.contacts.build.tycho at master · toedter/e4-tutorial (github.com)

Tycho官网文档

Tycho p2 Director Plugin – tycho-p2-director:archive-products (eclipseprojects.io)

标签:插件,target,eclipse,Eclipse,tycho,Maven,Tycho,test,org
From: https://www.cnblogs.com/jasonboboblog/p/18412254

相关文章

  • 6- 【JavaWeb】Maven管理项目
    ApacheMaven是一个流行的构建自动化工具,用于Java项目的构建、管理和依赖处理。Maven使用XML配置文件pom.xml来管理项目的构建过程和依赖关系。1.项目结构一个标准的Maven项目结构如下:my-maven-project/├──src/│├──main/││├──java......
  • Maven更换阿里云源
    亲测可用<?xmlversion="1.0"encoding="UTF-8"?><!--LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements.SeetheNOTICEfiledistributedwiththisworkforadditionalinformationre......
  • 【快速解决】Maven安装和配置详细教程,解决你可能出现的问题Error: JAVA_HOME not foun
    看着文章一步一步来......
  • 基于JavaWeb开发的java eclipse+jsp+mysql+servlet+Spring的学生信息管理系统基础版
    基于JavaWeb开发的javaeclipse+jsp+mysql+servlet+Spring的学生信息管理系统基础版......
  • JavaWeb【day15】--(Maven高级)
    Maven高级Web开发讲解完毕之后,我们再来学习Maven高级。其实在前面的课程当中,我们已经学习了Maven。我们讲到Maven是一款构建和管理Java项目的工具。经过前面10多天web开发的学习,相信大家对于Maven这款工具的基本使用应该没什么问题了。我们掌握了Maven工具的基本......
  • 【SpringBoot Demo】MySQL + JPA + Hibernate + Springboot + Maven Demo
    主要包含:springboot+jpa+hibernate+mysql+lombok(两年前写过一个,现在重新记录一个)1. 目录结构: 2.pom 文件1<?xmlversion="1.0"encoding="UTF-8"?>2<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.or......
  • 以MySQL为例,来看看maven-shade-plugin如何解决多版本驱动共存的问题?
    开心一刻清明节那天,看到一小孩在路边烧纸时不时地偷偷往火堆里扔几张考试卷子边烧边念叨:爷爷呀,你岁数大了,在那边多做做题吧,对脑子好,要是有不懂的地方,就把我老师带走,让他教您!前提说明假设MySQL5.7.36的库qsl_datax有表qsl_datax_source和数据CREATETABLE`qsl_datax_source`......
  • Eclipse Check For Updates总是检查不到更新-解决方法
    最近想用流行的JavaIDE——Eclipse的Help->CheckForUpdates更新Eclipse,结果总是说未找到更新:1.检查是否有更新首先,访问Eclipse下载地址获得最新版本(目前为2020-06):再看看系统中的Eclipse版本(Help->AboutEclipseIDE):如果网上版本和当前版本相等(像图中),那就System.......
  • Eclipse安装包下载慢解决方法
    最近开始学习Java,使用经典的EclipseIDE,结果发现下载太慢……问题分析Eclipse的下载依赖于其他镜像,(在我这里)默认为朝鲜的镜像(可能在不同电脑中默认不同):点击SelectAnotherMirror:选择中国的镜像:......
  • eclipse乱码
    ‌Eclipse注释乱码问题的核心解决方案是统一编码设置。‌具体步骤如下:‌设置工作空间编码‌:打开Eclipse,选择“Window”->“Preferences”->“General”->“Workspace”,在“Textfileencoding”中选择合适的编码,如UTF-8或GBK。‌设置项目编码‌:右键点击项目,选择“Properties”......