I am using the Gradle Application Plugin to distribute a Java Application for Windows and Ubuntu / Linux / Mac etc.
I tested this on Linux some weeks ago and it worked perfectly. Today my Main class is not found on my Linux machines. I can't think any changes I have made to the Gradle part, except for updating from Gradle 2.0 to 2.12. I didn't test every change on Linux because I usually work on Windows.
The batch script for Windows works flawless, it does not pop any error message. On Linux I get the classic message:
Could not find or load main class...
Are you aware of anything that could cause this error on Linux but not on Windows? I think Gradle should build both scripts exactly the same and I don't need to set up anything special to make it work on Linux. If I remember correctly I haven't changed anything since Updating Gradle, and it was working on Linux just fine.
// I even changed it back to the old syntax.
//plugins {
// id 'java' // or 'groovy' Must be explicitly applied
// id 'application'
//}
apply plugin: 'java'
apply plugin: 'application'
repositories {
mavenCentral()
}
mainClassName = "controllers.Main"
If you need more infos dont hesitate to ask me.
EDIT
And I updated to IntelliJ 2016 (from the last years version). I don't know if this is important, but I think they did quite some changes with Gradle.
EDIT 2
Just tested this on OSX, and works flawless. The problem is just with Ubuntu and Raspbian.
After spending hours trying different things, I finally found out what the problem is.
Ubuntu (and Raspbian) use OpenJDK per default. The development for my application was done on Oracle Java 8.
After installing the Oracle JDK on Ubuntu it worked on the first go.
I don't know if this is an expected behavior. I have two questions:
- Shouldn't OpenJDK have the same parameters when executing a Java file?
- If not: Shouldn't Gradle support OpenJDK?
To make my solution complete, I want to post some informations how you can install Oracle JDK 8 easily on Ubuntu (15.10):
I used the webupd8 repository which provides an automated way of installing Java 8 on Ubuntu (this is also recommended by Ubuntu/Canonical).
Our PPA supports Ubuntu 15.04, 14.10, 14.04 and 12.04 as well as Linux
Mint 17.1, 17 and 13. Add the PPA and install Oracle Java 8 (the
package provides both JDK8 and JRE8) using the following commands:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update sudo
apt-get install oracle-java8-installer
Tip: if you're behind a firewall / router that blocks some of the
redirects required to download the Oracle Java archive, you can
download the JDK tar.gz archive manually and place it under
/var/cache/oracle-jdk8-installer - then, installing the
"oracle-java8-installer" package will use the local archive instead of
trying it to download it itself.
Once installed, running "java -version" in a terminal should output
something like this:
andrei@andrei-desktop:~$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)