I need to compile a GWT project from Java App.
So i created a Compiler instance with CompilerOptions which sets output directories etc.
My code is like this:
Compiler compiler=new Compiler(new CompilerOptions() {......
....
}
ModuleDef def=new ModuleDef("sampleweb");
def.clear();
def.addSourcePackage("D:\\projects\\sampleweb\\src\\com\\sample\\web", new String[]{"client"}, new String[]{}, new String[]{}, true, false);
def.addGwtXmlFile(new File("D:\\projects\\sampleweb\\src\\com\\sampleweb\\web\\Sampleweb.gwt.xml"));
TreeLogger logger=new SwingTreeLogger(new SwingLoggerPanel(Type.ALL, new File("x.txt")));
compiler.run(logger,def);
When the compiler.run is called, a NullPointerException as shown is thrown
Exception in thread "main" java.lang.NullPointerException
at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:373)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:246)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
at com.google.gwt.dev.Compiler.run(Compiler.java:232)
at com.asklepian.TestApp.Starter.main(Starter.java:400)
How should I configure compiler?
I would create just the Java source code and the XML module code, and than execute a Java process who calls the GWT compiler. The GWT compiler is located at com.google.gwt.dev.Compiler, and you can execute it in Windows from the DOS command shell with the java command. The only parameter the compiler needs is the GWT module Location (the location of the module xml file).
Related
I've used Java 8 to create JavaFX venture in which I utilized webview for HTML substance and it is JavaFX expert task. When I try to move to OpenJDK 12 from Java 8 it stops working. What's more, it returns the underneath blunder:
Exception in thread "JavaFX Application Thread"
java.lang.IllegalAccessError: superclass access check failed: class
com.sun.javafx.sg.prism.web.NGWebView (in unnamed module #0x2145b572)
cannot access class com.sun.javafx.sg.prism.NGGroup (in module
javafx.graphics) because module javafx.graphics does not export
com.sun.javafx.sg.prism to unnamed module #0x2145b572
Use this to VM arguments to load all libraries and it will work.
-Djava.library.path=ext\windows64 --module-path "C:\Program Files\Java\javafx-sdk-12.0.1\lib" --add-modules javafx.controls,javafx.fxml,javafx.web,javafx.graphics,javafx.media
I am trying to do a basic scala HelloWorld in Eclipse 2019 and I am getting an error.
The following is my code and the error it is producing. Can someone please help me address this error in eclipse? Thanks
package hello
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError:
scala/Predef$
at HelloWorld/hello.HelloWorld$.main(HelloWorld.scala:5)
at HelloWorld/hello.HelloWorld.main(HelloWorld.scala)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
Scala library is already in source path
There are two required places to set your class-path:
Build/compilation time class-path: (i) Right-click on your project, (ii) Buildpath > Configure BuildPath, (iii) Add Library (or jar), (iv) Select the Scala Library. This one you already have as supported by your screenshot.
Run-time compilation class-path: This needs to be explicitly set in the Run-time configuration to also include the scala library: (i) Run configurations..., (ii) Classpath, (iii) Add Jar and use the scala-library jar. For this option, I have not tested whether User vs Bootstrap matters. Furthermore, I was unable to use the Add Library here, only Add jar results in a functioning run within Eclipse.
The second option is the likely cause of the error you are getting.
You need to add Scala library to your classpath.
From Eclipse:
Right-click on your project
Configure Buildpath
Add Library
Select the Scala Library
I've written a simple Scala application that I'd like to distribute in the form of a standalone, executable jar to servers without the Scala runtime. Everything works fine when invoked through SBT run, but not java -jar.
When I run the jar through java, I get the following unhandled exception:
Exception in thread "main" java.lang.AbstractMethodError: java.util.logging.Handler.publish(Ljava/util/logging/LogRecord;)V
at java.util.logging.Logger.log(Logger.java:458)
at net.lag.logging.Logger.log(Logger.scala:108)
at net.lag.logging.Logger.log(Logger.scala:91)
at net.lag.logging.Logger.info(Logger.scala:121)
at com.rentawebgeek.sitewiki.SiteWiki$.main(SiteWiki.scala:29)
at com.rentawebgeek.sitewiki.SiteWiki.main(SiteWiki.scala)
Exception in thread "Thread-0" java.lang.AbstractMethodError: java.util.logging.Handler.close()V
at java.util.logging.LogManager.resetLogger(LogManager.java:682)
at java.util.logging.LogManager.reset(LogManager.java:665)
at java.util.logging.LogManager$Cleaner.run(LogManager.java:223)
I'm using Configgy and it's Logger, and, per the javadocs for AbstractMethodError, thought it might be related to Scala/SBT using a different Java version than what I'm invoking from my shell. However, java -version and $JAVA_HOME/bin/java -version (what /usr/local/bin/scala uses) both match up as 1.6.0_22.
My ProGuard options are:
//program entry point
override def mainClass: Option[String] = Some("com.rentawebgeek.sitewiki.SiteWiki")
//proguard
override def proguardOptions = List(
"-keepclasseswithmembers public class * { public static void main(java.lang.String[]); }",
"-dontoptimize",
"-dontobfuscate",
"-keep class *",
proguardKeepLimitedSerializability,
proguardKeepAllScala,
"-keep interface scala.ScalaObject"
)
override def proguardInJars = Path.fromFile(scalaLibraryJar) +++ super.proguardInJars
How can I resolve this error? Or find another way to build an executable jar from an SBT project for a Scala-less deployment?
Check out what call you are making at line 29 in SiteWiki.scala; that is the offending call. You're probably calling a trait/class there with an abstract method. Most probably the method that should implement the abstract method is ripped away by proguard (or there the Scala override doesn't match up (I've seen that happen)).
If the line is long to find the offending call; try to decompose over multiple lines.
The latest ProGuard releases contain a sample configuration for processing a Scala application plus the Scala runtime:
http://proguard.sourceforge.net/manual/examples.html#scala
If that doesn't work, the output of -printconfiguration and the console output might help finding the root cause.
A program of mine (written in Scala 2.8) works fine when launched by means of NetBeans IDE. But when I try to run it from outside, with "java- jar", it says "Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject...". Putting all the libraries, incl. Scala runtime inside the same dir as the jar to be run doesn't help. If i try to run the jar with scala itself, it complains that it can't decode it as utf-8 (it expects a scala source rather than a jar, I suppose). So how do I run a Scala application at all?
UPDATE: For those who come here later having the same question I'd recommend to read comments under barjak's answer (including those latest ones hidden), the answer is there. VonC also gives some interesting links on the subject.
The -jar and -classpath of the java command are mutually exclusive : you can't do java -jar YourScalaProg.jar -classpath scala-library.jar
If you want to run your application with java -jar, then the full classpath must be specified in the Class-Path section of the jar's manifest.
You can run your application using only -classpath, like that : java -classpath YourScalaProg.jar:scala-library.jar your.package.MainClass.
Are you using scala-library.jar as described in Adventures with Scala blog post?
java -classpath scala-library.jar:. YourClass
or:
java -classpath scala-library.jar:yourApp.jar YourClass
Where YourClass is was your scalac compiled Scala code.
You will find the same scala-library.jar used in the SO question "Creating a jar file from a Scala file" (or in the blog post "the not so elegant way of creating an executable jar from scala code").
I just added "-Djava.library.path=" to the "VM Arguments" under Run Configuration in Eclipse and everything works fine until I tried to add an external JAR file. I get the following error:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
Am I not setting something properly in Eclipse?
If your interested I forked RXTXserial a while back since thier update "schedule" sucks. I have just ported it over to the Android platform too. We decided to move the native libs into the jar and use reflection to deploy them. The API is the same as RXTX, but everything just works. You can find jars and full project sources at:
http://code.google.com/p/nrjavaserial/
The exception indicates that the class gnu.io.RXTXCommDriver tries to load a native library, which would be named rxtxSerial.dll on Windows and rxtxSerial.so on Linux, and the JVM cannot find it in the directories listed in java.library.path. Have you tried to add a JAR containing the library to java.library.path? I don't think that's possible, it has to be a directory containing the extracted library file.
Appearently that external library has a dependancy with another class gnu.io.RXTXCommDriver
. Perhaps you will need to add that library to class path.