前言
eclipse本身是基于java实现的,也就意味着eclipse ide必须要依托jre运行。作为开发者,通常会手动下载和配置jdk,然而作为非java开发者的用户而言,让其下载和配置jdk无疑会增加学习成本,影响用户体验。因此,将jre优雅的内置到eclipse ide中,是很有必要的。
此处借助eclipse的 justj 开源工程,来实现内置jre功能。本文以jre11为例
eclipse justj是一组开源的eclipse插件,其内置了各个版本、各个平台的jre
定义target platform
myide.target
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="mcstudio">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/releases/2021-12"/>
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://mirrors.tuna.tsinghua.edu.cn/eclipse/justj/jres/11/updates/release"/>
<unit id="org.eclipse.justj.openjdk.hotspot.jre.minimal.feature.group" version="0.0.0"/> <!-- 包含justj jre -->
</location>
</locations>
</target>
定义product
myide.product
在.product文件中包含<feature id="org.eclipse.justj.openjdk.hotspot.jre.minimal" installMode="root"/>
pom.xml
在pom中配置target-platform-configuration
插件,如下
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<executionEnvironment>org.eclipse.justj.openjdk.hotspot.jre.minimal-11</executionEnvironment> <!-- 这句很重要 -->
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
<target>
<artifact>
<groupId>com.zhangsan.myide</groupId> <!-- .target文件所在的pom -->
<artifactId>target</artifactId>
<version>1.0.0-SNAPSHOT</version>
</artifact>
</target>
</configuration>
</plugin>
构建完成后,生成的product中就内置了一份jre11