Ubuntu下JavaFX项目:寻求免费独立JAR打包工具
Hey there! Let's work through your JAR packaging issue for your JavaFX app on Ubuntu. You're looking for free, standalone tools that let you manually add all required JARs and specify a main class to build a command-line-runnable JAR—here are some solid options, including the ones you've already found, plus a few more worth checking out:
1. Tools You've Already Identified
- InstallBuilder: Its open-source free version fits your needs perfectly. It lets you manually add all dependency JARs, specify your main class, and build a runnable JAR (it can also create cross-platform installers if you ever need that later). It's command-line friendly, no fancy UI required, and works great on Ubuntu.
- lzPack: This lightweight tool is exactly the kind of no-frills option you're after. You can manually manage your dependencies, set your main class, and generate an executable JAR with minimal setup—definitely worth testing.
2. Additional Free Tools to Try
Apache Maven: While it's a build tool, it gives you full manual control over dependencies and main class configuration. Just add a few lines to your
pom.xmland run a terminal command to build your JAR. Here's a quick snippet for your setup:<build> <plugins> <!-- Basic JAR with main class and classpath --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.3.0</version> <configuration> <archive> <manifest> <mainClass>your.full.main.class.path</mainClass> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> </configuration> </plugin> <!-- Optional: Build a single JAR with all dependencies included --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.4.2</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>your.full.main.class.path</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>build-fat-jar</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>Run
mvn packagein your project directory, and you'll get your runnable JAR in thetargetfolder.Gradle: Similar to Maven but with a more concise configuration. You can define your main class and dependencies in a
build.gradlefile, then build via the terminal. Example config:plugins { id 'java' id 'application' } mainClassName = 'your.full.main.class.path' // Build a basic JAR with classpath references jar { manifest { attributes( 'Main-Class': mainClassName, 'Class-Path': configurations.runtimeClasspath.files.collect { "lib/${it.name}" }.join(' ') ) } } // Optional: Build a fat JAR with all dependencies included task fatJar(type: Jar) { manifest { attributes 'Main-Class': mainClassName } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } with jar }Run
./gradlew fatJarto generate your all-in-one runnable JAR.JarSplice: A tiny, standalone Java tool that's perfect for quick JAR packaging. You can launch it via
java -jar jarsplice.jaron Ubuntu, manually add all your dependency JARs (including JavaFX ones), set your main class, and export a runnable JAR in a few clicks. It has a simple, no-nonsense interface—exactly what you're looking for.
Quick Note for JavaFX Apps
Don't forget to include JavaFX's core JARs in your dependencies when using these tools. For Maven/Gradle, you can add JavaFX dependencies directly to your build file; for tools like JarSplice or lzPack, just add the JavaFX JARs from your SDK alongside your other dependencies.
内容的提问来源于stack exchange,提问作者user1300214

