Why does JavaFX app using OpenJDK+openjfx fail on Ubuntu 16? - java

I have created a very basic JavaFX application
// Viewer.java
package crossjavafx;
public class Viewer {
public static void main(String[] args) {
MainViewer.main(args);
}
}
// MainViewer.java
package crossjavafx;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainViewer extends Application {
#Override
public void start(Stage stage) {
try {
System.out.println("Hello from Viewer");
Group root = new Group();
Scene scene = new Scene(root, 400, 300);
stage.setTitle("Hello");
stage.setScene(scene);
stage.show();
} catch (final Exception e) {
System.exit(1);
}
}
public static void main(String args[]){
launch(args);
}
}
there is also simple pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>crossjavafx</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have built it on Ubuntu 16.04 using mvn and:
./java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
I have also installed openjfx and libopenjfx packages:
libopenjfx-java/xenial,xenial,now 8u60-b27-4 all [installed]
libopenjfx-jni/xenial,now 8u60-b27-4 amd64 [installed,automatic]
openjfx/xenial,now 8u60-b27-4 amd64 [installed]
The application is built successfully, but fails to launch. The process hangs before printing "Hello from Viewer". I start it:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp crossjavafx-0.1.0-SNAPSHOT.jar crossjavafx.Viewer
I do not have problem to start a non-javafx application build in the same way, even when calling its class from the same JAR, so I suppose there is something wrong with my JavaFX installation.
I also tried to build it and run using Java 8 Oracle SDK, with the same result. Is there anything missing in my JavaFX installation that I forgot?
Edit
I have built and attempted to run it using Java 8 Oracle, printing the stacktrace. I got:
Hello from Viewer
Framebuffer object format is unsupported by the video hardware. (GL_FRAMEBUFFER_UNSUPPORTED)(FBO - 820)
Error creating framebuffer object with TexID 1)
[VGL] ERROR: OpenGL error 0x0502
[VGL] ERROR: in readPixels--
[VGL] 475: Could not Read Pixels

I had a similar issue and added the following parameters as VM arguments "-Djavafx.platform=monocle -Dmonocle.platform=X11 -Dembedded=monocle". As I am using eclipse I added it to the Run configuration Run -> Run configuration ...
Run Configurations in eclipse
I found that hint at https://wiki.openjdk.java.net/display/OpenJFX/Building+the+OpenJFX+embedded+stack+for+Linux+desktop

Related

Scala script engine not initialized when starting java -jar file. javax.script.ScriptException: Failed to compile ctx

i am trying to compile scala code in runtime in java programm.
I am using jsr232 api and my code looks like:
ScriptEngineManager manager=new ScriptEngineManager();
Scripted engine = (Scripted) manager.getEngineByName("scala");
engine.compile(sourceCode);
My pom looks like:
<properties>
<scala.version>2.13.10</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
When i am running such code in IDE all is ok and i have no problems (all dependencies jars are in -classpath option)
But after i try to package to jar with copy dependencies (so i have small jar with fat manifest and put all dependencies to lib folder).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>$$$MYCLASS$$$</mainClass>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
and run my application i got null on (Scripted) manager.getEngineByName("scala");
After some research i found that javax.script.ScriptEngineManager contains scala engine factory;
But 'javax.script.ScriptEngineManager#getEngineByName(String)' returns null if something go wrong during method execution(without printstacktrace).
And my problem is on ScriptEngine engine = spi.getScriptEngine();
I manually try to create Scala script engine the same way as manager and Scala.Factory(Engine factory) do this with some debug settings:
if(engine==null) {
log.warn("No scala script engine exists. Try load again");
try {
Settings settings = new Settings();
settings.usejavacp().value_$eq(true);//same as scala code
settings.usemanifestcp().value_$eq(true); //same as scala code
settings.Yreplclassbased().value_$eq(true); //same as scala code
settings.verbose().value_$eq(true); //for more logs
settings.debug().value_$eq(true); //for more logs
Scripted.Factory fact = new Scripted.Factory();
engine= Scripted.apply(fact,settings, ReplReporterImpl.defaultOut());
}catch (Exception e){
log.error("Scala compiler wasn't initialized",e);
return;
}
}
I got next errors.
Top level error is:
javax.script.ScriptException: Failed to compile ctx
at scala.tools.nsc.interpreter.shell.Scripted.<init>(Scripted.scala:89) ~[scala-compiler-2.13.10.jar:?]
at scala.tools.nsc.interpreter.shell.Scripted$.apply(Scripted.scala:278) ~[scala-compiler-2.13.10.jar:?]
at scala.tools.nsc.interpreter.shell.Scripted.apply(Scripted.scala) ~[scala-compiler-2.13.10.jar:?]
and some other errors from compiler:
java.lang.NullPointerException
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:180)
at scala.reflect.io.ManifestResources$$anon$3.close(ZipArchive.scala:434)
at scala.tools.nsc.symtab.classfile.ReusableDataReader.reset(ReusableDataReader.scala:85)
......
java.io.IOException: class file 'file:..../target/lib/scala-library-2.13.10.jar(scala/Predef.class)' is broken
(class java.lang.NullPointerException/null)
at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$handleError(ClassfileParser.scala:126)
at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$parseErrorHandler$1.applyOrElse(ClassfileParser.scala:134)
at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$parseErrorHandler$1.applyOrElse(ClassfileParser.scala:132)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
......
java.lang.NullPointerException
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:180)
at scala.reflect.io.ManifestResources$$anon$3.close(ZipArchive.scala:434)
at scala.tools.nsc.symtab.classfile.ReusableDataReader.reset(ReusableDataReader.scala:85)
at scala.tools.nsc.symtab.classfile.ClassfileParser.$anonfun$parse$2(ClassfileParser.scala:161)
......
java.io.IOException: class file 'file:..../target/lib/scala-library-2.13.10.jar(scala/Unit.class)' is broken
(class java.lang.NullPointerException/null)
at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$handleError(ClassfileParser.scala:126)
at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$parseErrorHandler$1.applyOrElse(ClassfileParser.scala:134)
at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$parseErrorHandler$1.applyOrElse(ClassfileParser.scala:132)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:144)
It looks like scala compiler for some reason can not read jar source files.
Java version:
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Updated after Dmytro answer
It helps. Thanks alot.
But still got 1 issue with runtime classloading. I want user be able to add new dependency jar runtime.
On first version i do it like: engine.intp().addUrlsToClassPath(new ArraySeq.ofRef<>(url)). And it works well(i mean well when run inside IDEA)
Now i try do it like:
private final ScalaCompilerClassLoader urlClassLoader = new ScalaCompilerClassLoader(new URL[]{},ClassLoader.getSystemClassLoader());
private static class ScalaCompilerClassLoader extends URLClassLoader {
public ScalaCompilerClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
public void add(URL url){
super.addURL(url);
}
}
and i use your code with my classLoader.
JavaUniverse.JavaMirror mirror = universe.runtimeMirror(urlClassLoader);
The issue is that i can add new jar to my urlClassLoader before first call to toolBox.eval(toolBox.parse(sourceCode)).
After first toolBox.eval call newly injected dependencies are not recognized by compiler.
And now i have to create new toolBox after each new jar dependency injecting.
Could you try to replace
ScriptEngineManager manager=new ScriptEngineManager();
Scripted engine = (Scripted) manager.getEngineByName("scala");
engine.compile(sourceCode);
with
import scala.reflect.api.JavaUniverse;
import scala.tools.reflect.ToolBox;
// ...
scala.reflect.runtime.package$ runtime = scala.reflect.runtime.package$.MODULE$;
JavaUniverse universe = runtime.universe();
JavaUniverse.JavaMirror mirror = universe.runtimeMirror(this.getClass().getClassLoader());
scala.tools.reflect.package$ toolsReflect = scala.tools.reflect.package$.MODULE$;
ToolBox<?> toolBox = toolsReflect.ToolBox(mirror).mkToolBox(toolsReflect.mkSilentFrontEnd(), "");
int res = (int) toolBox.eval(toolBox.parse("1 + 1")); // 2
?
Does this change anything for you?
Using scala macro from java
How can I run generated code during script runtime?
How to compile and execute scala code at run-time in Scala3?
"eval" in Scala
Regarding your original code with JSR232 scripting. Could you check whether anything changes if you add fork := true (sbt syntax) to the build file? I guess in Maven this should be <fork>true</fork>.
Regarding your question with classloading. One option is to use protected method addURL
ClassLoader classLoader = this.getClass().getClassLoader();
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addUrlMethod.setAccessible(true);
String url = "file:///home/dmitin/.cache/coursier/v1/https/repo1.maven.org/maven2/com/chuusai/shapeless_2.13/2.3.10/shapeless_2.13-2.3.10.jar";
addUrlMethod.invoke(urlClassLoader, new URL(url));
Object res = toolBox.eval(toolBox.parse("import shapeless._; 1 :: \"a\" :: HNil"));
// 1 :: a :: HNil
Another is to create a child class loader, new runtime mirror and toolbox
ClassLoader classLoader1 = new URLClassLoader(new URL[]{new URL(url)}, classLoader);
JavaUniverse.JavaMirror mirror1 = universe.runtimeMirror(classLoader1);
ToolBox<?> toolBox1 = toolsReflect.ToolBox(mirror1).mkToolBox(toolsReflect.mkSilentFrontEnd(), "");
Object res = toolBox1.eval(toolBox1.parse("import shapeless._; 1 :: \"a\" :: HNil"));
// 1 :: a :: HNil

How do I include src/test/java files to run TestNG tests?

I'm just learning Java and could use your help. I'm using Eclipse, and created a Maven project using the org.openjfx archetype. Everything seems to work fine except when I try to write tests in src/test/java, which causes an error.
An error occurred while instantiating class
starcraft.warcraft.test.TestClass: Unable to make public
starcraft.warcraft.test.TestClass() accessible: module
starcraft.warcraft does not "exports starcraft.warcraft.test" to
module org.testng
This is how I created the project with default settings in Eclipse:
Project Setup with Maven Archetype Selection
Now, when Eclipse creates the project, it doesn't have a src/test/java folder, so I create that manually. Then I create a class called "TestClass" inside a package "starcraft.warcraft.test" inside src/test/java, and I add a simple method to test inside the App class called "adder". You can see the project structure
Project Structure
package starcraft.warcraft;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class App extends Application {
#Override
public void start(Stage stage) {
var javaVersion = SystemInfo.javaVersion();
var javafxVersion = SystemInfo.javafxVersion();
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
var scene = new Scene(new StackPane(label), 640, 480);
stage.setScene(scene);
stage.show();
}
// WILL TEST THIS METHOD
public static int adder(int digit1, int digit2) {
return digit1 + digit2;
}
public static void main(String[] args) {
launch();
}
}
Now I want to use TestNG for the tests, and so I include it in my POM which is
<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>starcraft</groupId>
<artifactId>warcraft</artifactId>
<version>0.0.1-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>13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</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.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>starcraft.warcraft.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This is the default POM created by the Maven archetype except for the TestNG dependency I added. When I try to use TestNG, Eclipse makes me add it to the module path like so:
Maven saying I need to add the TestNG library
And here is my module-info:
module starcraft.warcraft {
requires javafx.controls;
requires org.testng;
exports starcraft.warcraft;
}
OK, all good so far, but now when I try to run my test inside TestClass:
package starcraft.warcraft.test;
import org.testng.annotations.Test;
import starcraft.warcraft.App;
public class TestClass {
#Test
public void testAdder() {
int sum = App.adder(1, 2);
System.out.println(sum);
}
}
I get the error, which again is
An error occurred while instantiating class
starcraft.warcraft.test.TestClass: Unable to make public
starcraft.warcraft.test.TestClass() accessible: module
starcraft.warcraft does not "exports starcraft.warcraft.test" to
module org.testng
I can't figure out how to do the export. When I try making the entry in module-info, it doesn't give me the option of adding the package in src/test/java, the only packages it allows me to choose from are in src/main/java.
I don't understand modules well. How can I get the program to let me run tests from src/test/java?
Thanks everyone who looked at this. I solved it by following these steps:
Delete module-info.java. This turns it into a nonmodular project which is fine for me. I hesitated to do this because the Maven JavaFX archetype included it, but as it says here somewhere
https://openjfx.io/openjfx-docs/#IDE-Eclipse
you can just delete it after its created.
The problem then if you try to run the project is it will give you a warning that JavaFX isn't included as a module. It will still run, but its best to get rid of this incase of problems down the road. So you need to download the JavaFX libraries, place them in your hard drive, and then include them in your project via VM arguments in Eclipse:
right click project -> Run configuration -> Arguments tab -> add in the VM arguments area something like:
--module-path [fully qualified path to lib folder containing downloaded JavaFX] --add-modules javafx.controls
path would be like "C:\javafx\lib" or wherever you placed the downloaded JavaFX.
Then it should run, and project will still build using Maven, but I'm not sure if its using the JavaFX which is still in the Maven POM or the one I specified on the C drive. But it works. Any help on whats happening there would be appreciated. Thanks

Unable to run "Hello World" Java client of Elastic-Search

I am unable to run a very basic program of creating a "Hello World" java client of Elastic-Search.
The documentation is extremely terse about what to do in such cases.
Here is my code:
find . -type f
./pom.xml
./src/main/java/examples/EsRoutingNodeClient.java
Both files are shown below.
Java file containing the code:
package examples;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeBuilder;
public class EsRoutingNodeClient
{
private static final String ZEN_DISCOVERY_UNICAST_HOSTS = "[\"10.10.10.10:9200\"]"; // Used an actual ES master node's IP here
private static final String ES_PATH_HOME = "/Users/appuser/work/software/elasticsearch/dummy-path-home/";
private static final String ES_CLUSTER_NAME = "my-cluster";
private Client client;
private void createEsClient ()
{
Settings settings = Settings.settingsBuilder()
.put("http.enabled", false)
.put("discovery.zen.ping.multicast.enabled", false)
.put("discovery.zen.ping.unicast.hosts", ZEN_DISCOVERY_UNICAST_HOSTS)
.put("discovery.zen.minimum_master_nodes", 1)
.put("path.home", ES_PATH_HOME)
.build();
client =
NodeBuilder.nodeBuilder()
.settings(settings)
.clusterName(ES_CLUSTER_NAME)
.data(false)
.client(true)
.node().client();
}
public EsRoutingNodeClient ()
{
createEsClient();
}
public static void main (String args[])
{
new EsRoutingNodeClient();
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?><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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>examples</groupId>
<artifactId>es-node-client</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>es-node-client</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration />
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.slf4j:*</exclude>
<exlcude>com.esotericsoftware.kryo:kryo:*</exlcude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>examples.EsRoutingNodeClient</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Finally I run it as follows:
mvn clean package
java -jar target/es-node-client-0.0.3-SNAPSHOT.jar
And the exception I get is:
194) Error injecting constructor, java.lang.IllegalStateException: This is a proxy used to support circular references involving constructors. The object we're proxying is not constructed yet. Please wait until after injection has completed to use this object.
at org.elasticsearch.node.service.NodeService.<init>(Unknown Source)
while locating org.elasticsearch.node.service.NodeService
for parameter 5 at org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction.<init>(Unknown Source)
while locating org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction
for parameter 2 at org.elasticsearch.cluster.InternalClusterInfoService.<init>(Unknown Source)
while locating org.elasticsearch.cluster.InternalClusterInfoService
while locating org.elasticsearch.cluster.ClusterInfoService
for parameter 3 at org.elasticsearch.cluster.routing.allocation.AllocationService.<init>(Unknown Source)
while locating org.elasticsearch.cluster.routing.allocation.AllocationService
for parameter 3 at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService.<init>(Unknown Source)
while locating org.elasticsearch.cluster.metadata.MetaDataCreateIndexService
for parameter 5 at org.elasticsearch.snapshots.RestoreService.<init>(Unknown Source)
while locating org.elasticsearch.snapshots.RestoreService
Caused by: java.lang.IllegalStateException: This is a proxy used to support circular references involving constructors. The object we're proxying is not constructed yet. Please wait until after injection has completed to use this object.
at org.elasticsearch.common.inject.internal.ConstructionContext$DelegatingInvocationHandler.invoke(ConstructionContext.java:103)
at com.sun.proxy.$Proxy11.setNodeService(Unknown Source)
at org.elasticsearch.node.service.NodeService.<init>(NodeService.java:77)
at sun.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:50)
at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86)
at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104)
at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:47)
at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:887)
at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:43)
at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:59)
at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46)
at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
... more such lines
at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46)
at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:201)
at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193)
at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:880)
at org.elasticsearch.common.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:193)
at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:175)
at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:46)
at org.elasticsearch.node.Node.<init>(Node.java:200)
at org.elasticsearch.node.Node.<init>(Node.java:128)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:152)
at examples.EsRoutingNodeClient.createEsClient(EsRoutingNodeClient.java:30)
at examples.EsRoutingNodeClient.<init>(EsRoutingNodeClient.java:46)
at examples.EsRoutingNodeClient.main(EsRoutingNodeClient.java:51)
194 errors
at org.elasticsearch.common.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:360)
at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:178)
at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:46)
at org.elasticsearch.node.Node.<init>(Node.java:200)
at org.elasticsearch.node.Node.<init>(Node.java:128)
at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:145)
at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:152)
at examples.EsRoutingNodeClient.createEsClient(EsRoutingNodeClient.java:30)
at examples.EsRoutingNodeClient.<init>(EsRoutingNodeClient.java:46)
at examples.EsRoutingNodeClient.main(EsRoutingNodeClient.java:51)
My ultimate aim is to use a routing node client in storm.
Any help would be very much appreciated.
Thanks!
While upgrading from 1.4 to 2.4 I ran into this same issue. I'm not 100% why, but for me it was something to due with specifying the unicast host. I'm running ES via the zip download with the defaults.
At first I had set the ports for Client Node (ie, the app i'm working on) to be outside the default range thinking I need to do this to avoid conflicts running 2 nodes on the same box. When I did this my client could never find the master. Turns out that the zen discovery only pings 5 local ports in its own range. Before I figured this out (by reading https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java) I added in a unicast.host to get the same issue you are having. After removing both settings my app is now connecting to my ES server.
here's my config
cluster.name=elasticsearch
node.name=local-dev
node.master=false
node.data=false
path.home=${project.build.directory}/es
path.data=${project.build.directory}/es/data
path.logs=${project.build.directory}/es/logs
network.host=127.0.0.1
discovery.zen.minimum_master_nodes=1
code
#Bean
public Node elasticSearchNode() throws Exception {
Settings settings = Settings.settingsBuilder().put(getProps()).build();
return nodeBuilder()
.settings(settings)
.client(true)
.node();
}
#Bean
public Client elasticSearchClient(Node node) throws Exception {
return node.client();
}
private Properties getProps() {
try {
String profile = getProfile();
log.info("Loading ES properties for env: {}", profile);
ClassPathResource resource = new ClassPathResource("es/es."+profile+".properties");
return PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) {
log.error("Can not read property file");
throw new RuntimeException(e);
}
}
private String getProfile() {
return System.getProperty("env", "local");
}

Running a jade program without a main class

I have a simple maven project with the Code below.
import jade.core.Agent;
public class HelloAgent extends Agent
{
protected void setup()
{
System.out.println(getLocalName());
}
}
How do I run this program?. When i right click to run it, I dont see a run as Java Application.
I am following the tutorial here
http://www.iro.umontreal.ca/~vaucher/Agents/Jade/primer2.html
% javac HelloAgent.java
% java jade.Boot fred:HelloAgent
Output
fred
You need to set maven up to have a run task that executes jade.Boot. You have a few different ways to do this. Here is a complete example for Jade using 'profiles'.
For your example above, it would look somewhat like:
<profile>
<id>jade-fred</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<mainClass>jade.Boot</mainClass>
<arguments>
<argument>fred:HelloAgent</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
and would be executed with:
mvn -Pjade-fred exec:java
You should add main method like this:
public class HelloAgent extends Agent
{
public static void main (String[] args)
{
HelloAgent helloAgent = new HelloAgent();
helloAgent.setup();
}
protected void setup()
{
System.out.println(getLocalName());
}
}
To run class java as Java Application you needs a method with main like above.

Maven error with Java 8

Getting an error with Maven and Java 8 (jdk1.8.0_45). This issue does not occur with Java 7.
MCVE
Create a sample maven project. For example:
mvn archetype:create -DgroupId=testinovke -DartifactId=testinvoke
Create the following content in the generated App.java file
package testinovke;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public class App {
public static MethodHandles.Lookup lookup;
public static class Check {
public void primitive(final int i){
}
public void wrapper(final Integer i){
}
}
public static void main(String[] args) throws Throwable {
Check check = new Check();
MethodType type = MethodType.methodType(void.class, int.class);
MethodHandle mh = lookup.findVirtual(Check.class, "primitive", type);
mh.invoke();
}
}
Compile the maven project:
mvn clean compile
Output
Get the following error:
testinvoke/src/main/java/testinovke/App.java:[25,18] method invoked with incorrect number of arguments; expected 0, found 1
Tried it with both Maven 3.0.4 and 3.3.3.
This issue does not exist if I directly compile against App.java using Javac command.
Add plugin configuration for the compiler:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Another solution is adding these properties:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
to your pom.xml, and the plugins will pick these up automatically.

Categories

Resources