I'm following this tutorial to create my ant build file that java compiles, than GWT compiles than perform the correct actions to build my .war file.
I use Eclipse and GWT-compile works, and when I run the development mode it works. I have also successfully deployed on tomcat.
The things is when I run my script, the compiles work but it fails on the gwt-compiler task. My ant build script is as follow :
<project name="vlp" default="gwt.compile" basedir=".">
<tstamp />
<!-- ################# PROPERTIES ################ -->
<!-- directory properties -->
<!-- source -->
<property name="projectName" value="VirtualLabPortal" />
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="src.build.dir" location="${build.dir}/src" />
<property name="gwt.build.dir" location="${build.dir}/gwt" />
<property name="gwt.unitCache.dir" location="gwt-unitCache" />
<!-- libraries -->
<property name="src.lib.dir" location="war/WEB-INF/lib" />
<!-- ___________________________________________________________________
| |
| Configure path source/test |
|___________________________________________________________________|
-->
<path id="compile.path">
<fileset dir="${src.lib.dir}" includes="*.jar" />
<fileset dir="${src.lib.dir}/gwt" includes="*.jar" />
</path>
<!-- ___________________________________________________________________
| |
| Clean old compiled source/test/war |
|___________________________________________________________________|
-->
<target name="clean" description="Clean all the old build files.">
<delete dir="${build.dir}" />
<delete dir="${gwt.unitCache.dir}" />
<delete file="${projectWar}" />
<delete file="${src.lib.dir}/${projectJar}" />
</target>
<!-- ___________________________________________________________________
| |
| Compile the source |
|(should exclude gwtview code which is compiled by the gwt compiler)|
|___________________________________________________________________|
-->
<target name="src.compile" depends="clean" description="Compile the source code when everything has been cleaned.">
<mkdir dir="${src.build.dir}" />
<javac encoding="utf-8" destdir="${src.build.dir}" nowarn="true">
<src path="${src.dir}" />
<classpath refid="compile.path" />
</javac>
</target>
<!-- ___________________________________________________________________
| |
| Invoke the GWT compiler |
|___________________________________________________________________|
-->
<property name="module.gwt.xml" location="${src.dir}/com/banctecmtl/ca/vlp" />
<target name="gwt.compile" depends="src.compile">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
<pathelement location="${module.gwt.xml}" />
<path refid="compile.path" />
</classpath>
<jvmarg value="-Xmx512m" />
<arg line="${projectName} -logLevel ALL -style OBF -war ${build.dir}" />
</java>
</target>
<!-- ___________________________________________________________________
| |
| Copy the config files in the war directory |
|___________________________________________________________________|
-->
<property name="config.dir" location="war/config" />
<target name="copy-resources">
<copy todir="war/config" preservelastmodified="true">
<fileset dir="${config.dir}">
<include name="**.*" />
</fileset>
</copy>
</target>
<!-- ___________________________________________________________________
| |
| Create a Jar to be included in the war |
|___________________________________________________________________|
-->
<property name="projectJar" value="${projectName}.jar" />
<property name="gwt.client.dir" location="com/banctecmtl/ca/vlp/view/webview" />
<target name="jar" depends="src.compile">
<!-- should also depend on gwt.compile -->
<jar jarfile="${src.lib.dir}/${projectJar}" basedir="${src.build.dir}/">
<!-- Don't wrap any of the client only code into the JAR
<exclude name="${gwt.client.dir}/**/*.class"/> -->
<exclude name="${gwt.client.dir}/**/*.class" />
</jar>
</target>
<!-- ___________________________________________________________________
| |
| Create a War from the source |
|___________________________________________________________________|
-->
<property name="projectWar" value="${projectName}.war" />
<target name="war" depends="jar,copy-resources">
<war basedir="war" destfile="${projectWar}" webxml="war/WEB-INF/web.xml">
<exclude name="WEB-INF/**" />
<webinf dir="war/WEB-INF/">
<include name="lib/*.jar" />
<include name="classes/*.properties" />
<exclude name="**/gwt-dev.jar" />
<exclude name="**/gwt-user.jar" />
</webinf>
</war>
</target>
<!-- ___________________________________________________________________
| |
| Deploy to the production server |
|___________________________________________________________________|
-->
<!-- It is possible you can't run this from eclipse,
you need to edit the run configurations and add the
latest jsch library to the classpath -->
<property name="user" value="root" />
<property name="password" value="Banctec01" />
<property name="prodHost" value="vlp" />
<property name="dest" value="/usr/share/tomcat6/webapps/ROOT.war" />
<target name="deploy" depends="war">
<echo message="Copying to : ${user}#${prodHost}:${dest}" />
<scp file="${projectWar}" remoteTofile="${user}#${prodHost}:${dest}" password="${password}" trust="true" />
</target>
</project>
It fails with the following error :
Buildfile: D:\workspace\vlp\build.xml
clean:
[delete] Deleting directory D:\workspace\vlp\war\WEB-INF\classes
src.compile:
[mkdir] Created dir: D:\workspace\vlp\war\WEB-INF\classes
[javac] D:\workspace\vlp\build.xml:42: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 134 source files to D:\workspace\vlp\war\WEB-INF\classes
[javac] Note: D:\workspace\vlp\src\com\banctecmtl\ca\vlp\controller\schedule\ScheduledTaskManager.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
gwt.compile:
[java] Checking for updates
[java] First launch was 134c3e23387
[java] Last ping was Mon Apr 23 14:42:48 EDT 2012, min wait is 86400000ms
[java] Module location: file:/D:/workspace/vlp/src/com/banctecmtl/ca/vlp/VirtualLabPortal.gwt.xml
[java] Loading inherited module 'com.google.gwt.user.User'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/user/User.gwt.xml
[java] Loading inherited module 'com.google.gwt.animation.Animation'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/animation/Animation.gwt.xml
[java] Loading inherited module 'com.google.gwt.core.Core'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/core/Core.gwt.xml
[java] Loading inherited module 'com.google.gwt.dev.jjs.intrinsic.Intrinsic'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-dev.jar!/com/google/gwt/dev/jjs/intrinsic/Intrinsic.gwt.xml
[java] Loading inherited module 'com.google.gwt.lang.LongLib'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-dev.jar!/com/google/gwt/lang/LongLib.gwt.xml
[java] Loading inherited module 'com.google.gwt.emul.Emulation'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/emul/Emulation.gwt.xml
[java] Loading inherited module 'com.google.gwt.logging.LogImpl'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/logging/LogImpl.gwt.xml
[java] Loading inherited module 'com.google.gwt.xhr.XMLHttpRequest'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/xhr/XMLHttpRequest.gwt.xml
[java] Loading inherited module 'com.google.gwt.core.Core'
[java] Module 'com.google.gwt.core.Core' has already been loaded and will be skipped
[java] Loading inherited module 'com.google.gwt.core.CompilerParameters'
[java] Module location: jar:file:/D:/workspace/vlp/war/WEB-INF/lib/gwt/gwt-user.jar!/com/google/gwt/core/CompilerParameters.gwt.xml
[java] [...]
[java] Loading inherited module 'com.google.gwt.user.User'
[java] Module 'com.google.gwt.user.User' has already been loaded and will be skipped
[java] Public resources found in...
[java] Translatable source found in...
[java] Persistent unit cache dir set to: D:\workspace\vlp\war\..\gwt-unitCache
[java] Compiling module VirtualLabPortal
[java] Looking for previously cached Compilation Units in D:\workspace\vlp\war\..\gwt-unitCache
[java] Loaded 0 units from persistent store.
[java] Starting UnitWriteThread.
[java] Found 0 cached units. Used 0 / 2413 units from cache.
[java] [ERROR] Unexpected internal compiler error
[java] java.lang.RuntimeException: Exception processing units
[java] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:248)
[java] at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:447)
[java] at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:370)
[java] at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:360)
[java] at com.google.gwt.dev.Precompile.precompile(Precompile.java:252)
[java] at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
[java] at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
[java] at com.google.gwt.dev.Compiler.run(Compiler.java:232)
[java] at com.google.gwt.dev.Compiler.run(Compiler.java:198)
[java] at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
[java] at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
[java] at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
[java] at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[java] Caused by: java.lang.NoSuchMethodError: com.google.gwt.dev.jjs.ast.JProgram.serializeTypes(Ljava/util/List;Ljava/io/ObjectOutputStream;)V
[java] at com.google.gwt.dev.javac.CompilationUnitImpl.<init>(CompilationUnitImpl.java:68)
[java] at com.google.gwt.dev.javac.SourceFileCompilationUnit.<init>(SourceFileCompilationUnit.java:48)
[java] at com.google.gwt.dev.javac.CompilationUnitBuilder$ResourceCompilationUnitBuilder.makeUnit(CompilationUnitBuilder.java:154)
[java] at com.google.gwt.dev.javac.CompilationUnitBuilder.build(CompilationUnitBuilder.java:266)
[java] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$1.run(CompilationStateBuilder.java:223)
BUILD FAILED
D:\workspace\vlp\build.xml:60: Java returned: 1
Total time: 36 seconds
I found that changing the gwt-compiler class name to the DevMode is building successfully. Using : classname="com.google.gwt.dev.DevMode" instead of classname="com.google.gwt.dev.Compiler".
EDIT : I refactored the XML above.
The build.xml cleans all the bin directory. I also pointer the javacto the bin/src directory and Google Web Toolkit compiler outputs to : bin/gwt. The compiler still doesn't work...
EDIT : I downloaded the latest SDK right away from google developpers site, and overrided the old librairies found in my classpath and in my eclipse plugin. Still won't work with the ant build script.
Anybody sees what could be the problem here?
All I can say is that the method com.google.gwt.dev.jjs.ast.JProgram.serializeTypes(Ljava/util/List;Ljava/io/ObjectOutputStream;)V is introduced only in gwt-dev 2.4.0. It doesn't exist in gwt-dev 2.3.0.
Which implies there are somewhere, in the classpath, two gwt-dev versions. One of them is 2.4.0, which is why com.google.gwt.dev.javac.CompilationUnitImpl is looking for that method. The other is of 2.3.0 or older, which is why that method isn't found (JProgram class was loaded by the compiler using the older version).
Try to look them up thoroughly. Or try to start a fresh environment in which you put a good eye on what's getting in.
tl;dr: this is due to differences in the linkers provided by Compiler versus DevMode in cases of insufficient or incorrect class context
Tracing the issue
I noticed that the repro you have exists in the current GWT trunk. Specifically, it's failing in this block of code:
ArrayList<CompilationUnit> resultUnits = new ArrayList<CompilationUnit>();
do {
// Compile anything that needs to be compiled.
buildQueue = new LinkedBlockingQueue<CompilationUnitBuilder>();
final ArrayList<CompilationUnit> newlyBuiltUnits = new ArrayList<CompilationUnit>();
final CompilationUnitBuilder sentinel = CompilationUnitBuilder.create((GeneratedUnit) null);
final Throwable[] workerException = new Throwable[1];
Thread buildThread = new Thread() {
#Override
public void run() {
try {
do {
CompilationUnitBuilder builder = buildQueue.take();
if (builder == sentinel) {
return;
}
// Expensive, must serialize GWT AST types to bytes.
CompilationUnit unit = builder.build(); // <-- Right here.
newlyBuiltUnits.add(unit);
} while (true);
} catch (Throwable e) {
workerException[0] = e;
}
}
};
Unwinding the stack further than your trace, we bounce through a factory and ten layers of code, until we finally hit UnifyAst.java. And, lo and behold:
...
mapApi(enclosingType);
// Now the method should be there.
method = methodMap.get(sig);
if (method == null) {
// TODO: error logging
throw new NoSuchMethodError(sig);
}
assert !method.isExternal();
return method;
...
This is the only instance of NoSuchMethodError called by the Precompilation stage of GWT.
Differences in Compiler and DevMode linking
Cool. Now that we've taken the deep dive into why this is exploding, let's figure out why DevMode works when Compiler doesn't. We note that both import the same copy of Util.java, so technically, both types are available statically to our Java compiler (just not the GWT compiler).
Inspecting the linkers, we note that Compiler uses Link.link directly:
Link.link(logger.branch(TreeLogger.TRACE, logMessage), module,
generatedArtifacts, allPerms, resultFiles, options.getWarDir(),
options.getDeployDir(), options.getExtraDir(), precompileOptions);
Whereas DevMode uses a much terser static call, with a separate pass filling in an instance of StandardLinkerContext:
link(loadLogger, module);
...
#Override
protected synchronized void produceOutput(TreeLogger logger, StandardLinkerContext linkerStack,
ArtifactSet artifacts, ModuleDef module, boolean isRelink) throws UnableToCompleteException {
...
linkerStack.produceOutput(linkLogger, artifacts, Visibility.Public, outFileSet);
linkerStack.produceOutput(linkLogger, artifacts, Visibility.Deploy, deployFileSet);
linkerStack.produceOutput(linkLogger, artifacts, Visibility.Private, extraFileSet);
...
}
Great! So, how do I fix it?
As accepted in the middle of writing this post, yair provides one such diagnosis for the issue, noting that the precompilation step is non-robust to conflicting class identities in the context of two versions of GWT. Other class visibility problems where precompilation.getGeneratedArtifacts(); pulls in wrong or insufficient objects may also cause this repro.
I will assume the issue has now been resolved, given yair was given accepted answer status. But it is conceivable for other people running across this post that other classpath or visibility issues may cause this exact issue to recur.
java.io.ObjectOutputStream class isn't supported by GWT compiler.
You have to refer to https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation#Package_java_io before using Java classes to be sure GWT supports it.
You fork a JVM to run Gwt Compiler and the bin directory is in ClassPath.
As Eclipse compiles in development mode, a remaining class in bin may prevent the compiler to process properly some source files.
You should make sure the bin directory is empty before you invoke your Ant target. It may pass then.
I recommend you to use two target directories: one for classes compiled from Java sources and another one for GWT generated files. Then the target war will collect both into the WAR.
Related
I'm attempting to use opencv on an ubuntu installation and am following this tutorial. Everything seemed fine and it even listed amongst the installed parts so I proceeded into this tutorial. This went well up until the moment where you have to add opencv as a user library as it was not amongst the (completely empty) list of libraries found. I have looked throughout the opencv folder and can't find anything like a library either am I missing something? Any idea on how to fix this?
Note that it did manage to produce .jar file however the library is still missing. If it matters opencv is installed in usr/local/src.
If in order fix this you require any extra information feel free to ask in the comments.
This might have something to do with the problem:
ulap:/usr/local/src/opencv-2.4.8/opencv/build/bin$ ant -DocvJarDir=path/to/dir/containing/opencv-248.jar -DocvLibDir=/usr/local/src/opencv-2.4.8/opencv/build/bin /opencv_java248/native/library
Buildfile: /usr/local/src/opencv-2.4.8/opencv/build/bin/build.xml
BUILD FAILED
Target "/opencv_java248/native/library" does not exist in the project "SimpleSample".
Total time: 0 seconds
thijs#thijs-ulap:/usr/local/src/opencv-2.4.8/opencv/build/bin$ ant -DocvJarDir=path/to/dir/containing/opencv-248.jar -DocvLibDir=/usr/local/src/opencv-2.4.8/opencv/build/bin /opencv_java248/native/library
Buildfile: /usr/local/src/opencv-2.4.8/opencv/build/bin/build.xml
BUILD FAILED
Target "/opencv_java248/native/library" does not exist in the project "SimpleSample".
Total time: 0 seconds
This is my build.xml:
<property name="src.dir" value="src"/>
<property name="lib.dir" value="${ocvJarDir}"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="${ant.project.name}"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java fork="true" classname="${main-class}">
<sysproperty key="java.library.path" path="${ocvLibDir}"/>
<classpath>
<path refid="classpath"/>
<path location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="rebuild" depends="clean,jar"/>
<target name="rebuild-run" depends="clean,run"/>
running
ulap:/usr/local/src/opencv-2.4.8/opencv/samples/java/ant$ ant -DocvJarDir=/usr/local/src/opencv-2.4.8/opencv/build/bin rebuild-run
gave me:
clean:
compile:
[mkdir] Created dir: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/classes
[javac] Compiling 1 source file to /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/classes
jar:
[mkdir] Created dir: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/jar
[jar] Building jar: /usr/local/src/opencv-2.4.8/opencv/samples/java/ant/build/jar/SimpleSample.jar
run:
[java] Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path
[java] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
[java] at java.lang.Runtime.loadLibrary0(Runtime.java:844)
[java] at java.lang.System.loadLibrary(System.java:1051)
[java] at SimpleSample.<clinit>(Unknown Source)
[java] Could not find the main class: SimpleSample. Program will exit.
[java] Java Result: 1
rebuild-run:
BUILD SUCCESSFUL
Total time: 1 second
According to the first tutorial (how to build OpenCV from source), the result should be a JAR file and a .so native lib in the bin/ directory of your OpenCV directory. In the "SETTING UP ECLIPSE FOR USING OPENCV (JAVA) IN UBUNTU" tutorial, you must create the User Library by following the steps in the tutorial. That process involves browsing your file system to select the OpenCV JAR that was produced by the first tutorial and then selecting the .so file as the native library. Eclipse will not automatically "find" your OpenCV library, you have to configure it to know about it, that's what the second tutorial is doing.
I think you were running the wrong command with ant. You can read the manual here: https://ant.apache.org/manual/running.html
Below is the format to run ant:
ant [options] [target [target2 [target3] ...]]
So maybe your command line should look like:
ant -DocvJarDir=/usr/local/src/opencv-2.4.8/opencv/build/bin rebuild-run
given that /usr/local/src/opencv-2.4.8/opencv/build/bin contains the opencv-248.jar
As shown on your build.xml file that the property ocvJarDir is pointing to the location of the classpath requires to build the project:
<property name="lib.dir" value="${ocvJarDir}"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
And you need to specify the target "rebuild-run" in the command line since your build.xml does not have a default target specified.
Try installing 2.4.6 version. I have similar problems when installing in VS. Older version worked. Maybe it's the same in Eclipse, too.
I have written a JavaFx 2 application (using Eclipse on a Windows platform) and now I want to deploy it to a "clickable" jar-file. My application uses resource-code from a separate jar-file (in Eclipse, this resource code is a separate Project from the JavaFx application project).
With my Ant build.xml, I have compiled the code for both the application and the resource code and created two jar-files:
fxdemo.jar - A jar for my JavaFx application code
guifw.jar - A jar for the resource code referenced by the JavaFx application.
As a last step (I thought), using the JavaFX Ant tasks, I wanted to bundle these two jar-files to a "clickable" jar that starts my JavaFX application. I tried doing just that with the below extract from my build.xml.
<target name="deployFx" depends="fxdemo.jar" description="Releases FxDemo">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
<copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>
<fx:application id="FxDemoGUI" name="Fx Demo GUI" MainClass="com.demo.main.MainGUI"/>
<fx:resources id="jars">
<fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
<fx:fileset dir="delivery/lib" includes="guifw.jar"/>
</fx:resources>
<fx:jar destfile="deploy/fxDemoGui.jar">
<!-- Define what to launch -->
<fx:application refid="FxDemoGUI"/>
<fx:platform javafx="2.1+">
<fx:jvmarg value="-Xms32m"/>
<fx:jvmarg value="-Xmx32m"/>
<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
<property name="user.language" value="en"/>
<property name="user.country" value="GB"/>
<property name="CSS_ID" value="NIGHT"/>
</fx:platform>
<fx:resources>
<fx:fileset dir="delivery/lib" includes="fxdemo.jar"/>
<fx:fileset dir="delivery/lib" includes="guifw.jar"/>
</fx:resources>
<manifest>
<attribute name="Implementation-Vendor" value="${fxgui.vendor}"/>
<attribute name="Implementation-Title" value="${fxgui.title}"/>
<attribute name="Implementation-Version" value="1.0"/>
</manifest>
<fileset dir="delivery"/>
</fx:jar>
However, afterwards when I try to start the application (by either clicking the jar or starting from command line with java -jar appname.jar) it seems as the application can not find the Main class:
JavaFX Launcher Error
Unable to find class: com.demo.main.MainGUI
C:\Program Files\Java\jdk1.7.0_09\bin>java -jar C:\MEKMAN\Clearcase_Views\wmarekm_ss_gambau\amb_c2_prototype\javafx\prototypeGUI\deploy\fxDemoGui.jar
java.lang.ClassNotFoundException: com.demo.main.MainGUI
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.javafx.main.Main.getAppClass(Main.java:506)
at com.javafx.main.Main.launchApp(Main.java:622)
at com.javafx.main.Main.main(Main.java:805)
When I studie the created MANIFEST.MF (in the created jar-file) it looks pretty much as what I expected.
Manifest-Version: 1.0
JavaFX-Version: 2.1+
implementation-vendor: MyVendor
implementation-title: MyfirstJavaFxDeploy
implementation-version: 1.0
JavaFX-Application-Class:com.demo.main.MainGUI
JavaFX-Class-Path: fxdemo.jar guifw.jar
Created-By: JavaFXPackager
Main-Class: com/javafx/main/Main
... but then again, it doesn't work so obviously I have done something wrong.
I also tried including the classes-directory (the output folders from each of the two Eclipse/projects) by adding:
<fileset dir="../guifw/classes"/>
<fileset dir="classes"/>
Then, the launcher does find my main class (com.demo.main.MainGUI) but failes to run correctly because it lacks the -D argument that I tried to specify with:
<property name="com.util.fxguifw.setup" value="com/util/fxguifw/demo/demo.properties"/>
So, if you have read this far, my questions are:
Why can't the launcher find my main class in the referenced jar (fxdemo.jar)?
What have I done wrong when it comes to specify my -D arguments to the application?
Best regards
I studied/tested the fix presented in post (2012-apr-12 03:32) in the link from #Anders Petersson:
Link from #Anders Petersson
From what I can see, this is a workaround that unbudles any used jar-file (in my case; guifw.jar & demofx.jar) within the resulting jar file (fxDemoGui.jar), much like adding the classes-folders from my two Eclipse-projects (as described in the question).
I adjusted the example to my build.xml and got it to work after one slight addition:
<target name="dist" depends="fxdemo.jar">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath=".:${fxgui.javaHome}\lib\ant-javafx.jar"/>
<copy file="${fxgui.lib_guifw_path}" tofile="delivery/lib/guifw.jar"/>
<fx:jar destfile="predeploy/fxDemoGui.jar">
<!-- ADDITION -> Adds the Launcher's Main class to the resulting jar (com.javafx.main.Main)! -->
<fx:application id="FxDemoGUI"
name="Fx Demo GUI"
mainClass="com.demo.main.MainGUI"/>
<fileset dir="delivery"/>
</fx:jar>
</target>
In the dist-target from the example, I had to add:
<fx:application id="FxDemoGUI"
name="Fx Demo GUI"
mainClass="com.demo.main.MainGUI"/>
Without it, the resulting jar-file did not have the necessary com.javafx.main.Main-class and hence, failed to start.
So, this solution presents a useful workaround for my question 1)
Still, I'd be grateful if anyone comes up with a solution on how to keep the jar-files intact within the resulting jar/file.
While using ivy:retrieve, it fails to resolve the dependency that should be downloaded. The output looks like this:
Buildfile: C:\Users\Simon\workspace\apollo\build.xml
init:
resolve:
BUILD FAILED
C:\Users\Simon\workspace\apollo\build.xml:42: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
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
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
-C:\Users\Simon\.ant\lib
-a directory added on the command line with the -lib argument
Total time: 348 milliseconds
The relevant section of the build.xml looks like so:
<target name="resolve" depends="init">
<ivy:retrieve pattern="${lib}/[artifact]-[revision].[ext]" sync="true" />
</target>
Here is also a list of what it should be downloading (from the build.xml)
<target name="doc" depends="build">
<javadoc sourcepath="${src}" classpathref="libraries" access="private" destdir="${doc}" windowtitle="Apollo">
<doclet name="org.jboss.apiviz.APIviz" pathref="libraries">
<param name="-sourceclasspath" value="${bin}" />
<param name="-author" />
<param name="-version" />
<param name="-use" />
<param name="-nopackagediagram" />
</doclet>
<doctitle><![CDATA[<h1>Apollo</h1>]]></doctitle>
<link href="http://download.oracle.com/javase/6/docs/api/" />
<link href="http://docs.jboss.org/netty/3.2/api/" />
<link href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/" />
<link href="http://www.junit.org/apidocs/" />
<link href="http://commons.apache.org/compress/apidocs/" />
<link href="http://jruby.org/apidocs/" />
</javadoc>
</target>
ANT cannot find the ivy jar. Needs to be downloaded, extracted, and the ivy-x.y.z.jar placed into one of the following locations:
$ANT_HOME/lib
$HOME/.ant/lib
Enabling ivy
Ivy is packaged as an antlib, so to enable it you need to do the following
1)
Declare the ivy namespace at the top of the build file
<project ..... xmlns:ivy="antlib:org.apache.ivy.ant">
2)
Include the ivy jar in one of the ant library directories
Your error message indictates some of the possible locations for antlibs:
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
-C:\Users\Simon\.ant\lib
-a directory added on the command line with the -lib argument
Note:
The beauty of an antlib is that you don't need to perform the taskdef (It's optional if you want to place the ivy jar in a non-standard location)
How to bootstrap a build
Even though ivy is an ANT sub-project, for some inexplicable reason ivy is not packaged with ANT....
I normally include the following target in my build files to setup a new environment:
<target name="bootstrap" description="Used to install the ivy task jar">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>
It downloads the ivy jar from Maven Central.
Since all other ANT tasks can subsequently be downloaded using ivy, few people object to this little piece of ugliness at the top of the build file.
If you can't put the ivy libs in the classpath for ant you will need to define it yourself:
<path id="ivy.lib.path">
<fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
This bit is missing from the getting started tutorial, but listed here: http://ant.apache.org/ivy/history/2.2.0/ant.html
When you Run Ant task, in the classpath ensure that ivy.jar is there. In the eclipse -> Run As-> Ant Build -> Edit configuration -> Classpath tab. Even though Eclipse would have the ivy.jar in the ANT Home, for some reason it's not called.
I had a similar problem on MacOSX (10.11.6 El Capitan). I installed ant and Ivy with the Brew package manager.
One additional way is to define it manually using the -lib option, e.g.:
ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar
Even after adding ivy jar to the ant lib, it was not being picked up. Selecting the ANT_HOME again in Preferences->Ant->Runtime will cause the lib dir to be refreshed, and any libraries you have added there to be taken up.
I'm new to GWT, and I'm setting up a project to hold the UI portion of a complicated application. The JPA data objects are defined in a separate project using MyBatis generated POJOs. Once I manually modify the JPA objects to include 'implements Serializable' (this is a separate problem I need to solve), the gwtc step in the build process can't continue because it needs the source code for the JPA object, but can't find them.
I've created the 'core' project's jar files so that it includes the source .java files, but this didn't work. I've tried adding a classpath element to the gwtc ant java call.
How can I make my UI project compile while keeping the JPA objects defined in a separate project?
Errors:
Buildfile: /Users/user/source/user_interface/build.xml
libs:
javac:
gwtc:
[java] Compiling module org.mysite.ui
[java] Validating newly compiled units
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyService.java'
[java] [ERROR] Line 21: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyServiceAsync.java'
[java] [ERROR] Line 19: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/presenter/MainTabPresenter.java'
[java] [ERROR] Line 75: No source code is available for type org.mysite.core.model.Person; did you forget to inherit a required module?
[java] Scanning for additional dependencies: file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyApp.java
[java] Computing all possible rebind results for 'org.mysite.ui.client.MyService'
[java] Rebinding org.mysite.ui.client.MyService
[java] Checking rule <generate-with class='com.google.gwt.user.rebind.ui.ImageBundleGenerator'/>
[java] [ERROR] Unable to find type 'org.mysite.ui.client.MyService'
[java] [ERROR] Hint: Previous compiler errors may have made this type unavailable
[java] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[java] [ERROR] Errors in 'file:/Users/user/source/user_interface/src/org/mysite/ui/client/MyApp.java'
[java] [ERROR] Line 23: Failed to resolve 'org.mysite.ui.client.MyService' via deferred binding
[java] [ERROR] Cannot proceed due to previous errors
BUILD FAILED
/Users/user/source/user_interface/build.xml:39: Java returned: 1
Total time: 26 seconds
Ant gwtc target:
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<pathelement location="../core/src"/>
<path refid="project.class.path"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg line="-war"/>
<arg value="web"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="org.mysite.ui.MyApp"/>
</java>
</target>
GWT has always had this problem.
The approach I have taken in the past is to make a .gwt.xml module in the other JAR including the JPA POJOs and putting the JPA annotation classes in an "emul" javax.persistence folder. This won't work w/ many providers that use lazy fetching of course, so Gilead (as mentioned in another answer here) will be needed.
Another way is to make copies of the JPA objects and just Dozer them before sending across RPC
Luckily, GWT 2.1 has solved this problem. Use Entity proxies and request factories. It works well.
Either use the new GWT 2.1 RequestFactory / EntityProxy approach, or
Better, ditch the JPA and use Objectify or Twig.
We use Objectify, because JPA is not a good fit for Datastore. JPA was created with SQL-based relational databases in mind, while GAE Datastore is an entirely different thing.
Google ported JPA layer to Datastore to lure in developers, pretending that Datastore is just a plain old SQL relational database. This later blows up in their faces once projects grow big.
You really need to understand the Datastore tradeoffs if you want to use AppEngine. JPA is not making you a favor here.
Your best bet if you want to serialize POJOs to GWT is to use Gilead http://noon.gilead.free.fr/gilead/
All you have to do on your POJO is extend LightEntity and implement Serializable
The tutorial is pretty straight forward in how to set up the RPC.
I can successfully compile the source, but when I hit this ant task:
<target name="gwtc" depends="javac" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<jvmarg value="-Xmx256M"/>
<arg line="${gwt.args}"/>
<arg value="com.jwavro.jaguar.jaguar"/>
</java>
</target>
I'm getting these errors:
gwtc:
[java] Compiling module com.jwavro.jaguar.jaguar
[java] Scanning for additional dependencies: generated://9161C2B729E3521B2A51CBE6F2AE8A77/com/unnison/framework/client/GeneratedGinInjector.java
[java] Computing all possible rebind results for 'com.unnison.framework.client.GeneratedGinInjector'
[java] Rebinding com.unnison.framework.client.GeneratedGinInjector
[java] Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
[java] [ERROR] Generator 'com.google.gwt.inject.rebind.GinjectorGenerator' threw an exception while rebinding 'com.unnison.framework.client.GeneratedGinInjector'
[java] com.google.inject.CreationException: Guice creation errors:
[java]
[java] 1) No implementation for javax.inject.Provider was bound.
[java] while locating javax.inject.Provider
[java] for parameter 9 at com.google.gwt.inject.rebind.BindingsProcessor.(BindingsProcessor.java:209)
[java] at com.google.gwt.inject.rebind.GinjectorGeneratorModule.configure(GinjectorGeneratorModule.java:59)
GUICE binding is supposed to be automatic, any idea how to fix it ?
Guice can not be used directly with GWT. You need to use GIN.
javax.inject is a dependency that needs to be in your classpath.
If you downloaded Guice from Google, there should be a lib folder in the exploded zip with a javax.inject.jar file, or you can download it direct from trunk.
The key is this line:
[java] 1) No implementation for javax.inject.Provider was bound.
There are two things I can think of. First of all make sure you have properly inherited the GIN module in your GWT module xml:
<module>
...
<inherits name="com.google.gwt.inject.Inject"/>
...
</module>
Secondly you have to be carefull about versions of GIN and Guice. On the GIN homepage it says:
GIN 1.0 requires ... and Guice 2.0
For Gin 1.5 you'll need to use the Guice snapshot distributed with Gin or ... Guice 3.0
So make sure you have the appropriate Guice JAR in path.