gradle - 执行Gradle编译的jar,导致“没有主类”
问题描述
gradle 的版本是 6.3-all。这是我的 build.gradle:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
}
group 'com.dennis'
version '1.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
jar {
from {
configurations.runtime.collect { zipTree(it) }
}
manifest {
attributes 'Main-Class': 'com.dennis.tcp.robot.RobotClient'
}
}
dependencies {
/*...*/
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
这里是 settings.gradle
rootProject.name = 'robot'
这是主要课程:
package com.dennis.tcp.robot;
/*import ignored*/
public class RobotClient {
private static final String URL = "192.168.10.140";
private static final int PORT = 9760;
public static void main(String[] args) {
NioEventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
try {
bootstrap.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE,true)
.handler(new RobotClientInitializer());
ChannelFuture future = bootstrap.connect(URL, PORT).sync();
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
group.shutdownGracefully();
}
}
}
打包进度很顺利,但是输出的 jar 无法执行,并给出no main class
jar 文件的异常显示主类 RobotClient 确实已编译。但是,java -jar
无法执行或找到主类。为什么会这样?
解决方案
推荐阅读
- c# - 如何将 ListView 项目显示为 1 行中的 1 个项目?
- flutter - 在 Flutter 中循环完成后,CountdownTimer 正在运行
- c# - 在 c# 中使用 ProtonMail 发送电子邮件
- wordpress - 使用 WPBakery 页面构建器和默认的 Wordpress 元素
- javascript - 为什么我的搜索栏不起作用?Javascript - 网页
- reactjs - 如何访问 SCSS 中的 react 公共文件夹以导入图像
- reactjs - Reactjs - 使用钩子将类组件转换为功能性组件
- database - 持久的基于 Oracle 连接/队列的插入?
- javascript - 为什么我的多维数组的最后一个元素不可点击?
- mongodb - 在空数组上使用 $all 查询 MongoDB 不会返回结果