Jlink can't put Derby into the runtime? - maven

UPDATE:
Maybe it is better if I rephrase the question: How to tell Jlink to put the java.sql or derby into the runtime?
Meantime I tried it with a 'jlinkVerbose' option in the pom file and as a result I can see this after a 'mvn clean javafx:jlink':
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AdventureGameEngine 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # AdventureGameEngine ---
[INFO] Deleting /home/sysadmin/NetBeansProjects/AdventureGameEngine/target
[INFO]
[INFO] --- javafx-maven-plugin:0.0.3:jlink (default-cli) # AdventureGameEngine ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 45 resources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /home/sysadmin/NetBeansProjects/AdventureGameEngine/target/classes
[INFO] /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java: /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java uses unchecked or unsafe operations.
[INFO] /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java: Recompile with -Xlint:unchecked for details.
com.mycompany.adventuregameengine file:///home/sysadmin/NetBeansProjects/AdventureGameEngine/target/classes/
java.base file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.base.jmod
java.datatransfer file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.datatransfer.jmod
java.desktop file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.desktop.jmod
java.logging file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.logging.jmod
java.prefs file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.prefs.jmod
java.scripting file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.scripting.jmod
java.sql file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.sql.jmod
java.transaction.xa file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.transaction.xa.jmod
java.xml file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.xml.jmod
javafx.base file:///home/sysadmin/.m2/repository/org/openjfx/javafx-base/11/javafx-base-11-linux.jar
javafx.controls file:///home/sysadmin/.m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-linux.jar
javafx.fxml file:///home/sysadmin/.m2/repository/org/openjfx/javafx-fxml/11/javafx-fxml-11-linux.jar
javafx.graphics file:///home/sysadmin/.m2/repository/org/openjfx/javafx-graphics/11/javafx-graphics-11-linux.jar
jdk.unsupported file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/jdk.unsupported.jmod
Providers:
java.desktop provides java.net.ContentHandlerFactory used by java.base
java.base provides java.nio.file.spi.FileSystemProvider used by java.base
java.desktop provides javax.print.PrintServiceLookup used by java.desktop
java.desktop provides javax.print.StreamPrintServiceFactory used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiDeviceProvider used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiFileReader used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiFileWriter used by java.desktop
java.desktop provides javax.sound.midi.spi.SoundbankReader used by java.desktop
java.desktop provides javax.sound.sampled.spi.AudioFileReader used by java.desktop
java.desktop provides javax.sound.sampled.spi.AudioFileWriter used by java.desktop
java.desktop provides javax.sound.sampled.spi.FormatConversionProvider used by java.desktop
java.desktop provides javax.sound.sampled.spi.MixerProvider used by java.desktop
java.logging provides jdk.internal.logger.DefaultLoggerFinder used by java.base
java.desktop provides sun.datatransfer.DesktopDatatransferService used by java.datatransfer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.176 s
[INFO] Finished at: 2020-06-17T11:01:49+02:00
[INFO] Final Memory: 22M/84M
[INFO] ------------------------------------------------------------------------
It still gives the 'BUILD SUCCESS' result and despite it says 'java.sql file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.sql.jmod
', the java.sql is missing from the 'Providers:' section.
END of UPDATE.
I am working on a game in Java11 + JavaFX. The building tool is Maven. The IDE is Netbeans 11.
It is a modular project.
I use this manual: https://openjfx.io/openjfx-docs/#IDE-NetBeans
The game compiles and runs smoothly, it can create/read/update the Derby DB when I start it in Netbeans via maven by 'clean javafx:run'.
When I want to create the runtime from terminal by 'mvn clean javafx:jlink' I get a 'BUILD SUCCESS' result too.
But when I try to start the launcher by 'target/adventuregame/bin/adventuregamelauncher' I get an error message:
Connection error: java.sql.SQLException: No suitable driver found for jdbc:derby:advDB;create=true
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: javafx.fxml.LoadException:
/com.mycompany.adventuregameengine/com/mycompany/adventuregameengine/FXMLDocument.fxml:15
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.AdventureGame.start(AdventureGame.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
Caused by: java.lang.NullPointerException
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.DB.<init>(DB.java:46)
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.FXMLDocumentController.<init>(FXMLDocumentController.java:888)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.lang.Class.newInstance(Class.java:584)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 17 more
Exception running application com.mycompany.adventuregameengine.AdventureGame
I checked the target/adventuregame/lib/classlist file and it seems to me that the problem is that the jdbc / derby classes are not included. It seems to me that the Jlink can not put the jdbc into the runtime, despite that this manual
https://github.com/openjfx/javafx-maven-plugin#javafxjlink-options
writes that 'The plugin includes by default: --module-path, --add-modules and -classpath options.'
Here is my module-info.java file:
module com.mycompany.adventuregameengine {
requires javafx.controls;
requires javafx.fxml;
requires java.sql;
requires java.desktop;
// requires java.naming;
// requires java.management;
opens com.mycompany.adventuregameengine to javafx.fxml; //java.desktop, java.sql
exports com.mycompany.adventuregameengine;
}
Before I posted I've checked the similar topics here on stackoverflow, and one suggested that including java.naming and java.management could help, I tried it but it doesn't.
Here is my pom 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>com.mycompany</groupId>
<artifactId>AdventureGameEngine</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.sql</arg>
</compilerArgs>
<launcher>adventuregamelauncher</launcher>
<jlinkImageName>adventuregame</jlinkImageName>
<mainClass>com.mycompany.adventuregameengine.AdventureGame</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I tried the 'compilerArgs' section, but it did not help.
Here is the section of my DB file what the error message refers to, but it must be OK since it runs properly via Netbeans, the problem is with the runtime.
public class DB {
final String JDBC_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
final String URL = "jdbc:derby:advDB;create=true";
Connection conn = null;
Statement createStatement = null;
DatabaseMetaData dbmd = null;
public DB(){
try {
conn = DriverManager.getConnection(URL);
System.out.println("There is a connection.");
} catch (SQLException ex) {
System.err.println("Connection error: " + ex);
}
if (conn != null){
try {
createStatement = conn.createStatement(); //create a statement (auto)
} catch (SQLException ex) {
System.err.println("Statement error: " + ex);
}
}
//is the database empty, so the program runs first time?
try {
dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTables(null, "APP", "HERO", null); //capital letter!
if(!rs.next()){
createStatement.execute("create table hero(hp INT, score INT, currentRoom INT, vanBackpack boolean)");
createStatement.execute("create table rooms(description varchar(200), eszakra INT, keletre INT, delre INT, nyugatra INT, fel INT, le INT, id INT)");
createStatement.execute("create table items(roomnumber INT, name varchar(30), description varchar(200), felveheto boolean, vizsgal varchar(200), pozX INT, pozY INT)");
}
} catch (SQLException ex) {
System.err.println("ResultSet getTables/create table error: " + ex);
}
}
If I create a simple sample project on the same way as the above manual suggests, then the runtime runs properly. It seems it can not include only the jdbc/derby.
I thank you in advance for every suggestion to solve this really annoying issue.
Zed

Related

Mule SDK Plugin leads to java.lang.NoClassDefFoundError: org/json/JSONObject

I created a plugin on my own that uses a JSON library. The project builds, runs and tests in IntelliJ and on the console.
When I import my plugin to Anypoint Studio I'm getting this error:
ERROR 2021-06-04 06:41:34,587 [[MuleRuntime].uber.01: [p-buchzentrum].get:\delays:p-buchzentrum-config.BLOCKING #2eb68d5] [processor: p-buchzentrum-implementationSub_Flow1/processors/4; event: 23dce8c1-c4ef-11eb-96c7-00e04c682392] org.mule.runtime.core.internal.exception.OnCriticalErrorHandler:
********************************************************************************
Message : java.lang.NoClassDefFoundError: org/json/JSONObject
Element : p-buchzentrum-implementationSub_Flow1/processors/4 # p-buchzentrum:p-buchzentrum-implementation.xml:22 (Write)
Element DSL : <bookit:write doc:name="Write" doc:id="1b4c08ce-1f90-459b-821d-78ad2a4f0f19" payload="#[payload]"></bookit:write>
Error type : MULE:FATAL_JVM_ERROR
FlowStack : at p-buchzentrum-implementationSub_Flow1(p-buchzentrum-implementationSub_Flow1/processors/4 # p-buchzentrum:p-buchzentrum-implementation.xml:22 (Write))
at get:\delays:p-buchzentrum-config(get:\delays:p-buchzentrum-config/processors/0 # p-buchzentrum:p-buchzentrum.xml:130 (Flow Reference))
at p-buchzentrum-main(p-buchzentrum-main/processors/0 # p-buchzentrum:p-buchzentrum.xml:17)
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
ERROR 2021-06-04 06:41:34,597 [[MuleRuntime].uber.01: [p-buchzentrum].get:\delays:p-buchzentrum-config.BLOCKING #2eb68d5] [processor: p-buchzentrum-implementationSub_Flow1/processors/4; event: 23dce8c1-c4ef-11eb-96c7-00e04c682392] org.mule.runtime.core.internal.exception.OnCriticalErrorHandler:
********************************************************************************
Message : java.lang.NoClassDefFoundError: org/json/JSONObject
Element : (None)
Element DSL : (None)
Error type : MULE:FATAL_JVM_ERROR
FlowStack : (None)
Both my plugin and my Anypoint studio project contain the library:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
My Operations class does not expose any methods that take or return any JSONObjects:
public class BookitOperations {
#MediaType(value = ANY, strict = false)
public String read(String payload) {
return FileHandler.read(payload);
}
#MediaType(value = ANY, strict = false)
public String write(String payload) {
return FileHandler.write(payload);
}
}
I tried packing the maven dependency with the assembly-plugin:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
But unpacking the plugin with:
jar xf {my-connector.jar}
Shows that this has not worked.
Any help would be appriciated!
Cheers

"Dependency problems found" when `mvn clean install` a che plugin project

I downloaded the che plugin project example che-ide-server-extension. It works when mvn clean install. But when I add a dependency in
che-ide-server-extension/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
, it fails to install.
The dependency I added is
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-ide-ui</artifactId>
</dependency>
And the error message of mvn clean install -e -X is:
...
[WARNING] Unused declared dependencies found:
[WARNING] org.eclipse.che.core:che-core-ide-ui:jar:6.16.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Plugin ServerService :: Parent pom ................. SUCCESS [ 2.174 s]
[INFO] Plugin ServerService :: Plugins :: Parent ......... SUCCESS [ 0.064 s]
[INFO] Plugin ServerService :: Plugin :: Parent ........... SUCCESS [ 1.382 s]
[INFO] Plugin ServerService :: Plugin :: Server ........... SUCCESS [ 3.827 s]
[INFO] Plugin ServerService :: Plugin :: IDE .............. FAILURE [ 4.870 s]
[INFO] Plugin ServerService :: Che Assembly :: Assembly Parent SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Workspace Agent Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Workspace Agent Tomcat Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: IDE Assembly SKIPPED
[INFO] Plugin ServerService :: Che Assembly :: Assemblies Tomcat SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.925 s
[INFO] Finished at: 2019-07-10T10:48:43+08:00
[INFO] Final Memory: 75M/1321M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.0.1:analyze-only (analyze) on project plugin-serverservice-ide: Dependency problems found -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.0.1:analyze-only (analyze) on project plugin-serverservice-ide: Dependency problems found
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
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:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Dependency problems found
at org.apache.maven.plugins.dependency.analyze.AbstractAnalyzeMojo.execute(AbstractAnalyzeMojo.java:261)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :plugin-serverservice-ide
I don't think I added a wrong dependency. Because when I
import org.eclipse.che.ide.ui.dialogs.DialogFactory;
in my java code, che says
The import org.eclipse.che.ide.ui.dialogs cannot be resolved.
But after I added the dependency, che can recognize it.
I don't know why this happens... The error message says Dependency problems found, but it didn't point out the real problem...
I've just checked and I didn't face any issues you mentioned above.
This my changes for the project:
diff --git a/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml b/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
index 1237c6e..a5eed89 100644
--- a/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
+++ b/plugins/plugin-serverservice/plugin-serverservice-ide/pom.xml
## -28,6 +28,10 ##
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
+<dependency>
+ <groupId>org.eclipse.che.core</groupId>
+ <artifactId>che-core-ide-ui</artifactId>
+</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
diff --git a/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java b/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
index cb1cf58..0def9c2 100644
--- a/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
+++ b/plugins/plugin-serverservice/plugin-serverservice-ide/src/main/java/org/eclipse/che/sample/ide/MyServiceClient.java
## -8,13 +8,15 ##
*/
package org.eclipse.che.sample.ide;
-import javax.inject.Inject;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.rest.AsyncRequestFactory;
import org.eclipse.che.ide.rest.StringUnmarshaller;
+import org.eclipse.che.ide.ui.dialogs.DialogFactory;
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
+import javax.inject.Inject;
+
/**
* Client for consuming the sample server service.
*
## -25,6 +27,7 ## public class MyServiceClient {
private AppContext appContext;
private AsyncRequestFactory asyncRequestFactory;
private LoaderFactory loaderFactory;
+ private DialogFactory dialogFactory;
/**
* Constructor.
## -38,8 +41,10 ## public class MyServiceClient {
public MyServiceClient(
final AppContext appContext,
final AsyncRequestFactory asyncRequestFactory,
- final LoaderFactory loaderFactory) {
+ final LoaderFactory loaderFactory,
+ final DialogFactory dialogFactory) {
+ this.dialogFactory = dialogFactory;
this.appContext = appContext;
this.asyncRequestFactory = asyncRequestFactory;
this.loaderFactory = loaderFactory;
## -52,6 +57,7 ## public class MyServiceClient {
* #return a Promise containing the server response
*/
public Promise<String> getHello(String name) {
+ this.dialogFactory.createChoiceDialog("1", "2", "", "", null, null);
return asyncRequestFactory
.createGetRequest(appContext.getWsAgentServerApiEndpoint() + "/hello/" + name)
.loader(loaderFactory.newLoader("Waiting for hello..."))

ClassNotFoundException running Flyway Migrate task with java callback

I am trying to implement a FlyWay java callback. However, flyway doesn't seem to find my class.
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1
/snip.../
Caused by: java.lang.ClassNotFoundException: ch.x.dp.test1
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
It seems that Flyway cannot find the class.
Here my java class:
package ch.x.dp;
import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;
public class test1 implements Callback {
public test1() {
System.out.println("sldhksjhdkghd");
}
public boolean supports(Event event, Context context) {
return false;
}
public boolean canHandleInTransaction(Event event, Context context) {
return false;
}
public void handle(Event event, Context context) {
}
}
My pom contains the following:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.0.0-beta2</version>
</dependency>
and
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<locations>classpath:ch.x.dp,filesystem:src/main/resources/db/migration</locations>
<callbacks>
<callback>ch.x.dp.test1</callback>
</callbacks>
<snip/>
</plugin>
I have verified that my mvn package calls create a jar in /target that contains my test1 class.
What else could be missing? How can I tell that FlyWay is actually using that jar?

How do you resolve dependencies across all modules in a maven plugin?

I'm writing a Maven plugin that gets the resolved dependencies. It works fine for a single module project/pom, but fails on multiple module projects.
Here's a code snippet
#Mojo(
name="scan",
aggregator = true,
defaultPhase = LifecyclePhase.COMPILE,
threadSafe = true,
requiresDependencyCollection = ResolutionScope.TEST,
requiresDependencyResolution = ResolutionScope.TEST,
requiresOnline = true
)
public class MyMojo extends AbstractMojo {
#Parameter(property = "project", required = true, readonly = true)
private MavenProject project;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
#Override
public void execute() throws MojoExecutionException {
for(MavenProject p : reactorProjects) {
for(Artifact a : p.getArtifacts()) {
...consolidate artifacts
}
}
}
}
The above code will consolidate all the resolved dependencies across all the modules, but it includes some additional ones.
Here's a sample project to work with. Please download this github repo
From the modules-project main folder, please run
mvn dependency:tree -Dverbose -Dincludes=commons-logging
You should see an output like this
[INFO] ------------------------------------------------------------------------
[INFO] Building core 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # core ---
[INFO] com.github:core:jar:0.1-SNAPSHOT
[INFO] \- axis:axis:jar:1.4:compile
[INFO] +- commons-logging:commons-logging:jar:1.0.4:runtime
[INFO] \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] \- (commons-logging:commons-logging:jar:1.0.3:runtime - omitted for conflict with 1.0.4)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building web 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # web ---
[INFO] com.github:web:war:0.1-SNAPSHOT
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] \- com.github:core:jar:0.1-SNAPSHOT:compile
[INFO] \- axis:axis:jar:1.4:compile
[INFO] +- (commons-logging:commons-logging:jar:1.0.4:runtime - omitted for conflict with 1.1.1)
[INFO] \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] \- (commons-logging:commons-logging:jar:1.0.3:runtime - omitted for conflict with 1.1.1)
[INFO] ------------------------------------------------------------------------
Notice that the module/project core depends on commons-logging 1.0.4 and commons-logging 1.0.3, but 1.0.3 is omitted due to a conflict and 1.0.4 is resolved.
This means that if you were to build core on its own, you should only get commons-logging 1.0.4.
Notice that module/project web depends on conflicting versions of commons-logging as well but resolves to 1.1.1.
Now if you were to build the "entire project" (modules-project) with the "mvn package" command, you should see that modules-project/web/target/myweb/WEB-INF/lib contains all the resolved dependencies and it includes ONLY commons-logging 1.1.1.
Here's the problem with the code
In the above code, reactorProjects is instantiated with 3 MavenProject's: modules-project, core, and web.
For modules-project and web, it resolves and returns commons-logging 1.1.1. However, for the core project, it resolves and returns commons-logging 1.0.4.
I want my plugin code to know that commons-logging 1.1.1 is the dependency that the build will produce, and not commons-logging 1.0.4
Any thoughts?
You practically have all it takes in your question. The following plugin will print in the console output the artifacts of the WAR project in the reactor:
#Mojo(name = "foo", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST)
public class MyMojo extends AbstractMojo {
#Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
#Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
public void execute() throws MojoExecutionException, MojoFailureException {
MavenProject packagedProject = getWarProject(reactorProjects);
for (Artifact artifact : packagedProject.getArtifacts()) {
getLog().info(artifact.toString());
}
}
private MavenProject getWarProject(List<MavenProject> list) throws MojoExecutionException {
for (MavenProject project : list) {
if ("war".equals(project.getPackaging())) {
return project;
}
}
throw new MojoExecutionException("No WAR project found in the reactor");
}
}
What this does is that it acquires all the projects in the reactor with the injected parameter reactorProjects. Then, it loops to find which one of those is the "war" by comparing their packaging. When it is found, getArtifacts() will return all the resolved artifacts for that project.
The magic that makes it work is the aggregator = true in the MOJO definition:
Flags this Mojo to run it in a multi module way, i.e. aggregate the build with the set of projects listed as modules.
When added to core POM
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>test-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<goals>
<goal>foo</goal>
</goals>
</execution>
</executions>
</plugin>
and run with your example project, this prints in the console:
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] com.github:core:jar:0.1-SNAPSHOT:compile
[INFO] axis:axis:jar:1.4:compile
[INFO] org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] axis:axis-wsdl4j:jar:1.5.1:runtime
[INFO] commons-discovery:commons-discovery:jar:0.2:runtime
This is good enough. With that, we can go forward and, for example, compare the resolved artifacts by the current project being build and the packaged project. If we add a method
private void printConflictingArtifacts(Set<Artifact> packaged, Set<Artifact> current) {
for (Artifact a1 : current) {
for (Artifact a2 : packaged) {
if (a1.getGroupId().equals(a2.getGroupId()) &&
a1.getArtifactId().equals(a2.getArtifactId()) &&
!a1.getVersion().equals(a2.getVersion())) {
getLog().warn("Conflicting dependency: " + a2 + " will be packaged and found " + a1);
}
}
}
}
called with
printConflictingArtifacts(packagedProject.getArtifacts(), project.getArtifacts());
that compares the current artifacts with the artifacts of the packaged project, and only retain those with the same group/artifact id but different version, we can get in the console output with your example:
[WARNING] Conflicting dependency: commons-logging:commons-logging:jar:1.1.1:compile will be packaged and found commons-logging:commons-logging:jar:1.0.4:runtime
The above assumed that our final packaging module was a WAR module. We could make that more generic and let the user specify which one of the module is the target module (i.e. that will package the real delivery).
For that, we can add a parameter to our MOJO
#Parameter(property = "packagingArtifact")
private String packagingArtifact;
This parameter will be of the form groupId:artifactId and will represent the coordinates of the target module. We can then add a method getPackagingProject whose goal will be to return the MavenProject associated with those coordinates.
The configuration of the plugin inside core would be
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>test-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>test</id>
<phase>compile</phase>
<goals>
<goal>foo</goal>
</goals>
<configuration>
<packagingArtifact>com.github:web</packagingArtifact>
</configuration>
</execution>
</executions>
</plugin>
And the full MOJO would be:
#Mojo(name = "foo", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.COMPILE)
public class MyMojo extends AbstractMojo {
#Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
#Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
#Parameter(property = "reactorProjects", required = true, readonly = true)
private List<MavenProject> reactorProjects;
#Parameter(property = "packagingArtifact")
private String packagingArtifact;
public void execute() throws MojoExecutionException, MojoFailureException {
MavenProject packagedProject = getPackagingProject(reactorProjects, packagingArtifact);
printConflictingArtifacts(packagedProject.getArtifacts(), project.getArtifacts());
}
private void printConflictingArtifacts(Set<Artifact> packaged, Set<Artifact> current) {
for (Artifact a1 : current) {
for (Artifact a2 : packaged) {
if (a1.getGroupId().equals(a2.getGroupId()) && a1.getArtifactId().equals(a2.getArtifactId())
&& !a1.getVersion().equals(a2.getVersion())) {
getLog().warn("Conflicting dependency: " + a2 + " will be packaged and found " + a1);
}
}
}
}
private MavenProject getPackagingProject(List<MavenProject> list, String artifact) throws MojoExecutionException {
if (artifact == null) {
return getWarProject(list);
}
String[] tokens = artifact.split(":");
for (MavenProject project : list) {
if (project.getGroupId().equals(tokens[0]) && project.getArtifactId().equals(tokens[1])) {
return project;
}
}
throw new MojoExecutionException("No " + artifact + " project found in the reactor");
}
private MavenProject getWarProject(List<MavenProject> list) throws MojoExecutionException {
for (MavenProject project : list) {
if ("war".equals(project.getPackaging())) {
return project;
}
}
throw new MojoExecutionException("No WAR project found in the reactor");
}
}
This implements the idea of above: when the user has given a target module, we use it as reference. When this parameter is not present, we default to finding a WAR in the reactor.

Error: The type byte[] cannot be used here. (In Proxy Class of Request Factory)

I have a maven + spring + gwt(2.4.0) project. When I am running mvn gwt:run i get the following error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project star: Compilation failure: Compilation failure:
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\customer\CDocumentProxy.java:[19,8] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\customer\CDocumentProxy.java:[21,25] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\dealer\DealerTargetAgreementProxy.java:[35,36] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\dealer\DealerTargetAgreementProxy.java:[40,15] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\services\dealer\TreeNodeTargetAgreementRequest.java:[29,33] error: Could not find domain method similar to java.util.List<com.base.star.server.dto.dealer.FileTextDTO> getTreeNodeTargetAgreementsList(java.lang.Long)
My CDocumpentProxy.java looks like :
#ProxyFor(value = com.base.star.server.domain.CDocument.class, locator=
com.base.star.server.locators.customer.CDocumentLocator.class)
public interface CDocumentProxy extends EntityProxy {
byte[] getDocument(); //line 19
void setDocument(byte[] document); //line 21
If i build the project with STS 2.9.2 the project builds up. So i think the problem is bad configuration to maven-compiler-plugin.
In my .pom file i have configure maven-compiler-plugin like :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Can't i use byte[] as a return type for a method in a request factory proxy ? I just can't understand the error..
You cannot use arrays in Request Factory: https://developers.google.com/web-toolkit/doc/latest/DevGuideRequestFactory#transportable
That being said, for a byte[] equivalent, I'd rather use a String than a List<Byte>, and GWT emulates String#getBytes for the UTF-8 and ISO-8859-1 charsets.

Resources