Apple .app (build with Ant's JarBundler) won't run - java

I build my app with the following build.xml
When I click on release/MyApp.app, it won't run!!!
But when I do
java -jar release/MyApp.app/Contents/Resources/Java/helloworld.jar
the executable (a Windows) does come up, meaning the helloworld.jar is built correctly.
But for some reason, the app doesn't know to load it.
<?xml version="1.0" encoding="UTF-8"?>
<project name="App Builder" default="build_app" basedir=".">
<taskdef name="jarbundler"
classname="net.sourceforge.jarbundler.JarBundler" />
<target name="build_app">
<jarbundler dir="release"
name="MyApp"
mainclass="com.test"
jar="helloworld.jar" />
</target>
</project>
Does anyone know what is wrong here?
Thanks

+1 to trashgod. When testing this (from your previous question), my app wouldn't start. It was because the Stub was using Java 6 instead of Java 7 ... go figure. Once I compiled my files down to Java 6, it worked fine.
Also, make sure that you are including all the dependent Jar files...
I used this as my target...
<target name="default">
<delete dir="package" failonerror="false"/>
<mkdir dir="package"/>
<jarbundler dir="package"
name="Cars"
mainclass="testanimation10.TestAnimation10">
<jarfileset dir="dist">
<include name="**/*.jar" />
<!--<exclude name="**/CVS" />-->
</jarfileset>
</jarbundler>
Updated
I downloaded Java Application Bundler from java.net, which seems to be the replacement for Apple's bundler and following the basic instructions from here and was able to build a bundle that was capable of running binaries compiled under Java 7

Related

Executable Jar: Could not load main (but main is in ANT xml)

When I run my jar file via terminal I have no issues. However, when I put it on my client's computer it gave me the following error (when I tried it through terminal:
Error: could not find or load main class base.Main.
Caused by: NoClassDefFoundErrors javafx/application/Application
Normally I'd assume Main wasn't included. However, I exported the ANT XML as well (included below) and base.Main is where my main should be. I'm also confused because I can run the executable jar through the terminal on my machine with no issues.
I'm using the export runnable jar feature in STS. I've tried exporting multiple times. I've tried changing export settings (cycling through the options). I've verified my client had a valid JDK even though I doubt that would be the issue.
*I've spent two hours searching through answers. While I'm sure there are similar questions out there, I have not yet found when that exactly matches the issue I'm having. If you've seen one feel free to post it.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for
Project BLIS with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR file Export
Wizard-->
<!--ANT 1.7 is required-->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="${dir.buildfile}"/>
<property name="dir.jarfile" value="/Users/me/Documents"/>
<target name="create_run_jar">
<jar destfile="${dir.jarfile}/BLIS.jar">
<manifest>
<attribute name="Main-Class"
value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
<attribute name="Rsrc-Main-Class" value="base.Main"/>
<attribute name="Class-Path" value="."/>
<attribute name="Rsrc-Class-Path" value="./ spring-jdbc-3.2.11.RELEASE.jar spring-jdbc-3.2.11.RELEASE.jar mysql-connector-java-
8.0.13.jar joda-time-2.10.1.jar"/>
</manifest>
<zipfileset src="jar-in-jar-loader.zip"/>
<fileset dir="${dir.workspace}/BLIS/bin"/>
</jar>
</target>
</project>
I know that expecting things to "just work" is unrealistic. The problem is I'm not sure where I messed up. Is it because Main-Class is the resource loader instead of base.Main? I haven't used this exporter before, but I assume it "loads the resource" before checking if main exists.
Any help would be appreciated.
This must be mainly due to the unavailability of javafx.application.Application class in the classpath in the client's computer even though it is there in your machine.
Oracle by default contains the javafx, but OpenJDK does not. If it is the OpenJDK, then you will need to separately install openjfx.
Better check Java version in both machines and compare.
Hope this will help you in resolving your issue.

"no swt-win32 in java.library.path" on runtime jar

I am new to Java & Eclipse. I have a window-based app with dialogs, that works fine inside of the IDE. However, when I try to export a JAR to make it executable outside the IDE (and thus redistributable), I execute it with the command:
java -jar MyLibrary-app.jar
I get the exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-win32-4427 in java.library.path
no swt-win32 in java.library.path
Can't load library: C:\Users\jay.imerman\.swt\lib\win32\x86\swt-win32-4427.dll
Can't load library: C:\Users\jay.imerman\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:327)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:236)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
at org.jimerman.MyLibrary.MainWindow.open(MainWindow.java:51)
at org.jimerman.MyLibrary.MainWindow.main(MainWindow.java:40)
I don't know what the difference is between exporting a JAR and a Runnable JAR, I tried both. On the former, I also tried including the src from the swt project, as well as another Java class library project that I reference. I am used to visual Studio, and the Setup project, which detects dependencies and collects references for a deployment. What am I missing? If I were to use something like Maven, how do I even go about learning what all the terminology and concepts are, to even understand what it means and what I need to build a redistributable file?
You have an option to export to runnable-jar in eclipse and save ant.xml. It should look like
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for Project MyLibrary-app">
<!--this file was created by Eclipse Runnable JAR Export Wizard-->
<!--ANT 1.7 is required -->
<target name="create_run_jar">
<jar destfile="MyLibrary-app" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="MainClass"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="bin"/>
<zipfileset excludes="META-INF/*.SF" src="{Eclipse_HOME}/plugins/org.eclipse.swt.win32.win32.x86_x.x.x.vxxxxa.jar"/>
</jar>
</target>
</project>

Jar to Mac OSX App Bundle with app bundler

I'm trying to bundle my .jar to a MacOSX app bundle, using app bundler.
I'm following this tutorial.
It says to add a lib folder to the high-level project directory, but I don't know what that means. I've been looking everywhere for it, and I cannot find out what it is. That's my only problem I have, anyone know?
EDIT:
Here is my build.xml file:
<project name="Rage Mage" basedir=".">
<taskdef name="ragemage"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="bundle-RageMage">
<delete dir="appBundle" failonerror="false"/>
<mkdir dir="appBundle"/>
<bundleapp outputdirectory="bundle"
name="Rage Mage"
displayname="Rage Mage"
icon="res/icon.icns"
identifier="ragemage.src.Window"
mainclassname="ragemage.src.Window">
<classpath file="dist/ragemage_1.1.1.jar" />
</bundleapp>
</target>
Thanks!
Okay, so, after having a little play around, this is what I understand...
Download Java Application Bundler and place it in the lib directory of your project. You will need to create this directory...
Create a new Ant script into your project directory, call it what ever you like...Also, take the time to read through the AppBundler Task Docs
The ant script should be based on the following skeleton...
<project name="ButtonDemo" default="bundle-buttonDemo" basedir=".">
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<!-- See the lib reference here, this is why you need to use the lib directory! -->
<target name="bundle-buttonDemo">
<delete dir="appBundle" failonerror="false"/>
<mkdir dir="appBundle"/>
<bundleapp outputdirectory="appBundle"
name="ButtonDemo"
displayname="Button Demo"
identifier="components.ButtonDemo"
mainclassname="components.ButtonDemo">
<!-- The following is important and should point to your build -->
<classpath file="dist/ButtonDemo.jar" />
<!-- You can have multiple instance of classpath if you 3rd party or
dependent jars in different locations -->
</bundleapp>
</target>
</project>
Build your project
Run the ant script, using (something like) ant -f {You App Bundler script}
The app bundle, in this case ButtonDemo.app will be created in appBundle directory. If you can, browse the contents of the ButtonDemo.app/Contents/Java and make sure all your required Jar files are there...
Happy bundling!
Updated based on updated build.xml file
1- There is no default target specified by the project tag. Think of this like your "main class" or "main" method, without, ant has no idea what you want to run...
<project name="Rage Mage" basedir="." default="bundle-RageMage">
2- The name of the taskdef is significant and you use it in the any script to identify what ant should do when it hits your tag reference...
So based on your example, you either need to change the name of the taskdef from ragemage to bundleapp or change the bundleapp tag to ragemage...
Either change this...
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
or this (in target bundle-RageMage)
<ragemage outputdirectory="bundle"
name="Rage Mage"
displayname="Rage Mage"
icon="res/icon.icns"
identifier="ragemage.src.Window"
mainclassname="ragemage.src.Window">
<classpath file="dist/ragemage_1.1.1.jar" />
</ragemage>
Personally, I'd leave it as bundleapp, but that's me...
3- The delete, mkdir and outputdirectory attribute of bundleapp are related...
<delete dir="appBundle" failonerror="false"/>
<mkdir dir="appBundle"/>
<bundleapp outputdirectory="bundle"...
Either, make them all appBundle or bundle, what every you want...
4- You main class is unlikely to be ragemage.src.Window and is probably going to be Window

JAVAFx Build Failed

I created an app with JavaFx for windows, which is really cool. I can run it from e(fx)clipse, everthing works fine, but I can't make a jar file from the project.
I can export it (Right click->Export->Runnable Jar File). However, if I run the jar on MAC OS X , in the menu bar I get "java" menuitem instead of my application name ,which i really don't like.
I searched for how to hide that menuitem, or just rename it, and I found that I have to rename the "Application title*" in the build.fxbuild file. Now I can't build it.
So this is what I really want: to remove/hide/rename the "java" menuitem in Mac OS X.
If you have any experience, please share it with me. I will be really grateful :) .
I get the following error when I try to run the build.xml file:
[javac] Compiling 22 source files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\src\application\SajátKészlet.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning
[copy] Copying 12 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build\classesinit
-fx-tasks:
[taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:
[copy] Copying 20 files to C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\dist\libs
BUILD FAILED
C:\Users\Hassan\Desktop\Programming\workspace\Raktar_vevo 2.7\build.xml:217: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
Total time: 22 seconds
**
I use:
-Windows 7 64bit
-jdk 8 u5
-JAVA_HOME is set
-e(fx)clipse (Kepler), I downloaded the All-in-one version (for the lazy link)
Thanks you very much for your help!
You need to setup jdk as jre in Prefereces->Java->Installed JREs, and check it as "separate jre" in External Tools Configuration->JRE in case of Eclipse
Edit:
Run > External Tools > External Tool Configuration
When you new the JavaFX Project, the generated file, build.xml, maybe have wrong file path.
<?xml version="1.0" encoding="UTF-8"?>
<project name="App2" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
you have to check that where are the ant-javafx.jar and the jfxrt.jar ?
For example, JDK 1.8 the two files are in the difference place,
C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar
C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar
so now I only find the way to modify by myself...
<?xml version="1.0" encoding="UTF-8"?>
<project name="App" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="C:\Program Files\Java\jdk1.8.0_20\lib\ant-javafx.jar"/>
<file name="C:\Program Files\Java\jre1.8.0_20\lib\ext\jfxrt.jar"/>
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
after modify the files, right click choose the Run as Ant Build!
I have a little better solution with less modification:
This fix path issue (just add ext\ to fix issue)
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\ext\jfxrt.jar"/>
</filelist>
</path>
Before doing this, you need to have a jdk1.8.xxx in your installed JREs list, not the jre included in the jdk package but jdk itself.
Next, in Run\External Tools\External Tools Configuration open the JRE tab and check that Execution environment is CDC-1.1/Foundation-1.1 (jdk1.8.xxx)
That's all !
I know that I'm a bit late to answer this, but so many of us are still struggling with this issue and in my case, I could not find a proper answer at any place.
In my case when I was getting the same issue, I managed to get it to work by going to Run->External Tools_>External Tools Configurations and selecting JRE Tab. I had to change the Execution environment from 1.7 to CDC-1.0/Foundation-1.0 (jdk1.7.0_25) (and CDC-1.1 also works).
Definitely a newb when it comes to ant, so not sure why the lazy install doesn't pick up the path correctly, but hopefully this will come in handy to someone else pounding their head before reaching for the excedrin.
I also got the same issue
<?xml version="1.0" encoding="UTF-8"?>
<project name="App2" default="do-deploy" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<target name="init-fx-tasks">
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/> <!-- wrong path -->
<file name="${java.home}\lib\jfxrt.jar"/> <!-- wrong path -->
</filelist>
</path>
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpathref="fxant"/>
</target>
from this removed the .. in the middle like this
--- file name="${java.home}\lib\ant-javafx.jar"---
then i got basedir error
for that i commented the basedir part and also chande the outdir path from ${basedir}
\build/deploy"
outfile="addressApp" nativeBundles="exe"
updatemode="background" >
<!--<fx:platform basedir="${java.home}"/>--> <------ comment Here
<fx:info title="addressApp" vendor="makery.ch"/>
<fx:application refId="fxApplication"/>
<fx:resources refid="appRes"/>
</fx:deploy>
for the above i saw this https://github.com/reds-heig/logisim-evolution/issues/135
After that build was successful and exe file was generated in deploy folder.
Thanks StackOverflow Peeps
What I did on Windows 8.1, Java 1.8.0_192, Eclipse Photon (4.8.0) and e(fx)clipse 3.3.0.
Uninstall all (incremental) Java installations (JDK, JRE)
Install latest (needed) Java JDK with JRE
Set default Java to JDK in Eclipse (Windows -> Preferences -> Java -> Installed JRE)
Set Separate JRE to JDK in Eclipse (Run -> External Tools -> External Tools Configurations)
Clean project
build.fxbuild -> ant build.xml and run

Build JavaFX project without NetBeans

I'm trying to learn JavaFX and maybe create a few "learner" games. I always do my development in Eclipse, rather than NetBeans which the JavaFX team is clearly trying to push.
Can anybody point me in the direction of a how-to for building a JavaFX project in Eclipse, or at least building a JavaFX project without NetBeans? Everything I've found so far either uses NetBeans, or they're running a one-file project in Eclipse (witch won't work for larger projects). Idealy, I'm looking for somebody who's set up a simple Ant script that builds a JavaFX project, since I assume that's the end-game for this situation.
I was able to find where to download the Eclipse JavaFX plugin. It provides syntax highlighting support, plus some "snippets". I can even use it to run simple hello world type JavaFX apps, but I cant seem to get it to automatically build multi-file JavaFX projects. Even if I could, I still can't seem to write a correct ant script to jar up the JavaFX project.
Also, I found this site that talks about what you can do to use a javafxc Ant task created by Sun(?), but I'm not having any luck trying to use what they talk about.
Thanks
Ross
If you create new project in NB there is folder called nbproject. This folder contains build-impl.xml. This file contains this target:
<target if="src.dir" name="-compile-fx">
<taskdef classname="com.sun.tools.javafx.ant.JavaFxAntTask" classpath="${platform.bootcp}" name="javafxc"/>
<javafxc bootclasspath="${platform.bootcp}" classpath="${build.classes.dir}:${javac.classpath}" compilerclasspath="${platform.bootcp}" debug="${javac.debug}" deprecation="${javac.deprecation}" destdir="${build.classes.dir}" excludes="${excludes}" fork="yes" includeJavaRuntime="false" includeantruntime="false" includes="**/*.fx" source="${javac.source}" sourcepath="" srcdir="${src.dir}" target="${javac.target}">
<compilerarg line="${javac.compilerargs}"/>
</javafxc>
</target>
This is good start to create ant for Eclipse. I'm not sure how building works for Eclipse, but there could be limitations. The com.sun.tools.javafx.ant.JavaFxAntTask is located in SDK, not in compiler jar. Good luck!.
I have read in article about JavaFX that there is an Eclipse extension available for it. According to that article it is not as mature as NetBeans support for FX but should be better than nothing...
I've created a partial Ant script for the build process. I can tell that it's actually compiling the JavaFX classes and Jaring them up. However, I think I'm missing an Ant task where I create the JNLP object that is needed in the Applet that I'm also missing (but managed to fake).
Since I didn't explicitly state it, I did not get this to a working state, so don't expect to get there just by doing what I did ;)
This Ant script is as far as I've gotten. I've left out everything but the important parts for brevity...
<project name="RABfx" default="all" basedir=".">
...
<property environment="env"/>
<property name="java.home" value="${env.JAVA_HOME}" />
<property name="jfx.home" value="${env.JAVAFX_HOME}" />
<path id="compile.classpath">
<fileset dir="${java.home}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${jfx.home}/lib">
<include name="**/*.jar" />
</fileset>
...
</path>
<taskdef classname="com.sun.tools.javafx.ant.JavaFxAntTask" name="javafxc">
<classpath refid="compile.classpath" />
</taskdef>
...
<target name="compile">
<javac srcdir="${src}" destdir="${src.classes}" includes="**/*.java">
<classpath refid="compile.classpath" />
</javac>
<javafxc srcdir="${src}" destdir="${src.classes}" includes="**/*.fx" executable="${jfx.home}/bin/javafxc.exe">
<classpath refid="compile.classpath" />
</javafxc>
...
</target>
<target name="build">
<jar jarfile="${src.jar}">
<fileset dir="${src.classes}" />
</jar>
</target>
...
</project>
Also, my "faked" Applet...
...
<script src="http://dl.javafx.com/dtfx.js"></script>
<script>
javafx(
{
archive: "RABfx.jar",
width: 440,
height: 560,
code: "TicTacToe.Main",
name: "TicTacToe"
}
);
</script>
...
After I asked this question, an official (I think?) JavaFX plugin for Eclipse was released. Go to the JavaFX for Eclipse page. I installed the plugin and everything automagically worked!
Either use the JavaFxAntTask mentioned before or generate the project in NetBeans and open it in Eclipse and then you can just run Ant targets. Or wait for 1.1 which will hopefully come with full Eclipse and IDEA support.

Categories