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.
Related
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>
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
I am trying to create an executable from a Java project in eclipse. I understand that the first step would be creating a JAR file so after searching the site I was able to compile the following Ant build.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configuration of the Ant build system to generate a Jar file -->
<project name="GraphBuild" default="CreateJar">
<target name="CreateJar" description="Create Jar file">
<manifest file="MANIFEST.MF">
<attribute name="Main-Class" value="GraphEditor" />
</manifest>
<jar jarfile="GraphEditor.jar" basedir="." includes="*.class"
manifest="MANIFEST.MF" />
</target>
</project>
When I run the GraphEditor.jar using the following command
java -jar GraphEditor.jar
I receive java.lang.NoClassDefFoundError because I have some referenced libraries in my project and it seems that the loader is not able to find them. I tried setting the -cp variable with no luck.
Appreciate you help.
With maven you can easily create an executable jar with all dependencies.
Maybe you want to use maven instead of ant.
How can I create an executable JAR with dependencies using Maven?
You need to attach the dependent jars appropriately and point to directory of your class files correctly.
Something like:
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${class.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="Class-Path" value="${lib.dir}/lib1.jar ${lib.dir}/lib2.jar"/>
</manifest>
</jar>
Can you add the Class-Path variable with the dependent jar files with appropriate location and try?
If I read your question properly I would first like to say you cannot use the -cp and -jar. If you declare a classpath when creating the jar (in ant #see http://www.tomred.net/tomred-java-jar-meta-inf-manifest.html) for example so that it is in the MANIFEST then you need not include the -cp.
If you want to test your jar with a classpath you should do as you have but swap the -jar for -cp as below.
java -cp lib/;deps/;GraphEditor.jar org.package.to.RunClass
Simply -jar and -cp are multiply exclusive. Note: ";" separation in windows ":" in linux
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
I am trying to create a jar file that is "self contained" concerning the libraries it needs.
Therefore, I created the following ant file:
<project name="srv" default="prod">
<target name="prod">
<jar destfile="build/ServerApplication.jar" basedir="bin/">
<restrict>
<name name="**/*.class"/>
<archives>
<zips>
<fileset dir="lib/" includes="**/*.jar"/>
</zips>
</archives>
</restrict>
<manifest>
<attribute name="Class-Path" value="." />
<attribute name="Main-Class" value="my.package.ServerApplication" />
</manifest>
</jar>
</target>
</project>
But, when I try to launch the application using
> java -jar ServerApplication.jar
I get an error
No suitable driver found for jdbc:mysql://localhost/db?user=root&password=
I reckon this is because the com.mysql.jdbc package inside the jar can't be found. Why is this? When I set the Class-Path to ., shouldn't the jar be able to find all classes inside that jar?
I opened the jar in a decompiler, and all the classes are where they need to be, see here:
What is going wrong here? My MANIFEST looks like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.7.0_07-b10 (Oracle Corporation)
Main-Class: my.package.ServerApplication
Class-Path: .
You must explicitly write the names of the jars if you want them included separated by spaces. Otherwise I would recommend simply launching your jar and providing the class path as a parameter manually:
java -cp . -jar ServerApplication.jar
See here for more information.
I think you should avoid setting classpath at all, and since you are packaging everything in uber-jar - it should work.
Maybe you could try the excellent eclipse plugin which is fatjar.
It had used it many times for including all dependencies of Java Swing based applications.