【发布时间】:2018-08-23 15:11:44
【问题描述】:
我正在尝试打包(maven 包)并运行(java -jar file.jar)一个包含 java 和 kotlin 代码的项目。我已按照以下教程进行操作:https://michaelrice.com/2016/08/hello-world-with-kotlin-and-maven/
kotlin source src/main/kotlin
java source src/main/java
我尝试运行的文件位于src/main/kotlin/THEFILE.kt
在尝试运行 jar 成功打包后,我收到错误
Error: Could not find or load main class THEFILEKt
这可能是什么原因以及如何解决?
提前致谢!!!
Pom.xml 包含必要的 kotlin 插件和依赖项:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>src/main/kotlin</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>
THEFILEKt
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
THEFILEKt
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
【问题讨论】:
-
THEFILEKT– Kotlin 文件外观类名称以Kt结尾,而不是KT。请尝试在整个 POM 中将THEFILEKT替换为THEFILEKt。 -
文件名无关紧要。内容更重要。
CsiidGenerator是什么?生成的清单是什么样子的? -
清单文件:
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Built-By: deividas Created-By: Apache Maven 3.5.0 Build-Jdk: 1.8.0_131 Main-Class: THEFILE
标签: java maven jar kotlin executable-jar