java找不到应用程序,在Ubuntu上找不到Java应用程序主类

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值