OpenJDK cannot find main class in jar while OracleJDK can - javafx

I have the problem, that I cannot run any jars with OpenJDK at all, where as with the normal OracleJDK it is no problem.
OpenJDK # java -version
openjdk version "1.8.0_101"
OpenJDK Runtime Environment (IcedTea 3.1.0) (suse-14.3-x86_64)
OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
when I run a jar with this JDK it can never find the main class even tough it is in the manifest.
OracleJDK # java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
when I launch a jar with this JDK it is no problem.
Do I need to configure something in OpenJDK so it can find the main class from the manifest or what is it that OpenJDK fails to do so?
Edit:
Source file structure:
-- ui
---- Main.java
Gradle build script:
group 'some.group'
version '0.1'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "ui.Main"
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.zeromq', name: 'jeromq', version: '0.3.5'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.12'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest {
attributes 'Implementation-Title': 'PlaceholderTitle',
'Implementation-Version': version,
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': mainClassName
}
}
building with installDist
Manifest:
Manifest-Version: 1.0
Implementation-Title: PlaceholderTitle
Implementation-Version: 0.1
Class-Path: jeromq-0.3.5.jar controlsfx-8.40.12.jar
Main-Class: ui.Main
//new line here

Ok I found the answer. The problem was that I had a JavaFX application and the OpenJDK runtime enviroment that was installed doesn't support that, which I don't understand, since JavaFX is part of the standard in Java 8.
OpenJDK lib/ext folder:
cldrdata.jar nashorn.jar
dnsns.jar sunec.jar
icedtea-sound.jar sunjce_provider.jar
jaccess.jar sunpkcs11.jar
localedata.jar zipfs.jar
meta-index
as you can see if you are familiar with it jfxrt.jar is missing. Which explains why it can't load the Main-Class, since it inherited from javafx.application.Application.

You don't need to configure anything for a jar to start. OracleJDK is mostly the same as OpenJDK, it basically adds a couple of commercial features.
If something weird is happening the best way to proceed is to reproduce the weirdness with the smallest example possible. If you really can't laucnh any jar then Gradle is an overkill to reproduce it. On the other hand, an actual command that you use to start the JVM would be helpful.
Here are the very basic commands that create a jar with a main class and execute it - it should run fine with any JDK and any configuration.
$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime enter code hereEnvironment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
$ echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
$ javac HelloWorld.java
$ jar cfe HelloWorld.jar HelloWorld HelloWorld.class
$ java -jar HelloWorld.jar
Hello, World!

Related

JFrog REST api client app fails to build with missing org.apache.commons.* packages

We have a Java app that was built using 2017 version of JFrog java services jar. Today I am trying to rebuild it using latest jfrog lib. I see that the new services jar doesn't have org.apache.* packages in it.
This is how I built jfrog services jar.
Downloaded 2.8.6 source zip and expanded it
Upgraded gradle to latest and ran "gradle clean build -x test -x javadoc"
Then copied services/build/lib/*services-2.8.6.jar ONLY to my project lib folder
When I try to build, I see so many compilation errors. The old lib was called something like artifactory-java-client-ning-services-1.2.0-all.jar.
How do I build one like it?
Update on 11/6/20 after Dror responses below:
I changed the build strategy to point to jcenter to download and create uber jar with all the dependencies with gradle file like below. I am still running into missing classes.
Below is one of those errors:
error: package org.jfrog.artifactory.client.ArtifactoryClient does not exist
import org.jfrog.artifactory.client.ArtifactoryClient.ProxyConfig;
In Netbeans IDE that I am using, I can expand each package in a jar and see the classes in it. I don't see anything under org.jfrog.artifactory.client package. That is strange.
My build.gradle:
group 'org.jftog.example'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.13
repositories {
jcenter()
}
dependencies {
compile 'org.apache.commons:commons-collections4:4.4'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-services:+'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-api:+'
}
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
Update on Nov 10th 2020:
I found that the artifactory sdk changed and I was using stale classes. I fixed those references in my classes to use newer SDK counterparts and the issues were gone.
I ended up using following gradle file to build everything I needed:
group 'artifactory-client-sdk'
version ''
apply plugin: 'java'
sourceCompatibility = 1.8
buildDir="${rootDir}/../out/artifactory_client_sdk"
def signbridge_lib="${rootDir}/../libs"
jar.baseName = 'artifactory-client-sdk'
repositories {
jcenter()
}
dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.3'
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-services:+'
implementation 'org.jfrog.artifactory.client:artifactory-java-client-api:+'
}
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA','**/org/jfrog/example'
}
task copyJar(type: Copy) {
from jar // copies output of file produced from jar task
into "${signbridge_lib}"
}
build.finalizedBy copyJar
Thanks a lot to Dror for great pointers!
The sources of the Artifactory Java client can be found in the jfrog/artifactory-client-java GitHub repository.
The services module used to be built as an uber jar containing 3rd party dependencies. On Oct 2019 the build has changed to create a thin jar instead of an uber jar.
To solve you issue you can either:
Include the 3rd party dependencies of the service module when building you application
Revert the change in build.gradle and continue to build an uber jar
Instead of building from source, you can consume the artifact from jcenter where is it being published by JFrog. The artifacts are published together with Maven .pom files which contains all the required 3rd party dependencies (all of them are available in jcenter).
In addition, there is an example Github project which shows how to consume the client library using Maven or Gradle.

Using Gluon maven-client-plugin, How do you add Graalvm flags such as --initialize-at-run-time, when running mvn client:compile

Development environment:
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.6, vendor: Oracle Corporation, runtime: /home/linuxlp/opt/graalvm/graalvm-svm-linux-20.1.0-ea+28
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-31-generic", arch: "amd64", family: "unix"
My application uses Reactor Netty for client http rest services. The io.netty libraries are generating INFO errors since some of these classes are getting initialized at build time, but they need to be initialized at runtime. There is a Graalvm flag --initialize-at-run-time that I would like to try, but I don't see how to implement it. I tried to implement it in a config file "initruntime" and put that file in the resources/META-INF/substrate/config directory, but this didn't work. Part of client-debug0.log file is included below showing one of the exceptions:
[Sun May 24 18:38:16 EDT 2020][INFO] [SUB] Error: Class initialization of io.netty.handler.ssl.JettyNpnSslEngine failed. Use the option --initialize-at-run-time=io.netty.handler.ssl.JettyNpnSslEngine to explicitly request delayed initialization of this class.
You can add this command to the list of native-image commands like this:
<nativeImageArgs>
<nativeImageArg>--initialize-at-build-time=com.mycompany.main.internal.NativeImageStaticInitializer</nativeImageArg>
</nativeImageArgs>

Missing 64-bit version of librealmreact.so

Using:
realm 2.22.0
react-native 0.58.5
Attempting to run on Android (6.0) 64-bit Huawei P9 lite
Building with Android Studio
Application crashes immediately with error:
E/SoLoader: Error when loading lib: dlopen failed: "/data/data/com.netballninja/lib-main/librealmreact.so" is 32-bit instead of 64-bit lib .....
Running the application on 32-bit Android simulator is fine.
I have analyzed the APK file and indeed under /libs/arm64-v8a the librealmreact.so does not exist (only under armeabi-v7a). 64-bit support appears to have been back ported into react-native 0.58.4 (originally slated for 0.59).
I have tried removing the inclusion of arm64-v8a support from the APK, (thinking that Android OS would drop back to 32-bit if no 64-bit libs were present) and the application does then run in 32-bit mode on the 64-bit device.
I assume that I do require a librealmreact.so that is 64-bit (precompiled). How do I ensure that my bundling includes that?
you must add this line to app/build.gradle
android {
....
defaultConfig {
....
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
}
This is a known bug of SoLoader.
Fixed in v0.8.0 by this.
As you said, the real reason which causes app crashed is that:
the application does then run in 32-bit mode on the 64-bit device.
SoLoader will follow certain of rules to extract some .so files from .apk file when the application runs first time. In 64-bit device, if the .apk file includes 64-bit .so files, soloader will extract them instead of 32-bit files.
Therefore, you can try to fix this problem by following the steps below:
Make sure that build.gradle of module like this:
...
android {
...
splits {
abi {
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
defaultConfig {
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
}
If step1 can not fix your problem, try to upgrade SoLoader to version 0.8.0:
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.0"
}
}

Ionic3 Execution failed for task ':app:transformClassesWithDexBuilderForDebug'

I have been dealing with this for the past 2 weeks now.I'm building an application with Ionic3. Everything worked fine, Untill I install phonegap push plugin. Then I start to get this error
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > com.android.build.api.transform.TransformException: java.lang.IllegalStateExce ption: Dex archives: setting .DEX extension only for .CLASS files
I have made research about this and none of the solution seemed to work for me. I have done below to app level build.gradle
defaultConfig {
multiDexEnabled true
}
i also added below code
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Then I started gettin below error
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write
[C:\ionic\brinmiz\platforms\android\app\build
\intermediates\multi-dex\debug\componentClasses.jar] (Can't read
[C:\ionic\brinmiz\platforms\android\app\build\intermediates\transforms\desugar\debug\17.jar(;;;;;;**.class)] (Duplicate zip entry [17.jar:android/support/v4/media/RatingCompat$1.class]))
This is my Ionic info
cli packages:
#ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
#ionic/app-scripts : 3.1.8
Cordova Platforms : android 7.0.0 ios 4.5.4
Ionic Framework : ionic-angular 3.9.2
System:
Android SDK Tools : 26.0.2
Node : v6.10.2
npm : 3.10.10
OS : Windows 8
Environment Variables:
ANDROID_HOME : C:\Users\Dd\AppData\Local\Android\sdk
Misc:
backend : legacy
Like I said, I have been on this for the past 2 weeks. I really need your solution
As explained here by the official documentation of Push Plugin, there is a known incompatibility between Push Plugin and another plugins that "are using an outdated way to declare dependencies such as android-support or play-services-gcm".
You can try to install cordova-android-support-gradle-release that will align various versions of the Android Support libraries specified by other plugins to a specific version.
cordova plugin add cordova-android-support-gradle-release --fetch
Also you can try to downgrade your cordova-android from 7.0.0 to 6.3.0 because there are also known issues with 7.x+. Delete your plugin folder(make sure you have all of them declared in config.xml) and run:
cordova platforms rm android
cordova platforms add android#6.3.0
If nothing do the job, update your answer with all the plugins used by your application using the next command and I will try to debug for you.
cordova plugin ls

Springfuse - Failed to execute goal: generate

I try to generate an Eclipse Project with Springfuse code generator, based on a MySql database. I have filled up the form at http://www.springfuse.com/, and it generated following Maven command:
mvn -U archetype:generate -DarchetypeGroupId=com.springfuse.archetypes -DarchetypeArtifactId=quickstart -DarchetypeVersion=3.0.108 -DgroupId=com.company.demo -Dpackage=com.company.demo -DartifactId=myproject -Dversion=1.0.0 -DfrontEnd=jsf2Spring -Demail=peter.varga.sp#gmail.com -Dpassword=none -DjdbcGroupId=mysql -DjdbcArtifactId=mysql-connector-java -DjdbcVersion=5.1.25 -DjdbcDriver=com.mysql.jdbc.Driver -DjdbcUser=root -DjdbcPassword=qwe123 -DjdbcUrl=jdbc:mysql://localhost/test -DinteractiveMode=false -DarchetypeRepository=http://maven2.springfuse.com/
I opened a command window, copied the command as it is, and run it, but got following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project standalone-pom: The desired archetype does not exist (com.springfuse.archetypes:quickstart:3.0.108) -> [Help 1]
My environment details:
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: c:\Prog\Maven\Maven.3.2.1
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: c:\Program Files\Java\jdk1.7.0_51\jre
Default locale: en_US, platform encoding: Cp1250
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Does anybody has an idea, what the problem is?
Thanks.
Please check the settings of proxy / firewall springfuse. Also check the Apache Maven, because it needs to download the dependencies on the Internet. And if it fails, then its usually you need to tell him about the http proxy you need to use.

Resources