Dojo 1.7 Build: Out of Memory Errors - java

After upgrading to Dojo 1.7.3, our ant build that was working flawlessly for years on previous versions of Dojo is now completely non-operational due to out of memory errors:
[java] starting writing resources...
[java] java.lang.OutOfMemoryError: GC overhead limit exceeded
[java] at org.mozilla.javascript.Interpreter.getArgsArray(Interpreter.java:4623)
[java] at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3335)
[java] at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2484)
[java] at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
[java] at org.mozilla.javascript.NativeArray.iterativeMethod(NativeArray.java:1565)
[java] at org.mozilla.javascript.NativeArray.execIdCall(NativeArray.java:313)
[java] at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
[java] at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3335)
[java] at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2484)
[java] at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
[java] at org.mozilla.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2347)
[java] at org.mozilla.javascript.BaseFunction.execIdCall(BaseFunction.java:272)
[java] at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
[java] at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
[java] at org.mozilla.javascript.gen.c1._c62(Unknown Source)
[java] at org.mozilla.javascript.gen.c1.call(Unknown Source)
[java] at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
[java] at org.mozilla.javascript.gen.c1._c69(Unknown Source)
[java] at org.mozilla.javascript.gen.c1.call(Unknown Source)
[java] at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
[java] at org.mozilla.javascript.gen.c1._c40(Unknown Source)
[java] at org.mozilla.javascript.gen.c1.call(Unknown Source)
[java] at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
[java] at org.mozilla.javascript.gen.c1._c42(Unknown Source)
[java] at org.mozilla.javascript.gen.c1.call(Unknown Source)
[java] at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3335)
[java] at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2484)
[java] at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
[java] at org.mozilla.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2347)
[java] at org.mozilla.javascript.BaseFunction.execIdCall(BaseFunction.java:272)
[java] at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:127)
[java] at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
[java] js: exception from uncaught JavaScript throw: java.lang.OutOfMemoryError: GC overhead limit exceeded
I have extensively documented our troubles here.
In particular, where I note:
If I run my build straight from the CL as a Java command, with the '
--optimize shrinksafe" switch, it fails, but without it succeeds. (running it with internStrings alone seems to cause other errors).
Not sure what to make of this, since I believe that oprtimize defaults
to shrinksafe, but I have determined the following:
WORKS:
c:\temp\dojo-release-1.7.3rc1-src\util\buildscripts>java -Xms256m
-Xmx256m -cp ../shrinksafe/js.jar;../closureCompiler/compiler.jar;../shrinksafe/shrinksafe.jar
org.mozilla.javascript.tools.shell.Main ../../dojo/dojo.js
baseUrl=../../dojo load=build -p
C:\company\builds\head\build\generated\general\comComplete.profile.js
--action release --releaseDir C:\company\builds\head\build\generated\general\htdocs\company\javascript\1420
BROKEN (out of memory errors):
c:\temp\dojo-release-1.7.3rc1-src\util\buildscripts>java -Xms256m
-Xmx256m -cp ../shrinksafe/js.jar;../closureCompiler/compiler.jar;../shrinksafe/shrinksafe.jar
org.mozilla.javascript.tools.shell.Main ../../dojo/dojo.js
baseUrl=../../dojo load=build -p
C:\company\builds\head\build\generated\general\comComplete.profile.js
--action release --releaseDir C:\company\builds\head\build\generated\general\htdocs\company\javascript\1420
--optimize shrinksafe --internStrings true
Unfortunately, the following ant script target continues to fail with
memory errors:
BuildNum: ${buildNum}
<path id="js.path"> <pathelement location="${basedir}"/>
</path>
<pathconvert targetos="unix" property="js.path.unix" refid="js.path"
/> js.path.unix: ${js.path.unix}
<!-- clean unpack and output dirs --> <delete
dir="${outputDir}/htdocs/company/javascript/src/" />
<copy file="${externalDir}/dojo/companyComplete.profile.js"
tofile="${outputDir}/companyComplete.profile.js" filtering="yes"
overwrite="yes">
<java fork="true"
dir="${outputDir}/htdocs/company/javascript/src/util/buildscripts"
classname="org.mozilla.javascript.tools.shell.Main"
failonerror="true">
-->
--> --> -->
Update 1
I've also tried it with:
<jvmarg value="-Xms5120m"/>
<jvmarg value="-Xmx5120m"/>
And also using the maxmemory setting on the ant java task itself.

Finally found the problem, the releaseDir switch value had both windows and unix file separators in it. That used to work fine in Dojo < 1.6 and typically Java has no problem with it. For some reason, the Dojo 1.7 build system hits memory problems in that case.
The releaseDir, after resolving the ant tokens from the question, had a mix of both unix and windows file separators:
<arg value="releaseDir=${output.dir}/path/foo/bar" />
-> Became ->
releaseDir=blah\blah\blah/path/foo/bar
And that was enough to cause the build to lock up at 'writing resources' and then crash with 'out of heap space'. (This is something Java normally handles without issue).
The fix was simple enough:
<path id="dojo.output.tmp">
<pathelement location=" ${output.dir}/path/foo/bar "/>
</path>
<pathconvert targetos="unix" property="dojo.output.dir" refid="dojo.output.tmp" />
...
<arg value="releaseDir=${dojo.output.dir}" />

Related

ClassCastException for class implementing class from another jar

I'm getting the below exception when attempting to run the class org.apache.tools.ant.launch.Launcher which comes as part of the ant launcher jar :
testTask: [java] Working directory ignored when same JVM is used.
[java] Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_141\lib\tools.jar
[java] java.lang.ClassCastException: org.apache.tools.ant.Main cannot be cast to org.apache.tools.ant.launch.AntMain
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:256)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[java] at java.lang.Thread.run(Unknown Source)
This is the ant target I'm running:
<target name="testTask">
<java classname="org.apache.tools.ant.launch.Launcher" failonerror="true" jvm="C:/jdk1.8.0_141-x64/bin/java" dir=".">
<classpath>
<pathelement location="ant-launcher-1.7.0.jar"/>
<pathelement location="ant-1.7.0.jar"/>
</classpath>
</java>
</target>
and if you look inside ant-1.7.0.jar inside the classpath, you will find that org.apache.tools.ant.Main in fact implements org.apache.tools.ant.launch.AntMain:
and inside ant-launcher-1.7.0.jar, org.apache.tools.ant.launch.AntMain exists exactly under the package we're looking for:
Also I made sure that org.apache.tools.ant.Main overrides the method startAnt(String[] paramArrayOfString, Properties paramProperties, ClassLoader paramClassLoader) and takes the same arguments.
The line causing this exception is:
mainClass = Class.forName("org.apache.tools.ant.Main");
AntMain main = (AntMain)mainClass.newInstance();
worth noting that if I create the exact same class as org.apache.tools.ant.Main but rename it and place it on its own (outside of any .jar package), and run the above snippet but using the name of the new class it works perfectly fine.
Why is java insisting that org.apache.tools.ant.Main cannot be cast to org.apache.tools.ant.launch.AntMain ?

Playn error - org.lwjgl.LWJGLException: X Error

After much work around, now i am able to understand the playn environment. Every thing is ok now, but, when i enter:
mvn install (from the main directory)
(or)
mvn java/pom.xml test -Ptest-java
I am getting the following error. I updated the pom.xml (java directory) with this
<!-- unpack LWJGL when testing -->
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<id>unpacknatives</id>
<phase>test-compile</phase>
<goals><goal>copy</goal></goals>
</execution>
</executions>
</plugin>
Then also, same error, can any one guide me on this
main:
[java] failed to create drawable
[java] Exception in thread "main" java.lang.RuntimeException: org.lwjgl.LWJGLException: X Error - disp: 0xa0b7cc8 serial: 91 error: BadGC (invalid GC parameter) request_code: 60 minor_code: 0
[java] at playn.java.JavaGLContext.initGL(JavaGLContext.java:183)
[java] at playn.java.JavaGraphics.init(JavaGraphics.java:155)
[java] at playn.java.JavaPlatform.run(JavaPlatform.java:218)
[java] at playn.core.PlayN.run(PlayN.java:37)
[java] at main.java.ExampleJava.main(ExampleJava.java:13)
[java] Caused by: org.lwjgl.LWJGLException: X Error - disp: 0xa0b7cc8 serial: 91 error: BadGC (invalid GC parameter) request_code: 60 minor_code: 0
[java] at org.lwjgl.opengl.LinuxDisplay.globalErrorHandler(LinuxDisplay.java:316)
[java] at org.lwjgl.opengl.LinuxKeyboard.nSetDetectableKeyRepeat(Native Method)
[java] at org.lwjgl.opengl.LinuxKeyboard.setDetectableKeyRepeat(LinuxKeyboard.java:152)
[java] at org.lwjgl.opengl.LinuxKeyboard.destroy(LinuxKeyboard.java:163)
[java] at org.lwjgl.opengl.LinuxDisplay.destroyKeyboard(LinuxDisplay.java:1190)
[java] at org.lwjgl.input.Keyboard.destroy(Keyboard.java:349)
[java] at org.lwjgl.opengl.Display.destroyWindow(Display.java:349)
[java] at org.lwjgl.opengl.Display.access$400(Display.java:62)
[java] at org.lwjgl.opengl.Display$5.destroy(Display.java:860)
[java] at org.lwjgl.opengl.Display.create(Display.java:880)
[java] at org.lwjgl.opengl.Display.create(Display.java:782)
[java] at org.lwjgl.opengl.Display.create(Display.java:764)
[java] at playn.java.JavaGLContext.initGL(JavaGLContext.java:173)
[java] ... 4 more
[java] Java Result: 1
Fact: Linux 64-bit + LWJGL = Problems
If you are using a 64-bit Linux then try these one by one:
Upgrade to the newest version of LWJGL(2.8.4)
Install OpenJDK7 64-bit and have it as the default jvm
I believe there was a third fix but forgot what it was. I'll edit it in when I find it.
If you're using a 32-bit Linux then none of these will help.

GWT compiler doesn't find javax libraries

I'm new to GWT and trying to run my fist GWT app. I have classes that uses API from javax.persistence package. When I try to compile the code using GWT compiler it fails for not being able to find the mentioned package in the classpath. I have the libraries added to the class though.
<property name="gwt.sdk" location="C:/gwt-2.4.0" />
<!-- Arguments to gwtc and devmode targets -->
<property name="gwt.args" value="" />
<path id="gwt.class.path">
<fileset dir="${devLib}"> <!-- here is all the dependent libraries-->
<include name="*.jar" />
</fileset>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
</path>
<target name="gwtc" description="GWT compile to JavaScript (production mode)">
<echo message="${gwt.class.path}"/>
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<path refid="gwt.class.path"/>
<pathelement location="gwt/project/src"/>
</classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
<jvmarg value="-Xmx256M"/>
<arg line="-war"/>
<arg value="web/five/gwtUI"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="org.scheduling.Scheduling"/>
</java>
</target>
here is the error that I see when run the ant target gwtc. Can someone help me to correct this?
[java] Compiling module org.scheduling.Scheduling
[java] Validating newly compiled units
[java] Ignored 91 units with compilation errors in first pass.
[java] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[java] Computing all possible rebind results for 'com.google.gwt.user.client.UserAgentAsserter'
[java] Rebinding com.google.gwt.user.client.UserAgentAsserter
[java] Checking rule <generate-with class='com.google.gwt.editor.rebind.SimpleBeanEditorDriverGenerator'/>
[java] [WARN] Detected warnings related to 'com.google.gwt.editor.client.SimpleBeanEditorDriver'. Are validation-api-<version>.jar and validation-api-<version>-sources.jar on the classpath?
[java] Specify -logLevel DEBUG to see all errors.
[java] [WARN] Unknown type 'com.google.gwt.editor.client.SimpleBeanEditorDriver' specified in deferred binding rule
[java] Scanning for additional dependencies: file:/C:/Tolven_skandula/org.component.scheduling/gwt/project/src/org/scheduling/gwt/common/client/SchedulingEntryPoint.java
[java] Computing all possible rebind results for 'org.scheduling.common.service.SchedulingService'
[java] Rebinding org.scheduling.common.service.SchedulingService
[java] Checking rule <generate-with class='com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator'/>
[java] [ERROR] Errors in 'file:/C:/Tolven_skandula/org.component.scheduling/gwt/project/src/org/scheduling/common/model/Appointment.java'
[java] [ERROR] Line 5: The import javax.persistence cannot be resolved
[java] [ERROR] Line 6: The import javax.persistence cannot be resolved
[java] [ERROR] Line 7: The import javax.persistence cannot be resolved
[java] [ERROR] Line 8: The import javax.persistence cannot be resolved
[java] [ERROR] Line 9: The import javax.persistence cannot be resolved
Have a look at http://code.google.com/intl/de-DE/webtoolkit/doc/latest/RefJreEmulation.html, which describes the classes from the standard JRE GWT is emulating. javax.persistence doesn't seem to be supported.
That's the thing with gwt. Only a small subset of the standard JRE is supported (given by the fact that JavaScript will never have the same functionality, as it runs in a browser environment). Also, whilst the google guys are trying to integrate more and more classes, they are only that fast.
But you can always create your own classes and libraries.
Ahhh yes, an old problem: your domain classes annotated with JPA annotations can not be used by GWT. You probably need to send those objects via RPC?
People have been solving this for some time - google around:
GWT with JPA
GWT + entities + JPA + DTO + Dozer
http://objectgeneration.com/eclipse/16-GWT.html
http://uptick.com.au/content/transferring-jpa-objects-server-browser
I had same problem. I've downloaded: javamail from:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.7-oth-JPR
and I've added : mailapi.jar to mu buildpath and GWT found javax.mail.*.
Good luck;
Anna
I have run into this issue using GWT 2.6.0. Rollbacking to GWT 2.5.1 solved it for me.
It's quite a wierd behaviour, as Java should treat annotations as mandatory. Not having sources should result in ignoring annotations, so annotations do not become tight coupling.

ClassNotFoundException with ant's java task and classpath

I am trying to compile and run a simple java class within eclipse. The compile task works fine, and since I do not specify a destination folder the build files are in the same directory as the source. Which is alright, at the moment all I need is to learn how I can run the class with the main() method.
I have tried using the fully qualified name of the class (with package name, etc) and the classname alone, but always I get a java.lang.ClassNotFoundException
Buildfile: C:\Users....\build.xml
run:
[java] java.lang.NoClassDefFoundError: code/control/MyClass
[java] Caused by: java.lang.ClassNotFoundException: code.control.MyClass
[java] at java.net.URLClassLoader$1.run(Unknown Source)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClassInternal(Unknown Source)
[java] Could not find the main class: code.control.MyClass. Program will exit.
[java] Exception in thread "main"
[java] Java Result: 1
compile:
default:
BUILD SUCCESSFUL
Total time: 234 milliseconds
Below, are the targets taken from my build.xml file:
<target name="default" depends="compile" description="learn">
</target>
<target name="compile" depends="run">
<javac srcdir="src/" />
</target>
<target name="run">
<java classname="code.control.MyClass" fork="true"/>
</target>
I can't figure out why the class is not found. MyClass contains the main() method and since i specify no classpath it should look at the current directory, which is the src/ right?
The development directory is the usual eclipse file structure:
projectName/src/code/control/MyClass
If it is a classpath problem how could I resolve it? I always had problem grasping the concept "put it on your classpath" ... If someone could provide a little bit of explanation with the classpath in the ant context, I would be very thankful.
Thanks for any help on this. The version of ant is 1.7.0
The classpath is where the Java runtime looks for your .class files, similar to how your OS uses the PATH variable to find executables.
Try this in your build script:
<target name="run">
<java fork="true" classname="code.control.MyClass">
<classpath>
<path location="src/"/>
</classpath>
</java>
There's a HelloWorld version for ant that walks through building a Java program with ant.
you should include classpath, e.g.
<java classpath="${bin}" classname="code.control.MyClass">
where ${bin} is your output folder.
change your build.xml as below and try out:
<target name="default" depends="run" description="learn">
</target>
<target name="compile" >
<javac srcdir="src/" />
</target>
<target name="run" depends="compile">
<java classname="code.control.MyClass" fork="true"/>
</target>

How can I have my ant task pass or fail based on the results of a jar it runs?

I'm running CrossCheck (browserless js unit testing) as part of an ant script. I'd like ant to report failure if the CrossCheck tests fail. Here's the relevant bit from the build.xml
<target name="test" depends="concat">
<java jar="src/test/lib/crosscheck.jar" fork="true">
<arg value="src/test/webapp/js/"/>
</java>
And an example of CrossCheck's failure messaging:
[java] Running tests in environment: Mozilla 1.7 (Firefox 1.0)
[java] org.mozilla.javascript.EcmaError: ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
[java] at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
[java] at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
[java] at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3292)
[java] at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1636)
[java] at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1575)
[java] at org.mozilla.javascript.gen.c1._c1(ResultXMLWrapperTest.js:22)
[java] at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
[java] at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
[java] at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
[java] at org.mozilla.javascript.gen.c1.call(ResultXMLWrapperTest.js)
[java] at net.thefrontside.crosscheck.framework.AbstractScopeFactory$1.run(AbstractScopeFactory.java:108)
[java] at org.mozilla.javascript.Context.call(Context.java:515)
[java] at org.mozilla.javascript.Context.call(Context.java:450)
[java] at net.thefrontside.crosscheck.framework.AbstractScopeFactory.initTestScope(AbstractScopeFactory.java:94)
[java] at net.thefrontside.crosscheck.framework.DefaultScopeFactory.getTestScope(DefaultScopeFactory.java:68)
[java] at net.thefrontside.crosscheck.framework.TestCase$1.run(TestCase.java:119)
[java] at org.mozilla.javascript.Context.call(Context.java:528)
[java] at org.mozilla.javascript.Context.call(Context.java:450)
[java] at net.thefrontside.crosscheck.framework.TestCase.run(TestCase.java:117)
[java] at net.thefrontside.crosscheck.framework.TestSuite.run(TestSuite.java:95)
[java] at net.thefrontside.crosscheck.framework.Crosscheck.runAll(Crosscheck.java:116)
[java] at net.thefrontside.crosscheck.framework.ConsoleRunner.run(ConsoleRunner.java:140)
[java] at net.thefrontside.crosscheck.framework.ConsoleRunner.main(ConsoleRunner.java:300)
[java] ReferenceError: "clusterNode" is not defined. (ResultXMLWrapperTest.js#22)
[java] Java Result: 1
Can ant get at the results of the CrossCheck test (perhaps Java Result: 1 gets passed back to ant?) and succeed or fail based on that?
Assuming that CrossCheck returns a non-zero return code on a error you could add the failonerror attribute to the java task:
<target name="test" depends="concat">
<java jar="src/test/lib/crosscheck.jar" fork="true" failonerror="true">
<arg value="src/test/webapp/js/"/>
</java>
See the documentation on the Ant java task.
You can use the 'failonerror' attribute of the 'java' task.
failonerror Stop the buildprocess if
the command exits with a returncode
other than 0. Default is "false" (see
note)
Check the Ant manual here.

Categories

Resources