I'm trying to compile GWT from my project from command line (no Ant/Maven)
like this
java -cp "/home/user/gwt-2.8.2/*:/home/user/myapp/src:/home/user/myapp/lib/*" com.google.gwt.dev.Compiler com.myapp.webservices.SpwrWebServices
but error is thrown
Loading inherited module 'com.myapp.webservices.SpwrWebServices'
Loading inherited module 'gwt.material.design.GwtMaterialWithJQuery'
Loading inherited module 'gwt.material.design.GwtMaterialDesignBase'
[WARN] Line 40: Setting configuration property named 'CssResource.legacy' in module 'gwt.material.design.GwtMaterialDesignBase' that has not been previously defined
[ERROR] Line 18: Unable to load class 'com.myapp.webservices.client.util.GitCommitGenerator'
java.lang.ClassNotFoundException: com.myapp.webservices.client.util.GitCommitGenerator
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.google.gwt.dev.cfg.ModuleDefSchema$ClassAttrCvt.convertToArg(ModuleDefSchema.java:899)
at com.google.gwt.dev.util.xml.HandlerArgs.convertToArg(HandlerArgs.java:64)
at com.google.gwt.dev.util.xml.HandlerMethod.invokeBegin(HandlerMethod.java:221)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.startElement(ReflectiveParser.java:296)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.parse(ReflectiveParser.java:349)
at com.google.gwt.dev.util.xml.ReflectiveParser$Impl.access$200(ReflectiveParser.java:70)
at com.google.gwt.dev.util.xml.ReflectiveParser.parse(ReflectiveParser.java:431)
at com.google.gwt.dev.cfg.ModuleDefLoader.nestedLoad(ModuleDefLoader.java:316)
at com.google.gwt.dev.cfg.ModuleDefLoader.load(ModuleDefLoader.java:243)
at com.google.gwt.dev.cfg.ModuleDefLoader.doLoadModule(ModuleDefLoader.java:193)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromResources(ModuleDefLoader.java:151)
at com.google.gwt.dev.cfg.ModuleDefLoader.loadFromClassPath(ModuleDefLoader.java:126)
at com.google.gwt.dev.Compiler.compile(Compiler.java:139)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:118)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
at com.google.gwt.dev.Compiler.main(Compiler.java:125)
I do have the file src/com/myapp/webservices/client/util/GitCommitGenerator.java so I don't understand my this error is showed. My gwt config xml file looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.7.0//EN" "\s">
<module rename-to= "SpwrWebServices">
<inherits name="com.google.gwt.user.User" />
<!-- GwtMaterialWithJQuery module is smaller and should be used for production code -->
<!-- <inherits name="gwt.material.design.GwtMaterialWithJQuery" /> -->
<!-- GWTMaterialWithJQueryDebug This module is larger and includes non-minified source for easier debugging -->
<!-- GWT Material -->
<inherits name="gwt.material.design.GwtMaterialWithJQuery"/>
<inherits name="gwt.material.design.addins.GwtMaterialAddins"/>
<inherits name="org.fusesource.restygwt.RestyGWT" />
<inherits name='com.googlecode.gwt.charts.Charts'/>
<inherits name="org.moxieapps.gwt.uploader.Uploader"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.logLevel" value="INFO"/>
<generate-with class="com.myapp.webservices.client.util.GitCommitGenerator">
<when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
</generate-with>
<source path="client" />
<!-- <source path ="shared" /> -->
<entry-point
class="com.myapp.webservices.client.SpwrWsEntryPoint" />
<set-property name="user.agent" value="gecko1_8,safari"/>
<set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
</module>
What is wrong with the configuration above and how can I get a clean compilation?
First, generators should not be written new any more, you should start with Java Annotation Processors or some other feature which does not rely on the GWT compiler generating code.
Second, any Generator you write should not be put in your client package, but should be somewhere that GWT will not try to compile it to JS sources. Usually people use the convention of rebind for the classes which let you change bindings of your GWT code and generate new classes.
Finally, it looks like you are running the GWT compiler on your sources without first compiling them with java. First, use javac to compile all your .java files to .class files, and then pass those on the rest of the classpath. Technically you only need your generator and anything it references, but you'd probably like Javac to report errors before GWT does, since it will do a nicer job.
Consider Maven or Gradle to manage your build instead, so it does the javac work for you, and builds the classpath to give to GWT for you too.
The project defines a generator inside the module descriptor:
<generate-with class="com.myapp.webservices.client.util.GitCommitGenerator">
<when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
</generate-with>
The generator is located under the client-package. GWT will try to compile it, which will pretty sure fail.
Try this:
create a new package besides the client package, call ist rebind
move the GitCommitGenerator to that package.
update the reference inside your module descriptor to
<generate-with class="com.myapp.webservices.rebind.GitCommitGenerator">
<when-type-assignable class="com.myapp.webservices.client.util.GitCommit"/>
</generate-with>
Think, this will solve the problem.
Related
I am trying to run a unsigned applet jar locally.
It uses several jar dependencies and some of those need native dlls. But I do not know how to point those dlls from the applet when deploying it on a browser.
When running using eclipse applet viewer I have set,
System.setProperty("jna.library.path", "<path>");
And it worked fine.
But when I deploy same on IE 10 it gives me the below exception
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jna.library.path" "write")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at com.neurotec.samples.SimpleFacesApplication.<init>(SimpleFacesApplication.java:88)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
I want to know where to put those dlls when loading from a browser.
Thanks in advance.
UPDATE
I have tried adding all the dlls to a new jar file called nativelibs.jar and added the entry <nativelib href="nativelibs.jar"/> to my applet JNLP file. But the issue is still remains same giving
java.lang.UnsatisfiedLinkError: Unable to load library 'NCore': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:194)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:283)
at com.neurotec.lang.NCore.<clinit>(NCore.java:104)
Now the resources tag of my JNLP file is like
<resources>
<!-- Application Resources -->
<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" />
<jar href="myApplet.jar" main="true" />
<nativelib href="nativelibs.jar"/>
</resources>
Any body have an idea, what is my mistake?
When starting my Java application, I get exceptions when trying to save images. In Eclipse, however, everything works fine. The application is built using fatjar and the necessary libraries (jar_imageio.jar and ij.jar) have been selected for export as well.
I tried using ImageIO and ImageJ:
a.) ImageIO:
ImageIO.write(image, "jpg", new File(f));
Exception in thread "main" sun.misc.ServiceConfigurationError:
javax.imageio.spi.ImageWriterSpi:
Provider com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageWriterSpi
could not be instantiated: java.lang.IllegalArgumentException: vendorName == null!
at sun.misc.Service.fail(Unknown Source)
at sun.misc.Service.access$200(Unknown Source)
at sun.misc.Service$LazyIterator.next(Unknown Source)
at javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(Unknown Source)
at javax.imageio.spi.IIORegistry.<init>(Unknown Source)
at javax.imageio.spi.IIORegistry.getDefaultInstance(Unknown Source)
at javax.imageio.ImageIO.<clinit>(Unknown Source)
b.) ImageJ:
IJ.saveAs(image, "jpg", f);
java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO
at ij.plugin.JpegWriter.saveAsJpeg(JpegWriter.java:49)
at ij.plugin.JpegWriter.save(JpegWriter.java:28)
at ij.io.FileSaver.saveAsJpeg(FileSaver.java:340)
at ij.io.FileSaver.saveAsJpeg(FileSaver.java:332)
at ij.plugin.filter.Writer.run(Writer.java:24)
at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:256)
at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:105)
at ij.IJ.runPlugIn(IJ.java:158)
at ij.Executer.runCommand(Executer.java:127)
at ij.Executer.run(Executer.java:64)
at ij.IJ.run(IJ.java:249)
at ij.IJ.run(IJ.java:296)
at ij.IJ.saveAs(IJ.java:1579)
As #Victor says I think you should look at
Exception in thread "main" sun.misc.ServiceConfigurationError:
javax.imageio.spi.ImageWriterSpi:
Provider com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageWriterSpi
could not be instantiated: java.lang.IllegalArgumentException: vendorName == null!
I had this issue just yesterday and it was tricky. There are similar questions here. I found if I included jai_imageio in the jar and did not modify the manifest file to include the contents of the JAI manifest file or combine the files in the services folder of META-INF in your build then I had a number of errors similar to yours. My application did work though without JAI included since JAI was installed locally I opted to build it with JAI included for the time being.
Opening you jar you will find a directory called META-INF. In there is the file MANIFEST.MF. I use Maven to include the JAI things in the Manifest file so it looks like
Manifest-Version: 1.0
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.0_01
Built-By: myName
Specification-Vendor: Sun Microsystems, Inc.
Created-By: Apache Maven
Implementation-Vendor: Sun Microsystems, Inc.
Build-Jdk: 1.6.0_43
Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.0-mr
Extension-Name: com.sun.media.imageio
Main-Class: myMain
Archiver-Version: Plexus Archiver
You should have your name and your main class substituted in there. You could just modify this file and jar it up yourself on the command line if you don't use Maven (or Ant) to get it working. I had the extra issue where some of my included jars were overwritting files in the services folder of META-INF. Instead I merged these files using Maven's Shade plugin.
add this lines into build.xml (solved for me)
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${TODAY}" />
<attribute name="Implementation-Title" value="MyApp" />
<attribute name="Implementation-Vendor" value="MyCompany" />
<attribute name="Implementation-Version" value="${version.num}-b${build.number}"/>
</manifest>
I have an old application that use swing-layout and i have to make it usable via java webstart . It runs fine from netbeans but if I launch it using jws I got this error :
exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdesktop/layout/GroupLayout$Group
at Gui.Accueil.jMenuItemConsPHActionPerformed(Accueil.java:2331)
.....
Caused by: java.lang.ClassNotFoundException: org.jdesktop.layout.GroupLayout$Group
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 41 more
I have tried to add swing-layout in the jnlp file but I get this error when I run it :
com.sun.deploy.net.FailedDownloadException: Impossible de charger la ressource : http://my_url:8080/___JWSappclient/___app/test/lib/swing-layout-1.0.4.jar
this the jnlp :
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>test </title>
</information>
<eligible>True</eligible>
<security>
<all-permissions/>
</security>
<resources>
<jar href="./lib/swing-layout-1.0.4.jar"/>
</resources>
</jnlp>
Thanks .
First edit :
I have removed and tried with many path but it's almost the same error com.sun.deploy.net.FailedDownloadException: Impossible de charger la ressource : http://url/___JWSappclient/___app/test/lib/swing-layout-1.0.4.jar
I tried to change swing-layout name to sl.jar but it didn't help .
What I dont understand is why jws try to download the swing-layout.jar from the server ?
The element <eligible> does not appear in the JNLP File Syntax, and your file is malformed as shown. In your previous question on this topic, you mentioned needing to support Java 6. To support Java 5, specify it in <resources>. The JAR containing org.jdesktop.layout.GroupLayout appears correct, but the path is suspicious. Try something like this:
<resources>
<j2se version="1.5+" />
<jar href="lib/swing-layout-1.0.4.jar"/>
</resources>
Addendum: I don't understand why JWS tries to download the swing-layout.jar from the server.
The JNLP client downloads all JARs from the server via HTTP. Each JAR must be accessible using the relative path specified in the href attribute. In particular, the directory containing your application JAR and JNLP file must also have a lib directory containing the layout JAR.
test/
application.jnlp
application.jar
lib/
swing-layout-1.0.4.jar
We're having difficulties getting past the mixed code error for Java webstart. In summary, we have our main JNLP file, we've signed all of our code that it loads directly. We've added the all-permissions option to the main JNLP. The main class it loads also comes from a signed jar.
When the main class kicks off a little down the road it fires off some things that need to load some unsigned resources that are pulled in from JNLP B. None of JNLP B's resources are signed and they do not need any special permissions.
All of the signed code has been setup based on the mixed code documentation from Oracle and the jar files have been set with manifests of "Trusted-Library: true" before signing.
When the unsigned code is attempted to be loaded by the signed code we get a class not found error like so:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/some/external/package/that/is/not/signed
at org.our.signed.package.main(Main.java:87)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.some.external.package.that.is.not.signed
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
Here's the scenario in the JNLP's:
JNLP A: (summarized)
<jnlp spec="1.5+" codebase="...." href="......">
<information>
...etc
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" initial-heap-size="80m" max-heap-size="256m" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="signedJar_1.jar" download="eager" main="true"/>
<jar href="signedJar_2.jar" download="eager" main="false"/>
<extension name="unsigned_ext" href="unsigned.jnlp"/>
</resources>
<application-desc main-class="(FROM SIGNED CLASS in signedJar_1.jar)"/>
</jnlp>
JNLP B (the unsigned.jnlp loader)
<jnlp spec="1.5+" codebase="....." href="......">
<information>
...etc
</information>
<resources>
<jar href="unsigned.jar"/>
</resources>
<component-desc/>
</jnlp>
We have noted that the security exceptions are working correctly, because if we move the unsigned jar into the the JNLP that has all-permissions and has signed jars, we get the expected security exceptions that Java won't let us mix the signed code with Trusted-Library: true and unsigned code with no manifest attributes.
Ideas? Is there a reason the classloader can't find the java files from the unsigned code? Is there something special we are missing to allow signed code to run unsigned code? I've only seen the cases where people have problems getting unsigned code to run signed code, which I can understand.
The trusted-library class loader is a parent (in the sense of class loader delegation) of the (possibly untrusted) applet class loader. Think of it as if it is the boot class loader. So the untrusted classes can link to the trusted-library classes but not vice versa. Without going to the bother of altering manifests and using WebStart you can try this stuff out by adding your trusted class with -Xbootclasspath/a: and your untrusted classes with -classpath (this is how the feature was tried out before it was implemented).
JNLPAppletLauncher is an example of how to have trusted-libraries invoke applet code. The applet class loader can be obtained with Thread.currentThread().getContextClassLoader(), and it's just reflection from there. Writing safe trusted library code is tricky. Remember, you can't trust untrusted code.
I have found MANY threads on packing all dependencies along with the project into one jar package, and it seems like there are many different ways to achieve this (oneJar, FatJar, Ant-build...)
So cooking up my own recipe, I have (after quite some effort) managed to package the project I am working on. In this one jar file, there is the code for the project plus all the jars that the project depends on which are loaded with jar-in-jar-loader that comes with eclipse. The resultant works fine on a number of different platforms, when it's ran through the terminal invoked via java -jar myjarfile.
Peachy, you might say, here's the problem though; when I sign my jar and try to run it via javaws (which is the ultimate goal here) I get an exception which I have decrypted to mean that libraries (in the case below org.apache.commons.lang.SystemUtils) are unaccessible.
So here's my question; is it not possible to load jars in jars when the applications is deployed for Java Web Start? If it is possible, what am I doing wrong? If not, what's the best alternative?
Thanks!
Below is the JNLP file along with the stackTrace I get when I run javaws myJNLPfile
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+"
codebase="file:///home/ukirik/workspace/myproject/dist"
href="project.jnlp">
<information>
<!-- Project info -->
</information>
<security>
<all-permissions />
</security>
<resources os="Mac\ OS\ X">
<j2se version="1.6+" java-vm-args="-XstartOnFirstThread"/>
</resources>
<resources>
<jar href="myjar-jws.jar" />
</resources>
<application-desc main-class="org.gvt.RuntimeMain"/>
</jnlp>
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:1799)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1745)
at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1507)
at com.sun.javaws.Launcher.run(Launcher.java:129)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/SystemUtils
at org.gvt.RuntimeMain.loadSwtJar(RuntimeMain.java:27)
at org.gvt.RuntimeMain.main(RuntimeMain.java:13)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.SystemUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:332)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 11 more
If you are using the Eclipse jar-in-jar loader I think that you may need this in the jnlp file
<application-desc main-class="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
That's assuming that your manifest is looking like this...
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 20.1-b02 (Sun Microsystems Inc.)
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Main-Class: yourapp.mainclass
Rsrc-Class-Path: ./ swt.jar velocity-1.7-dep.jar
Class-Path: .
It seems like the problem is with the classloader.
You may want to use a custom classloader in JWS, as described here:
http://lopica.sourceforge.net/faq.html#customcl
Depending on exactly what you need to do, in terms of packaging, there are a couple of options.
The problem you're running into is that you're passing org.gvt.RuntimeMain as your main class for your jar in your JNPL file, but that's a one-jar jar. Because it's a one-jar jar, you need to provide class com.simontuffs.onejar.Boot instead, as
<application-desc main-class="com.simontuffs.onejar.Boot"/>
The reason for it, is that the one-jar plugin will generate that class, which will make use of a classloader that understands jars within jars, and then invoke your org.gvt.RuntimeMain class (it figures it out through looking at the manifests's One-Jar-Main-Class: header).