I am trying to bundle a java application on windows for mac using appbundler-1.0.jar and Ant with an embedded jre 7.
This is the build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AppName" default="default" basedir=".">
<property environment="env" />
<taskdef
name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="bundle-AppName">
<bundleapp
outputdirectory="dist"
name="AppName"
displayname="AppName"
identifier="com.hmf.AppName"
icon="files\logo48.icns"
shortversion="1.0"
mainclassname="hmf.AppName.app">
<classpath file="files/AppName.jar" />
<librarypath dir="pathToLibraries" />
<option value="-Dapple.laf.useScreenMenuBar=false"/>
<option value="-XstartOnFirstThread=true"/>
<option value="-Dcom.apple.macos.useScreenMenuBar=false"/>
<option value="-Dcom.apple.smallTabs=true"/>
<option value="-Dsun.java2d.d3d=false"/>
<option value="-Derby.storage.pageSize=8192"/>
<option value="-Djava.library.path=lib/swt.jar:lib"/>
<option value="-Xmx1400M"/>
</bundleapp>
</target>
</project>
I then copy jre 7 for mac to PlugIns directory under AppName.app. (I cant make it work with the runtiime tag)
But when I try to run the application I get:
"Unable to load Java Runtime Environment".
When OS use system jre it works but I want to be able to use the embedded jre.
Also see:
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
Application is using Java 6 from Apple instead of Java 7 from Oracle on Mac OS X?
I've solved the issue with my "Unable to load Java Runtime Environment" by using an installed JDK as the jre to be embedded within my app. I was until now using a jre unzipped within a user folder. with the JDK I set the environment variable at the command line
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
I then used the
<runtime dir="${env.JAVA_HOME}" />
and it worked as the jre gets installed under the Plugins directory as it should i.e no need to manually copy jre
Related
I have a project I build using ant and eclipse which I'd like to have be compatible with Java 8.
When I try running the jar using Java 8, I get the following error:
$ /usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar hypnos.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError:
org/joshuad/musicplayer/MusicPlayerUI has been compiled by a more recent version of
the Java Runtime (class file version 53.0), this version of the Java Runtime only
recognizes class file versions up to 52.0
So it appears that it's compiling using Oracle's Java 9 (which is installed on my system) but I can't find the place in eclipse where this is designated. Everything I see seems to suggest that we're using java 8 (screenshots below).
I feel like I must be missing something, but I can't figure out where. What do I have to do to get this jar to be compatible with Java 8 / class file version 52.0?
Project > Properties > Java Build Path
Project > Properties > Java Compiler
Window > Preferences > Compiler
Right Click Ant Build File > Run As > External Tools Configuration
Ant Build File
<project name="Hypnos Music Player" default="compile" basedir=".">
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="jarFile" location="hypnos.jar"/>
<path id="class.path">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
<pathelement location="${jarFile}" />
</path>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source">
<javac fork="yes" includeantruntime="false" srcdir="${src}" destdir="${build}">
<classpath refid="class.path" />
</javac>
</target>
<target name="jar" depends="compile" description="Create a jar.">
<jar destfile="${jarFile}" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="org.joshuad.musicplayer.MusicPlayerUI" />
<attribute name="Class-Path" value="lib/commons-cli-1.4.jar lib/jaad-0.8.4-nospi.jar
lib/jaudiotagger-2.2.6-SNAPSHOT.jar lib/jflac-1.2.jar
lib/jl1.0.1.jar lib/jogg-0.0.7.jar lib/jorbis-0.0.15.jar
lib/vorbisspi1.0.3.jar" />
</manifest>
</jar>
</target>
</project>
What is your $JAVA_HOME environment variable?
I recently had a similar problem and it turns out that Ant seems to ignore many settings provided by Eclipse and only uses $JAVA_HOME. I discovered this by placing the following in build.xml:
<target name="jdk_version_validation">
<echo message="Java Version: ${java.version}" />
<echo message="Java home: ${java.home}" />
<echo message="JAVA_HOME: ${env.JAVA_HOME}" />
<echo message="JAVACMD: ${env.JAVACMD}" />
</target>
Which got me this:
jdk_version_validation:
[echo] Java Version: 1.7.0_80
[echo] Java home: C:\Program Files\Java\jre7
[echo] JAVA_HOME: C:\Program Files\Java\jdk1.8.0_131\
[echo] JAVACMD: C:\Program Files\Java\jdk1.7.0_80\bin
I found that the only sure way to predict which version Ant will produce is by brute-forcing the following in build.xml:
<property name="ant.build.javac.source" value="1.7"/>
<property name="ant.build.javac.target" value="1.7"/>
So, my recommendation to you: Try placing in your build.xml the following:
<property name="ant.build.javac.source" value="1.8"/>
<property name="ant.build.javac.target" value="1.8"/>
Update, for the benefit of those with a variation of the problem described in the OP, to eliminate any possibility of "Eclipse fooling Ant":
Go to Window > Preferences > Java > Installed JREs and try leaving only the target JRE, making sure it is the one inside the JDK folder (not the sibling one directly under the Java folder).
Go to Project > Properties > Java Compiler and check Enable project specific settings, making sure that the Compiler compliance level is set to the target JRE java version.
In addition to what datv said above, I'll add from experience:
Ant's javac, java, and junit tasks have a jvm attribute that determines how to run the JDK/JRE, if fork="true". Unfortunately, it only sets the raw launcher, and doesn't change all the other settings. When I set the jvm attribute to the full path of a Java 8 JRE, turning on ant's -d switch shows that it is being used as the executable, but followed by
'-Djava.specification.version=9'
'-Dsun.boot.library.path=C:\Java\x64\jdk-9.0.1\bin'
'-Djava.home=C:\Java\x64\jdk-9.0.1'
'-Djava.runtime.version=9.0.1+11'
'-Djava.version=9.0.1'
'-Djava.library.path=...;C:\Java\x64\jdk-9.0.1\bin;.....
'-Djava.vm.version=9.0.1+11'
'-Djava.class.version=53.0'
all of which take precedence.
It turns out that Ant cares more about the JAVACMD environment variable when it starts up. In the situation above, our build framework had set JAVACMD to C:\Java\x64\jdk-9.0.1\bin\java, and the individual jvm= and executable= attributes on specific tasks were... not "ignored" really, merely pointless and misleading.
Have a project that I am migrating over from netbeans to intellij.
Intellij recognises the spring config files and gives the warning "please configure/setup spring facet for modules". This requires manually adding these under project structure settings.
I don't want the other team members to all have to do this manually, so I wish to check these settings into git, but according to that, there are no changed files in the project directory (I have standard ignores added to .gitignore). I have also tried searches of file contents for the config file names etc and that turns up nothing too.
So my question is where are the settings stored? In a file that is typically on the ignored list or in a location external to the project directory?
Essentially all the IDEA related configuration for the project is under .idea folder, for example, all the project workspace iteams you can find in the .idea/worksapce.xml, include the spring features you mentioned.
But this is not a good idea to keep those things in your VCs, the .idea folder is ignore default as in the configuration items will store you local env related like the full path to your local gradle, e.g.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/DevTools/gradle-2.14.1" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
Here are some files under the .idea folder for my proejct
Update:
For the spring facets, it's under the module .iml file, like
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/resources/META-INF/spring/integration-beans.xml</file>
</fileset>
</configuration>
</facet>
</component>
I was trying to run an Ant script in Eclipse, but I am getting the below error:
BUILD FAILED
C:\Users\name\workspace\Client\build\Build_Local.xml:111: Error running C:\Program Files\Java\jdk1.6.0_45\jre\bin\javac compiler.
My java home is pointed to jdk and I edited the java path in windows>preferences>installed jre as well as in run>external tool>config>jre. Both locations are pointed to jdk. Also I am posting my build file(This is not the exact file, I have edited a lot before posting)
<?xml version="1.0"?>
<project name="projectName" default="main" basedir="C:\path\build">
<property name="LocalHome" value="C:\proName" />
<property name="home" value="${LocalHome}"/>
<property name="java.home" value="C:\Program Files \Java\jdk1.6.0_45"/>
<property name="CLIENT_JAR" value="client.jar"/>
<target name="main" description=": This is the default target.">
<antcall target="name"/>
</target>
<target name="name">
<javac failonerror="true" srcdir="${home}/source" destdir="path to class file"
executable="${java.home}\bin\javac" fork="true" debug="on" encoding="UTF-8"
source="1.6" target="1.6" bootclasspath="${java.home}/jre/lib/rt.jar"
classpath=""/>
</project>
See here I mentioned the javac path to "C:\Program Files \Java\jdk1.6.0_45\bin\javac". Then why does Ant choose javac from C:\Program Files\Java\jdk1.6.0_45\jre\bin\javac (see the build error)
It worked when I directly used java home path(C:\Program Files\Java\jdk1.6.0_45) in place of java.home
${java.home} points to C:\Program Files\Java\jdk1.6.0_45\jre. So you should be able to just remove that from bootclasspath:
bootclasspath="${java.home}/lib/rt.jar"
If you put the following line below a target, you'll see it print out the full path with jre appended:
<echo level="info" message="java.home = ${java.home}"/>
I have an existing javafx project in eclipse (JDK 1.8). The goal ist to create a msi package which contains an executable. But the java runtime should NOT be included. But when I start the application it shows following error:
Failed to find library ...\runtime\bin\server\jvm.dll
The build.xml fx:deploy target looks like this:
<fx:deploy embedJNLP="true"
install="false"
shortcut="true"
extension="false"
includeDT="false"
offlineAllowed="true"
outdir="${basedir}/deploy"
outfile="test"
nativeBundles="msi"
updatemode="background"
verbose="true">
<fx:platform basedir=""/>
<fx:info title="test" vendor="test GmbH" />
<fx:application refId="fxApplication" />
<fx:resources refid="appRes" />
<fx:preferences install="false" shortcut="true" />
</fx:deploy>
The platform basedir is configured to NOT include runtime. <fx:platform basedir=""/>
How to configure project to start with the default installed JRE?
I am not sure, but my guess is, there is currently a bug within the javafx packager. Even when <fx:platform basedir=""/> correctly results in not including a runtime the generated config still includes an entry to a non existing runtime folder
app.runtime=$APPDIR\runtime
Deleting this entry within the config next to your generated jar should result in using the default installed JRE on the system.
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