// action methods File execute(Map<String,? super Object> params, File outputParentDir); boolean validate(Map<String,? super Object> params); // information methods Collection<BundlerParamInfo<?>> getBundleParameters(); String getBundleType(); String getDescription(); String getID(); String getName();
public static List<Bundler> getSuitableBundlers() { return Bundlers.createBundlersInstance() .getBundlers() .stream() .filter(bundler -> { try { bundler.validate(Collections.emptyMap()); } catch (UnsupportedPlatformException ex) { return false; } catch (ConfigException ignored) { } return true; }).collect(Collectors.toList()); }
public class BundlerParamsBuilder { private Map<String, Object> params = new HashMap<>(); public <T> BundlerParamsBuilder setParam(BundlerParamInfo<T> param, T value) { params.put(param.getID(), value); return this; } public BundlerParamsBuilder unsafeSetParam(String key, Object value) { params.put(key, value); return this; } public Map<String, Object> build() { return new HashMap<>(params); } }
List<Bundler> bundlers = getSuitableBundlers(); Path directoryWithBundles = Files.createTempDirectory("bundles"); Path jar = Paths.get("/tmp/helloWorld.jar"); RelativeFileSet mainJar = new RelativeFileSet(jar.getParent().toFile(), new HashSet<File>( Arrays.asList(jar.toFile()) )); Map<String, Object> params = new BundlerParamsBuilder() .setParam(StandardBundlerParam.APP_NAME, "HelloWorld") .setParam(StandardBundlerParam.APP_RESOURCES, mainJar) .build(); bundlers.forEach(bundler -> bundler.execute(params, directoryWithBundles.toFile())); System.out.println("Bundles are created in " + directoryWithBundles); System.out.println("Parameters after bundling: " + params);
The bundles are created in / tmp / bundles5791581710818077755 Parameters after bundling: {appVersion = 1.0, copyright = Copyright (C) 2015, stopOnUninstall = true, .mac-jdk.runtime.rules = [Lcom.oracle.tools.packager.JreUtils $ Rule; @ 4c3e4790, mac.app. bundler = Mac Application Image, linux.deb. , linux.deb.licenseText = Unknown, linux.deb.maintainer = Unknown <Unknown>, jvmProperties = {}, mac.signing-key-user-name =, licenseFile = [], identifier = HelloWorld, linux.rpm.imageDir = / tmp / fxbundler6592356981290936843 / images / linux-rpm.image, runtime = RelativeFileSet {basedir: /home/dginzburg/soft/jdk1.8.0_25/jre, files: [<very big list of files>]}, shortcutHint = false , mainJar = RelativeFileSet {basedir: / tmp, files: [helloWorld.jar]}, jvmOptions = [], name.fs = HelloWorld, fxPackaging = false, name = HelloWorld, appResources = RelativeFileSet {basedir: / tmp, files: [ helloWorld.jar]}, mac.category = Unknown, linux.deb.imageDir = / tmp /fxbundler6592356981290936843/images/linux-deb.image/helloworld-1.0, .mac.default.icns = GenericAppHiDPI.icns, runAtStartup = false, linux.app.bundler = Linux Application Image, mac.signing-key-developer-id- app = null, linux.launcher.url = jar: file: /home/dginzburg/soft/jdk1.8.0_25/lib/ant-javafx.jar! / com / oracle / tools / packager / linux / JavaAppLauncher, description = HelloWorld , configRoot = / tmp / fxbundler6592356981290936843 / macosx, preferencesID = Hello, if you want to have a ceo, why = = helloworld-1.0, mac.CFBundleIdentifier = HelloWorld, serviceHint = false, vendor = Unknown, email = Unknown, applicationCategory = Unknown, mac.app.imageRoot = / tmp / fxbundler6592356981290936843 / images / dmg.image, userJvmOptions =} =, linux.deb.configDir = / tmp / fxbundler6592356981290936843 / images / linux-deb.image / helloworld-1.0 / DEBIAN, verbose = false, imagesRoot = / tmp / fxbundler6592 356981290936843 / images, mac.daemon.image = / tmp / fxbundler6592356981290936843 / images / pkg.daemon, applicationClass = HelloWorld, .linux.runtime.rules = [Lcom.oracle.tools.packager.JreUtils $ Rule; 38ccce, 38.cref, $ 38.3; true}
//... if (getDefaultValueFunction() != null) { T result = getDefaultValueFunction().apply(params); if (result != null) { params.put(getID(), result); } return result; } //...
params -> { extractMainClassInfoFromAppResources(params); return (RelativeFileSet) params.get("mainJar"); }
Source: https://habr.com/ru/post/257363/
All Articles