Cant compile JavaFX application with jdk11 on Ubuntu - eclipse

I am trying to run a JavaFX application on eclipse. Easy code like printing out hello world or entering a name are working. But when I am trying to run a modified fmxl-file I am getting different errors.
At first I got the message:
Error occurred during initialization of boot layer
java.lang.module.FindException: Two versions of module jurt found in /usr/share/java (jurt-6.0.7.jar and jurt.jar)
But when deleting the versions which are double the errormessage changed
to:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x65d71619) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x65d71619
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at application.Main.start(Main.java:17)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Exception running application application.Main
This is my main class:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
//BorderPane root = new BorderPane();
Parent root = FXMLLoader.load(getClass().getResource("/application/scene1.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
And this my fxml-file:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="300.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.MainController">
<!-- TODO Add Nodes -->
<children>
<Button layoutX="185.0" layoutY="140.0" mnemonicParsing="false" onAction="#generateRandom" text="Münzwurf" />
<Label layoutX="14.0" layoutY="63.0" text="Kopf oder Zahl du hast die Wahl:" />
<TextField layoutX="241.0" layoutY="60.0" prefWidth="200.0" text="Kopf oder Zahl ?" />
</children>
</AnchorPane>
My class controller just create a random number which I want to be printed out.
I imported the libraries with external jars into my project.
I am running this on a ubuntu 18.4 maschine with jdk11, openjfx11 and jre1.8/11
My next step will be to try the code on jdk1.8 with openjfx8
Does anyone have a clue how to fix this ?

Related

ScalaFX #sfxml Annotation Problems

I am writing a Scalafx application using FXML for the views with the scalafxml library. I am having a ton of trouble getting the classes to compile when using the #sfxml annotation on controller classes. When using them, I keep getting NoSuchMethodExceptions on my constructors as if I have no default constructor but this is definitely not the case. I have been studying this so much that I can only conclude that the problem must be with the library itself. I have followed any information on it as best I know how.
The controller is for creating a form for the user. Since the "IllegalArgumentException" will be thrown if I try to set the root node's scene twice, I use the root node's id in my constructor for purposes of avoiding the exception.
Any help is much appreciated. Thanks.
My code:
#sfxml
class ToolbarController(private val rootLayout: BorderPane) {
val parent = calcParent
import javafx.application.Platform
def newForm = {
new JFXPanel()
Platform.runLater(new Runnable() {
override def run() {
val dialogStage = new Stage {
scene = new Scene(parent) {
stylesheets = List(getClass.getResource("/scala/css/form.css").toExternalForm)
}
}
dialogStage.show()
}
})
}
def calcParent: Parent = {
val resource = getClass.getResource("scala/form.fxml")
if(rootLayout.scene == null)
FXMLView(resource, NoDependencyResolver)
else rootLayout.getParent
}
}
The FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane id="rootLayout"maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="FormController">
<center>...
And my stack trace:
Exception in Application start method
Workaround until RT-13281 is implemented: keep toolkit alive
[error] (run-main-0) java.lang.RuntimeException: Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$11/1268584418.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
/Users/patrickslagle/scala/MyApps/PattyCakes/target/scala-2.11/classes/scala/calendar.fxml:7
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at Calendar$.delayedEndpoint$Calendar$1(Calendar.scala:15)
at Calendar$delayedInit$body.apply(Calendar.scala:9)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scala.collection.immutable.List.foreach(List.scala:383)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
at scalafx.application.JFXApp$class.init(JFXApp.scala:297)
at Calendar$.init(Calendar.scala:9)
at scalafx.application.AppHelper.start(AppHelper.scala:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$62/2116169040.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$58/1458556428.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$60/778909025.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$59/1397409682.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.InstantiationException: controller.ToolbarController
at java.lang.Class.newInstance(Class.java:427)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at Calendar$.delayedEndpoint$Calendar$1(Calendar.scala:15)
at Calendar$delayedInit$body.apply(Calendar.scala:9)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scala.collection.immutable.List.foreach(List.scala:383)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
at scalafx.application.JFXApp$class.init(JFXApp.scala:297)
at Calendar$.init(Calendar.scala:9)
at scalafx.application.AppHelper.start(AppHelper.scala:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$62/2116169040.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$58/1458556428.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$60/778909025.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$59/1397409682.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NoSuchMethodException: controller.ToolbarController.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
at Calendar$.delayedEndpoint$Calendar$1(Calendar.scala:15)
at Calendar$delayedInit$body.apply(Calendar.scala:9)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
at scala.collection.immutable.List.foreach(List.scala:383)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
at scalafx.application.JFXApp$class.init(JFXApp.scala:297)
at Calendar$.init(Calendar.scala:9)
at scalafx.application.AppHelper.start(AppHelper.scala:33)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$62/2116169040.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$58/1458556428.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$60/778909025.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$59/1397409682.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
[trace] Stack trace suppressed: run last pattycakes/compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last pattycakes/compile:run for the full output.
[error] (pattycakes/compile:run) Nonzero exit code: 1
[error] Total time: 46 s, completed May 26, 2016 4:18:42 PM
You should not instantiate a class annotated with #fxml directly. This class is modified by the SFXML compiler macro. It is not shown in the code you posted but somewhere you must instantiate ToolbarController to call newForm. Posting Minimal, Complete, and Verifiable example is very important.
Attempting to directly instantiate ToolbarController is the most likely cause of the NoSuchMethodExceptions as ToolbarController constructor is modified by the macro. You need to move methods newForm and calcParent outside of ToolbarController. Only instantiate ToolbarController using FXMLView(resource, ...). You also need to add a reference to ToolbarControllerin the FXML file in the top pane:
<BorderPane ... fx:controller="mypackage.ToolbarController"> ...
With that the FXMLView can instantiate ToolbarController using only reference to the FXML file. For instance, the instantiation could look like this:
import java.io.IOException
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafxml.core.{NoDependencyResolver, FXMLView}
object MyFXMLDemo extends JFXApp {
val resource = getClass.getResource("/scala/css/form.css")
if (resource == null) {
throw new IOException("Cannot load resource: /scala/css/form.css")
}
val root = FXMLView(resource, NoDependencyResolver)
stage = new PrimaryStage() {
scene = new Scene(root)
}
}
Please take look carefully at the example at https://github.com/vigoo/scalafxml-unit-converter-example.

JavaFx8 (+Maven): error when loading the fxml file

I am trying to write a JavaFx8 application using Maven. I wrote a simple application main class and a fxml file (a root fxml file that does nothing).
When I try to load the fxml root file I have the error "Location is not set":
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$53/99550389.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2428)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2403)
at org.aklal.todofx.tasks.App.initRootLayout(App.java:58)
at org.aklal.todofx.tasks.App.start(App.java:31)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$56/1712616138.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/1268447657.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$52/511893999.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$50/1851691492.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$45(GtkApplication.java:126)
at com.sun.glass.ui.gtk.GtkApplication$$Lambda$42/584634336.run(Unknown Source)
... 1 more
Exception running application org.aklal.todofx.tasks.App
I am not new to JavaFx8 and I already had this kind of error but this time I do not find the problem.
My classes are:
App.java
package org.aklal.todofx.tasks;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class App extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
public App() {
System.out.println("TEST");
}
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("TEST App (JavaFx with Maven)");
initRootLayout();
}
public void initRootLayout() {
try {
//to check classpaths
Unused un = new Unused();
System.out.println("TESTAPP\n\t" + this.getClass());
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("view/RootLayout.fxml"));
//loader.setLocation(App.class.getResource("TestRootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
}
RootLayout.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="500.0" prefWidth="1024.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<!-- TODO Add Nodes -->
</BorderPane>
I checked the classpathes printing out the getClass output (Is that the correct way to have classpath?), to do so I wrote an "Unused.java" class in the fxml file package:
package org.aklal.todofx.tasks.view;
public class Unused {
public Unused(){
System.out.println("Unused\n\t" + this.getClass());
}
}
When I run the App, the getClass ouputs are:
Unused
class org.aklal.todofx.tasks.view
Unused APP
class org.aklal.todofx.tasks.App
So in my opinion the path ("view/RootLayout.fxml") I give to loader.setLocation is correct, isn't it?.
I also tried to put the root fxml file (renamed TestRootLayout) in the main class' package, I still have the error.
Can anybody see an error?
Note
I already wrote JavaFx apps but I never used Maven to do it, the purpose of this project is to set a JavaFx8 project with Maven. I think my problem does not come from Maven but I give you the commands I done to set my project, maybe there is something wrong:
I did the command:
mvn archetype:generate -DgroupId=org.aklal -DartifactId=javafx-with-maven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
I modified the pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.aklal</groupId>
<artifactId>javafx-with-maven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javafx-with-maven</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>JavaFXSimpleApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<mainClass>org.aklal.todofx.tasks.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
and then:
mvn eclipse:eclipse
and in Eclipse: Import -> Existing Projects into workspace
fxrt.jar is included in JRE System Library
Update:
To check if the problem has not a more general reason, I wrote the main class with hard coded elements:
public class App extends Application {
public static void main(String args[]) {
launch(args);
}
#Override
public void start(Stage stage) {
Button bouton = new Button("Click");
bouton.setOnAction(e -> System.out.println("Clicked!"));
StackPane root = new StackPane();
root.getChildren().add(bouton);
stage.setScene(new Scene(root));
stage.setWidth(300);
stage.setHeight(300);
stage.setTitle("JavaFx8 with Maven");
stage.show();
}
}
It works, so I guess everything is in order. The question remains: why does the setLocation not work?
Update:
There is definitely a problem with the path to the fxml file. If I change:
FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("view/RootLayout.fxml"));
with:
String pathToFxml = "absolute_path/RootLayout.fxml";
URL fxmlUrl = new File(pathToFxml).toURI().toURL();
loader.setLocation(fxmlUrl);
then it works
for now the jar I created did not have fxml files. I guess I made a
mistake, I will give one more try and let you know
You need to add the FXML file in a sub-directory of src/main/resources not src/main/java
If you call App.class.getResource("view/RootLayout.fxml") then the FXML file has to be in the directory: src/main/resources/mypackage/view where mypackage is the package of the class App.
If you call it with a leading slash: App.class.getResource("/view/RootLayout.fxml") then the FXML file has to be in the directory: src/main/resources/view
Double-check if the FXML-file is at the expected location in the JAR-file.
As Puce said, if you call App.class.getResource("view/RootLayout.fxml") then the FXML file has to be in the directory: src/main/resources/mypackage/view where mypackage is the package of the class App.
So , instead of using App.class
FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("view/RootLayout.fxml"));
Try ClassLoader
FXMLLoader loader = new FXMLLoader();
loader.setLocation(ClassLoader.getSystemResource("view/RootLayout.fxml"));

Spring Rest MultiModule Project has ClassCastException in requestMappingHandlerMapping()

I am facing following issue. I have a multi module project for which I now want to design a Rest-Module for using Spring-Hateoas.
The underlaying modules works as expected. The modules are organized like follows:
app
rest
business
backend
All modules are build by spring-boot in current version 1.1.9.RELEASE.
When I start the Integration-Test as well runable Application class I get the stacktrace you find below. That stacktrace just come when I integrate the business module in application class of rest module.
====
TESTCLASS
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = ApplicationRest.class)
#WebAppConfiguration
#ActiveProfiles("localhost")
public class ApplicationRestTest {
#Test
public void contextLoads() {
}
}
===
CONFIGURATION CLASS OF REST MODULE =>
RUNNING THAT CLASS ONLY WORKS WHEN COMMENTING #IMPORT!!!
#Configuration
#ComponentScan
#EnableAutoConfiguration
#Import(ApplicationBusiness.class) // WORKS WHEN COMMENTING THAT LINE!!!
#PropertySource({ "classpath:/config/application-localhost.properties" })
public class ApplicationRest {
public static void main(final String[] args) {
SpringApplication.run(ApplicationRest.class, args);
}
}
===
CONFIGURATION OF BUSINESS MODULE =>
RUNNING THAT CLASS WORKS!!!
#Configuration
#ComponentScan
#Import(Application.class)
#PropertySource({ "classpath:/config/application-localhost.properties" })
public class ApplicationBusiness {
public static void main(final String[] args) {
SpringApplication.run(ApplicationBusiness.class, args);
}
}
===
CONFIGURATION OF BACKEND MODULE =>
RUNNING THAT CLASS WORKS
#Configuration
#ComponentScan
#EnableAutoConfiguration
#EnableJpaRepositories
#ImportResource("classpath*:META-INF/spring/applicationContext-*.xml")
public class Application {
public static void main(final String[] args) {
final ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
final ContractService service = context.getBean(ContractService.class);
service.countAllContracts();
context.close();
}
}
====
STACKTRACE
CONSOLE OUTPUT OF MODULES BACKEND AND BUSINESS ARE OKAY
....
CONSOLE OUTPUT REST MODULE STARTS HERE ...
2014-11-15 13:39:21.125 INFO 7988 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-11-15 13:39:21.346 WARN 7988 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
2014-11-15 13:20:13.722 ERROR 3472 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#29ae2517] to prepare test instance [at.compax.bbsng.app.rest.ApplicationRestTest#7a78d2aa]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:98)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:161)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:101)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping()] threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy130 cannot be cast to org.springframework.format.support.FormattingConversionService
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:107)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:69)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95)
... 25 common frames omitted
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping()] threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy130 cannot be cast to org.springframework.format.support.FormattingConversionService
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 41 common frames omitted
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy130 cannot be cast to org.springframework.format.support.FormattingConversionService
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$9d0e5a2e.mvcConversionService(<generated>)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.getInterceptors(WebMvcConfigurationSupport.java:230)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping(WebMvcConfigurationSupport.java:197)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$9d0e5a2e.CGLIB$requestMappingHandlerMapping$17(<generated>)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$9d0e5a2e$$FastClassBySpringCGLIB$$c90faea7.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$9d0e5a2e.requestMappingHandlerMapping(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 42 common frames omitted
============
That Issues happens when I add the following dependency to the classpath:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
When removing it, then it does not complain.
===============
Starting in Debug-Mode prints out following classpath dependencies, maybe that helps:
2014-11-15 16:18:48.758 INFO 8896 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/Development/Projekte/bbsng/trunk/app/rest/target/classes/, file:/C:/Development/Projekte/bbsng/trunk/app/business/target/classes/, file:/C:/Development/Projekte/bbsng/trunk/app/backend/target/classes/, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.1.9.RELEASE/spring-boot-starter-data-jpa-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.1.9.RELEASE/spring-boot-starter-aop-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/aspectj/aspectjrt/1.8.4/aspectjrt-1.8.4.jar, file:/C:/Users/hegnerM/.m2/repository/org/aspectj/aspectjweaver/1.8.4/aspectjweaver-1.8.4.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.1.9.RELEASE/spring-boot-starter-jdbc-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-jdbc/4.0.8.RELEASE/spring-jdbc-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/tomcat-jdbc/7.0.56/tomcat-jdbc-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/tomcat-juli/7.0.56/tomcat-juli-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-tx/4.0.8.RELEASE/spring-tx-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-orm/4.0.8.RELEASE/spring-orm-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/data/spring-data-jpa/1.6.4.RELEASE/spring-data-jpa-1.6.4.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/data/spring-data-commons/1.8.4.RELEASE/spring-data-commons-1.8.4.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-aspects/4.0.8.RELEASE/spring-aspects-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/postgresql/postgresql/9.3-1102-jdbc41/postgresql-9.3-1102-jdbc41.jar, file:/C:/Users/hegnerM/.m2/repository/org/hsqldb/hsqldb/2.3.2/hsqldb-2.3.2.jar, file:/C:/Users/hegnerM/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar, file:/C:/Users/hegnerM/.m2/repository/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar, file:/C:/Users/hegnerM/.m2/repository/commons-pool/commons-pool/1.6/commons-pool-1.6.jar, file:/C:/Development/Projekte/bbsng/trunk/app/domain/target/classes/, file:/C:/Users/hegnerM/.m2/repository/org/hibernate/hibernate-entitymanager/4.3.6.Final/hibernate-entitymanager-4.3.6.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/jboss/logging/jboss-logging-annotations/1.2.0.Beta1/jboss-logging-annotations-1.2.0.Beta1.jar, file:/C:/Users/hegnerM/.m2/repository/org/hibernate/hibernate-core/4.3.6.Final/hibernate-core-4.3.6.Final.jar, file:/C:/Users/hegnerM/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar, file:/C:/Users/hegnerM/.m2/repository/org/jboss/jandex/1.1.0.Final/jandex-1.1.0.Final.jar, file:/C:/Users/hegnerM/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar, file:/C:/Users/hegnerM/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar, file:/C:/Users/hegnerM/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.5.Final/hibernate-commons-annotations-4.0.5.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.0.Final/jboss-transaction-api_1.2_spec-1.0.0.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar, file:/C:/Users/hegnerM/.m2/repository/com/mysema/querydsl/querydsl-jpa/3.4.3/querydsl-jpa-3.4.3.jar, file:/C:/Users/hegnerM/.m2/repository/com/mysema/querydsl/querydsl-core/3.4.3/querydsl-core-3.4.3.jar, file:/C:/Users/hegnerM/.m2/repository/com/google/guava/guava/14.0/guava-14.0.jar, file:/C:/Users/hegnerM/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar, file:/C:/Users/hegnerM/.m2/repository/com/mysema/commons/mysema-commons-lang/0.2.4/mysema-commons-lang-0.2.4.jar, file:/C:/Users/hegnerM/.m2/repository/com/infradna/tool/bridge-method-annotation/1.13/bridge-method-annotation-1.13.jar, file:/C:/Development/Projekte/bbsng/trunk/app/log/target/classes/, file:/C:/Users/hegnerM/.m2/repository/org/aspectj/aspectjtools/1.8.4/aspectjtools-1.8.4.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter/1.1.9.RELEASE/spring-boot-starter-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot/1.1.9.RELEASE/spring-boot-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.1.9.RELEASE/spring-boot-autoconfigure-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.1.9.RELEASE/spring-boot-starter-logging-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar, file:/C:/Users/hegnerM/.m2/repository/org/slf4j/jul-to-slf4j/1.7.7/jul-to-slf4j-1.7.7.jar, file:/C:/Users/hegnerM/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.7/log4j-over-slf4j-1.7.7.jar, file:/C:/Users/hegnerM/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar, file:/C:/Users/hegnerM/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar, file:/C:/Users/hegnerM/.m2/repository/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar, file:/C:/Users/hegnerM/.m2/repository/org/projectlombok/lombok/1.14.8/lombok-1.14.8.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/commons/commons-collections4/4.0/commons-collections4-4.0.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar, file:/C:/Users/hegnerM/.m2/repository/joda-time/joda-time/2.3/joda-time-2.3.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/1.1.9.RELEASE/spring-boot-starter-actuator-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-actuator/1.1.9.RELEASE/spring-boot-actuator-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-core/4.0.8.RELEASE/spring-core-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.1.9.RELEASE/spring-boot-starter-web-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.1.9.RELEASE/spring-boot-starter-tomcat-1.1.9.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.56/tomcat-embed-core-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/7.0.56/tomcat-embed-el-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.56/tomcat-embed-logging-juli-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/7.0.56/tomcat-embed-websocket-7.0.56.jar, file:/C:/Users/hegnerM/.m2/repository/org/hibernate/hibernate-validator/5.0.3.Final/hibernate-validator-5.0.3.Final.jar, file:/C:/Users/hegnerM/.m2/repository/org/jboss/logging/jboss-logging/3.1.1.GA/jboss-logging-3.1.1.GA.jar, file:/C:/Users/hegnerM/.m2/repository/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-web/4.0.8.RELEASE/spring-web-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-webmvc/4.0.8.RELEASE/spring-webmvc-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-expression/4.0.8.RELEASE/spring-expression-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/hateoas/spring-hateoas/0.16.0.RELEASE/spring-hateoas-0.16.0.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-aop/4.0.8.RELEASE/spring-aop-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-beans/4.0.8.RELEASE/spring-beans-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/spring-context/4.0.8.RELEASE/spring-context-4.0.8.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.jar, file:/C:/Users/hegnerM/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar, file:/C:/Users/hegnerM/.m2/repository/org/springframework/plugin/spring-plugin-core/1.1.0.RELEASE/spring-plugin-core-1.1.0.RELEASE.jar, file:/C:/Users/hegnerM/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.4/jackson-databind-2.3.4.jar, file:/C:/Users/hegnerM/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.3.4/jackson-annotations-2.3.4.jar, file:/C:/Users/hegnerM/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.3.4/jackson-core-2.3.4.jar, file:/C:/Users/hegnerM/.m2/repository/com/jayway/jsonpath/json-path/0.9.1/json-path-0.9.1.jar, file:/C:/Users/hegnerM/.m2/repository/net/minidev/json-smart/1.2/json-smart-1.2.jar]
Okay I got the problem, but I really don't know why this is a problem or is it a spring bug.
I am using a module for Business-Method Logging, what I have centralized as aspect. This works with the modules backend and business, it just start that exception behavior when I use spring-mvc with spring-boot.
As you seen above my module backend has annotation #ImportResource("classpath*:META-INF/spring/applicationContext-*.xml"), so that spring can find the xml-config file what includes following (mentioned I use that xml-file for years to log service logger without any problems):
<bean id="serviceLogger" class="at.compax.bbsng.app.log.service.ServiceLogger" />
<aop:aspectj-autoproxy>
<aop:include name="serviceLogger" />
</aop:aspectj-autoproxy>
<!-- Trace all service methods -->
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor">
<property name="useDynamicLogger" value="true" />
<property name="hideProxyClassNames" value="true" />
</bean>
<!-- Time-Logger -->
<bean id="performanceMonitorInterceptor"
class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">
<property name="useDynamicLogger" value="true" />
</bean>
<aop:config>
<aop:pointcut id="daoPointcut" expression="execution(* *..*Repository+.*(..))" />
<aop:advisor advice-ref="debugInterceptor" pointcut-ref="daoPointcut" />
</aop:config>
<aop:config>
<aop:pointcut id="servicePointcut" expression="execution(* *..*Service+.*(..))" />
<aop:advisor advice-ref="performanceMonitorInterceptor"
pointcut-ref="servicePointcut" />
</aop:config>
I don't know why spring-boot-mvc has problem with that and why. Does it have problem with annotation for importing xml-files or does it have problems with aspects. But I guess I will find out and I will report.
If someone knows what is the problem, please don't hesiate to post.
=======
As mentioned spring-web-starter seems to have problem when using aspect. But thats really stupid, it always worked when doing multi-module-project without spring-boot. If nobody knows answer on it, I guess it is a spring bug and I will create jira ticket. Ideas are welcome....
I regenerated serialVersionUID after changed of Class properties, and that is works for me.

GWT RCP - SerializationException

Started a new project from scratch, converted to JPA, my persistence provider is EclipseLink, added the necessary libraries (eclipselink.jar, eclipselink.jar, javax.persistence, mysql-connector-java-5.1). Tested the connection, ping ok. Then created a new package New > JPA > Entities from Tables > Selected all Entities and Key generator > Identity.
GestorIpca.java
GestorIpcaService.util.getInstance().getLista(new AsyncCallback<ArrayList<Docente>>() {
#Override
public void onFailure(Throwable caught) {
Window.alert("Erro na Ligacao efectuada");
caught.getStackTrace();
}
#Override
public void onSuccess(ArrayList<Docente> result) {
Window.alert("Ligacao efectuada com sucesso:" + result.size());
}
});
GestorIpcaService
#RemoteServiceRelativePath("greet")
public interface GestorIpcaService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
public static class util{
public static GestorIpcaServiceAsync instance;
public static GestorIpcaServiceAsync getInstance(){
if(instance == null){
instance = GWT.create(GestorIpcaService.class);
}
return instance;
}
}
public ArrayList<Docente> getLista() throws IllegalArgumentException;
}
GestorIpcaServiceAsync
public interface GestorIpcaServiceAsync {
void greetServer(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
void getLista(AsyncCallback<ArrayList<Docente>> callback);
}
GestorIpcaServiceImpl
#SuppressWarnings("serial")
public class GestorIpcaServiceImpl extends RemoteServiceServlet implements
GestorIpcaService {
public ArrayList<Docente> getLista() throws IllegalArgumentException {
//Criamos um EntityManager
EntityManager em = JpaUtil.getEntityManagerFactory().createEntityManager();
//Criamos a consulta
String consulta = "SELECT r from Docente r";
//Executamos a consulta
Query q = em.createQuery(consulta);
ArrayList<Docente> lista = new ArrayList<Docente>(q.getResultList());
return lista;
}
/* public static void main(String args[]){
GestorIpcaServiceImpl serviceImpl = new GestorIpcaServiceImpl();
for (Docente docente : serviceImpl.getLista()){
System.out.println("nome: " + docente.getNome());
}
}
*/
In this file i tried to run as > Java Application and in Console showed me 2 records.
Package com.GestorIpca.factory
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JpaUtil {
private static final EntityManagerFactory emf;
//Método estático
static{
//BLoco try
try
{
//Criação de EntityManagerFactory
emf = Persistence.createEntityManagerFactory("GestorIpca");
}catch (Throwable e){
//Controlar as excepções
System.err.println("A criação de SessionFactory falhou" + e);
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
public static EntityManagerFactory getEntityManagerFactory(){
return emf;
}
}
My persistence.xml was created automatically. Placed inside META-INF
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="GestorIpca">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.GestorIpca.shared.Ano</class>
<class>com.GestorIpca.shared.Categoria</class>
<class>com.GestorIpca.shared.Curso</class>
<class>com.GestorIpca.shared.Disciplina</class>
<class>com.GestorIpca.shared.Disponibilidade</class>
<class>com.GestorIpca.shared.Docente</class>
<class>com.GestorIpca.shared.Sala</class>
<class>com.GestorIpca.shared.Semestre</class>
<class>com.GestorIpca.shared.TipoCurso</class>
<class>com.GestorIpca.shared.Turma</class>
<class>com.GestorIpca.shared.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/timetable"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="k771u3"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
Last step > Run as > Web Application
Error > Could not connect to database and print a stack trace in Eclipse Console
[EL Info]: 2011-05-09 10:03:08.78--ServerSession(8068087)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Info]: 2011-05-09 10:03:09.297--ServerSession(8068087)--file:/C:/Users/Martinho/WorkSpace/GestorIpca/war/WEB-INF/classes/_GestorIpca login successful
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: java.lang.reflect.InvocationTargetException
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:764)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:727)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: 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.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:746)
... 30 more
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'org.eclipse.persistence.indirection.IndirectSet' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = {IndirectSet: not instantiated}
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:45)
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:38)
... 35 more
[ERROR] 500 - POST /gestoripca/greet (127.0.0.1) 57 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Referer: http://127.0.0.1:8888/GestorIpca.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 132
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/gestoripca/
X-GWT-Permutation: HostedMode
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.30 Safari/534.30
Content-Type: text/x-gwt-rpc; charset=UTF-8
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response headers
Content-Type: text/plain
Note: I changed in package com.GestorIpca.shared all my classes generated from tables
public class Ano implements Serializable
to
public class Ano implements IsSerializable
changed also my GestorIpca.gwt.xml and added this lines in end
<extend-configuration-property name="rpc.blacklist" value="com.google.gwt.user.client.ui.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="-.*List"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Map"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.HashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.LinkedHashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.ArrayList"/>
What am i missing?
I depends on how your entities were defined. Maybe there are connections that GWT RPC doesn´t like. in this case i´d suggest create DTO´s or implement RequestFactory
Without knowing what your entities look like I would guess from the exception that the reason is probably how your entities get enhanced by your persistence provider:
What this means for GWT RPC is that by the time the object is ready to be transferred over the wire, it actually isn't the same object that the compiler thought was going to be transferred, so when trying to deserialize, the GWT RPC mechanism no longer knows what the type is and refuses to deserialize it.
Cited from: http://code.google.com/intl/de-DE/webtoolkit/articles/using_gwt_with_hibernate.html
That article also suggests how to create DTOs to solve this problem.
I know this is a very old question, but I ran into this exact issue tonight.
GWT Serialization doesn't seem to like java.util.Set. I almost feel like it was confusing java.util.Set with org.eclipse.persistence.indirection.IndirectSet.
Once I switched Set to ArrayList, the error went away.

Using JUnit with App Engine and Eclipse

I am having trouble setting up JUnit with App Engine in Eclipse. I have JUnit set up correctly, that is, I can run tests that don't involve the datastore or other services. However, when I try to use the datastore in my tests they fail. The code I am trying right now is from the App Engine site (see below):
http://code.google.com/appengine/docs/java/tools/localunittesting.html#Running_Tests
So far I have added the external JAR (using Eclipse) appengine-testing.jar. But when I run the tests I get the exception below. So, I am clearly not understanding the instructions to enable the services from the web page mentioned above. Can someone clear up the steps needed to make the App Engine services available in Eclipse?
java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/dev/LocalDatastoreService
at com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig.tearDown(LocalDatastoreServiceTestConfig.java:138)
at com.google.appengine.tools.development.testing.LocalServiceTestHelper.tearDown(LocalServiceTestHelper.java:254)
at com.cooperconrad.server.MemberTest.tearDown(MemberTest.java:28)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.datastore.dev.LocalDatastoreService
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 java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 25 more
Here is the actual code (pretty much copied from the site):
package com.example;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
public class MemberTest
{
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
#Before
public void setUp() {
helper.setUp();
}
#After
public void tearDown() {
helper.tearDown();
}
// run this test twice to prove we're not leaking any state across tests
private void doTest() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, ds.prepare(new Query("yam")).countEntities());
ds.put(new Entity("yam"));
ds.put(new Entity("yam"));
assertEquals(2, ds.prepare(new Query("yam")).countEntities());
}
#Test
public void testInsert1() {
doTest();
}
#Test
public void testInsert2() {
doTest();
}
#Test
public void foo()
{
assertEquals(4, 2 + 2);
}
}
In Eclipse, have you added all the jars mentioned here? You need a few more jars than just appengine-testing.jar.
However, if your tests or code under test have these dependencies you'll need a few more JARs on your testing classpath: ${SDK_ROOT}/lib/impl/appengine-api.jar, ${SDK_ROOT}/lib/impl/appengine-api-labs.jar, and ${SDK_ROOT}/lib/impl/appengine-api-stubs.jar. These JARs make the runtime APIs and the local implementations of those APIs available to your tests.
Peter's answer is correct: you need these libraries:
appengine-api.jar
appengine-api-labs.jar
appengine-api-stubs.jar
appengine-tools-api.jar
Chances are you already have the first one and only need the last three.
If you're using Maven, you can add these dependencies to pom.xml:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>1.9.60</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.9.60</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>1.9.60</version>
<scope>test</scope>
</dependency>