如何使用 java 命令将我的 Kotlin Spring 引导项目设置为 运行?

How do I get my Kotlin Spring Boot project to run using java command?

使用 IntelliJ,我可以将我的 Kotlin (JVM) 项目转移到 运行。但是,当我尝试使用 java 命令 运行 它时,它失败了。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>org.cas.eo.contentacq</groupId>
    <artifactId>content-acq-copper-manifest-writer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>content-acq-copper-manifest-writer</name>

    <properties>
        <java.version>11</java.version>
        <kotlin.version>1.5.21</kotlin.version>
        <start-class>org.cas.eo.contentacq.contentacqcoppermanifestwriter.Application</start-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.5.3</version>
        </dependency>





        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>


        <!-- LOGGING -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.30</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>
        <!-- end LOGGING-->

        <!-- DEPS from first try -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>


        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.cas.eo.contentacq.dbresources</groupId>
            <artifactId>dbresources-client</artifactId>
            <version>2.8.1</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>


    </dependencies>


    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <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>
                    <!-- added from kotlinlang.org-->
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals> <goal>test-compile</goal> </goals>
                    </execution>
                    <!-- -->
                </executions>
                <configuration>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                    <jvmTarget>1.8</jvmTarget>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>
    </build>

</project>

这就是我 运行 来自 Jenkins 的方式:

#!/bin/bash

cd /support/d63/copper/manifest_writer/dev

export SPRING_PROFILES_ACTIVE=dev

./run.sh

这是run.sh:

#!/bin/bash

JAVA_HOME=/usr2/jest/openjdk/java11

#This ensures that UTF-8 is always used, even for encoding file names.
export LC_ALL=en_US.UTF-8

cd /support/d63/copper/manifest_writer/dev

JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

$JAVA_HOME/bin/java $JAVA_OPTS -jar content-acq-copper-manifest-writer-0.0.1-SNAPSHOT.jar $*

这是我的开始class:

package org.cas.eo.contentacq.contentacqcoppermanifestwriter

import org.cas.eo.contentacq.contentacqcoppermanifestwriter.props.ProcessProps
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication

@SpringBootApplication
@ConfigurationPropertiesScan
class Application (
    private val controller: Controller,
    private val processProps: ProcessProps
): ApplicationRunner {


    fun main(args: Array<String>) {
        runApplication<Application>(*args)
    }

    override fun run(args: ApplicationArguments) {
        if (processProps.logOnly){
            controller.logManifests()
        } else {
            controller.writeManifests()
        }
    }
}

我运行mvn clean package去拿我的罐子。

查看罐子,这是 META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 11
Implementation-Title: content-acq-copper-manifest-writer
Implementation-Version: 0.0.1-SNAPSHOT
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: org.cas.eo.contentacq.contentacqcoppermanifestwriter.Applic
 ation
Spring-Boot-Version: 2.5.3
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx

以下是 jar 的其余内容:

Archive:  target/content-acq-copper-manifest-writer-0.0.1-SNAPSHOT.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2021-08-10 09:58   META-INF/
      518  2021-08-10 09:58   META-INF/MANIFEST.MF
        0  1980-02-01 00:00   org/
        0  1980-02-01 00:00   org/springframework/
        0  1980-02-01 00:00   org/springframework/boot/
        0  1980-02-01 00:00   org/springframework/boot/loader/
     5871  1980-02-01 00:00   org/springframework/boot/loader/ClassPathIndexFile.class
     6806  1980-02-01 00:00   org/springframework/boot/loader/ExecutableArchiveLauncher.class
     3966  1980-02-01 00:00   org/springframework/boot/loader/JarLauncher.class
     1483  1980-02-01 00:00   org/springframework/boot/loader/LaunchedURLClassLoader$DefinePackageCallType.class
     1535  1980-02-01 00:00   org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
    11154  1980-02-01 00:00   org/springframework/boot/loader/LaunchedURLClassLoader.class
     5932  1980-02-01 00:00   org/springframework/boot/loader/Launcher.class
     1536  1980-02-01 00:00   org/springframework/boot/loader/MainMethodRunner.class
      266  1980-02-01 00:00   org/springframework/boot/loader/PropertiesLauncher.class
     1484  1980-02-01 00:00   org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
     8128  1980-02-01 00:00   org/springframework/boot/loader/PropertiesLauncher$ClassPathArchives.class
     1953  1980-02-01 00:00   org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
    18267  1980-02-01 00:00   org/springframework/boot/loader/PropertiesLauncher.class
     1750  1980-02-01 00:00   org/springframework/boot/loader/WarLauncher.class
        0  1980-02-01 00:00   org/springframework/boot/loader/archive/
      302  1980-02-01 00:00   org/springframework/boot/loader/archive/Archive$Entry.class
      511  1980-02-01 00:00   org/springframework/boot/loader/archive/Archive$EntryFilter.class
     4745  1980-02-01 00:00   org/springframework/boot/loader/archive/Archive.class
     6093  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive$AbstractIterator.class
     2180  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive$ArchiveIterator.class
     1857  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive$EntryIterator.class
     1269  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
     2527  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive$SimpleJarFileArchive.class
     5346  1980-02-01 00:00   org/springframework/boot/loader/archive/ExplodedArchive.class
     2884  1980-02-01 00:00   org/springframework/boot/loader/archive/JarFileArchive$AbstractIterator.class
     1981  1980-02-01 00:00   org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
     1081  1980-02-01 00:00   org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
     2528  1980-02-01 00:00   org/springframework/boot/loader/archive/JarFileArchive$NestedArchiveIterator.class
    10349  1980-02-01 00:00   org/springframework/boot/loader/archive/JarFileArchive.class
        0  1980-02-01 00:00   org/springframework/boot/loader/data/
      485  1980-02-01 00:00   org/springframework/boot/loader/data/RandomAccessData.class
      282  1980-02-01 00:00   org/springframework/boot/loader/data/RandomAccessDataFile.class
     2680  1980-02-01 00:00   org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
     3259  1980-02-01 00:00   org/springframework/boot/loader/data/RandomAccessDataFile$FileAccess.class
     4015  1980-02-01 00:00   org/springframework/boot/loader/data/RandomAccessDataFile.class
        0  1980-02-01 00:00   org/springframework/boot/loader/jar/
     1438  1980-02-01 00:00   org/springframework/boot/loader/jar/AbstractJarFile$JarFileType.class
      878  1980-02-01 00:00   org/springframework/boot/loader/jar/AbstractJarFile.class
     4976  1980-02-01 00:00   org/springframework/boot/loader/jar/AsciiBytes.class
      616  1980-02-01 00:00   org/springframework/boot/loader/jar/Bytes.class
      295  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
     3401  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64End.class
     2004  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryEndRecord$Zip64Locator.class
     4682  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
     6223  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
     4620  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryParser.class
      540  1980-02-01 00:00   org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
      345  1980-02-01 00:00   org/springframework/boot/loader/jar/FileHeader.class
    13649  1980-02-01 00:00   org/springframework/boot/loader/jar/Handler.class
     3885  1980-02-01 00:00   org/springframework/boot/loader/jar/JarEntry.class
     1458  1980-02-01 00:00   org/springframework/boot/loader/jar/JarEntryCertification.class
      299  1980-02-01 00:00   org/springframework/boot/loader/jar/JarEntryFilter.class
     2296  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFile.class
     1299  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFile$JarEntryEnumeration.class
    16312  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFile.class
     1368  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFileEntries.class
     2258  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
    16395  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFileEntries.class
     3512  1980-02-01 00:00   org/springframework/boot/loader/jar/JarFileWrapper.class
      702  1980-02-01 00:00   org/springframework/boot/loader/jar/JarURLConnection.class
     4302  1980-02-01 00:00   org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
     9440  1980-02-01 00:00   org/springframework/boot/loader/jar/JarURLConnection.class
     3559  1980-02-01 00:00   org/springframework/boot/loader/jar/StringSequence.class
     1813  1980-02-01 00:00   org/springframework/boot/loader/jar/ZipInflaterInputStream.class
        0  1980-02-01 00:00   org/springframework/boot/loader/jarmode/
      293  1980-02-01 00:00   org/springframework/boot/loader/jarmode/JarMode.class
     2201  1980-02-01 00:00   org/springframework/boot/loader/jarmode/JarModeLauncher.class
     1292  1980-02-01 00:00   org/springframework/boot/loader/jarmode/TestJarMode.class
        0  1980-02-01 00:00   org/springframework/boot/loader/util/
     5174  1980-02-01 00:00   org/springframework/boot/loader/util/SystemPropertyUtils.class
        0  2021-08-10 09:58   BOOT-INF/
        0  2021-08-10 09:58   BOOT-INF/classes/
        0  2021-08-10 09:58   BOOT-INF/classes/org/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/config/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/repo/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/service/
        0  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/utils/
        0  2021-08-10 09:58   META-INF/maven/
        0  2021-08-10 09:58   META-INF/maven/org.cas.eo.contentacq/
        0  2021-08-10 09:58   META-INF/maven/org.cas.eo.contentacq/content-acq-copper-manifest-writer/
     1807  2021-08-10 09:58   BOOT-INF/classes/application.yml
     3677  2021-08-10 09:58   BOOT-INF/classes/data.sql
        0  2021-08-10 09:58   BOOT-INF/classes/META-INF/
      111  2021-08-10 09:58   BOOT-INF/classes/META-INF/content-acq-copper-manifest-writer.kotlin_module
     3194  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/Application.class
     4058  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/config/DatabaseConfiguration.class
     7339  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/Controller.class
     4889  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/EndInfo.class
     5699  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/JournalArticle.class
     5418  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/JournalArticleMaterial.class
     4678  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/Manifest.class
     3096  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/ManifestKt.class
     7622  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/StartInfo.class
     3168  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/model/StartInfoKt.class
     3049  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/AltRunProps.class
     3217  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/ErrorProps.class
     3125  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/FileProps.class
     3246  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/ManifestProps.class
     6897  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/ProcessProps.class
     3044  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/props/ZipProps.class
    12394  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/repo/CopperRepository.class
     3740  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/service/JSONWriter.class
    11097  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/service/TANProcessor.class
     1185  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/utils/Logging$Companion.class
     6095  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/utils/Logging.class
     4767  2021-08-10 09:58   BOOT-INF/classes/org/cas/eo/contentacq/contentacqcoppermanifestwriter/utils/ManifestSerializer.class
     2204  2021-08-10 09:58   BOOT-INF/classes/schema.sql
     5662  2021-08-10 09:08   META-INF/maven/org.cas.eo.contentacq/content-acq-copper-manifest-writer/pom.xml
      102  2021-08-10 09:58   META-INF/maven/org.cas.eo.contentacq/content-acq-copper-manifest-writer/pom.properties
        0  2021-08-10 09:58   BOOT-INF/lib/
  1392390  2021-07-22 13:50   BOOT-INF/lib/spring-boot-2.5.3.jar
  1250332  2021-07-14 06:38   BOOT-INF/lib/spring-context-5.3.9.jar
   374939  2021-07-14 06:38   BOOT-INF/lib/spring-aop-5.3.9.jar
   282575  2021-07-14 06:38   BOOT-INF/lib/spring-expression-5.3.9.jar
    17762  2021-03-06 22:13   BOOT-INF/lib/log4j-to-slf4j-2.14.1.jar
   300365  2021-03-06 22:11   BOOT-INF/lib/log4j-api-2.14.1.jar
     4589  2021-07-20 13:55   BOOT-INF/lib/jul-to-slf4j-1.7.32.jar
    25058  2019-08-02 11:08   BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar
  1458472  1980-02-01 00:00   BOOT-INF/lib/spring-core-5.3.9.jar
    23943  2021-07-14 06:37   BOOT-INF/lib/spring-jcl-5.3.9.jar
   326914  2021-02-22 05:55   BOOT-INF/lib/snakeyaml-1.28.jar
  2993765  1980-02-01 00:00   BOOT-INF/lib/kotlin-reflect-1.5.21.jar
  1497566  1980-02-01 00:00   BOOT-INF/lib/kotlin-stdlib-1.5.21.jar
    17536  2013-12-17 16:10   BOOT-INF/lib/annotations-13.0.jar
   197814  1980-02-01 00:00   BOOT-INF/lib/kotlin-stdlib-common-1.5.21.jar
   104930  2021-07-06 21:17   BOOT-INF/lib/jackson-module-kotlin-2.12.4.jar
  1516044  2021-07-06 20:01   BOOT-INF/lib/jackson-databind-2.12.4.jar
   365223  2021-07-06 19:51   BOOT-INF/lib/jackson-core-2.12.4.jar
    75705  2021-07-06 19:42   BOOT-INF/lib/jackson-annotations-2.12.4.jar
    41472  2019-12-16 22:03   BOOT-INF/lib/slf4j-api-1.7.30.jar
   290339  2017-03-31 20:20   BOOT-INF/lib/logback-classic-1.2.3.jar
   471901  2017-03-31 20:19   BOOT-INF/lib/logback-core-1.2.3.jar
   159222  2021-03-03 13:06   BOOT-INF/lib/HikariCP-4.0.3.jar
   417943  2021-07-14 06:39   BOOT-INF/lib/spring-jdbc-5.3.9.jar
   696496  2021-07-14 06:38   BOOT-INF/lib/spring-beans-5.3.9.jar
   326496  2021-07-14 06:39   BOOT-INF/lib/spring-tx-5.3.9.jar
  2303679  2019-10-14 09:19   BOOT-INF/lib/h2-1.4.200.jar
    31619  2018-05-29 07:59   BOOT-INF/lib/dbresources-client-2.8.1.jar
    13158  2018-05-29 07:50   BOOT-INF/lib/dbresources-lib-2.8.1.jar
   183147  2021-07-14 06:39   BOOT-INF/lib/spring-context-support-5.3.9.jar
     4523  2018-05-29 07:50   BOOT-INF/lib/dbresources-codec-2.8.1.jar
   353793  2020-01-22 15:10   BOOT-INF/lib/commons-codec-1.15.jar
   284220  2011-01-13 23:06   BOOT-INF/lib/commons-lang-2.6.jar
   575389  2008-04-11 15:37   BOOT-INF/lib/commons-collections-3.2.1.jar
   163151  2011-10-03 17:30   BOOT-INF/lib/commons-io-2.1.jar
   358048  2012-08-04 17:37   BOOT-INF/lib/commons-configuration-1.9.jar
    60686  2007-11-19 00:16   BOOT-INF/lib/commons-logging-1.1.1.jar
   159123  2010-12-14 20:30   BOOT-INF/lib/json-lib-2.4-jdk15.jar
   231320  2008-08-28 16:18   BOOT-INF/lib/commons-beanutils-1.8.0.jar
    86487  2008-08-08 11:10   BOOT-INF/lib/ezmorph-1.0.6.jar
  2152051  2010-08-14 12:20   BOOT-INF/lib/ojdbc6-11.2.0.2.0.jar
  1564883  2021-07-22 13:49   BOOT-INF/lib/spring-boot-autoconfigure-2.5.3.jar
    16125  1980-02-01 00:00   BOOT-INF/lib/kotlin-stdlib-jdk8-1.5.21.jar
    22993  1980-02-01 00:00   BOOT-INF/lib/kotlin-stdlib-jdk7-1.5.21.jar
    29278  1980-02-01 00:00   BOOT-INF/lib/spring-boot-jarmode-layertools-2.5.3.jar
     1909  2021-08-10 09:58   BOOT-INF/classpath.idx
      212  2021-08-10 09:58   BOOT-INF/layers.idx
---------                     -------
 23596713                     169 files

这是错误:

Exception in thread "main" java.lang.NullPointerException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)

因为它在 IntelliJ 中有效,但在 运行 java 命令中无效,我假设我在那里做错了。

(在这里抓着救命稻草……)

我想到一件事:你的main()方法是一个实例方法,我没见过,可能是个问题。

在独立程序中,main() 不能是实例方法,因为还没有实例可以调用它。我不知道 Spring 加载程序是否为这种情况提供了特殊津贴,但如果没有,我建议尝试将其移动到 companion object:

class Application(/* … */): ApplicationRunner {

    companion object {
        fun main(args: Array<String>) {
            runApplication<Application>(*args)
        }
    }
    
    // …

或者输出到顶层函数:

class Application(/* … */): ApplicationRunner {
    // …
}

fun main(args: Array<String>) {
    runApplication<Application>(*args)
}

在后一种情况下,您必须将 Kt 附加到 start-class 标记(或者您将 class 的名称指定到 运行 的任何位置) ,因为这就是 Kotlin/JVM 编译器处理顶级函数的方式。

你喜欢哪一种是风格问题;伴生对象封装得更紧密,但顶层函数更简单、更简洁。 (而且由于您在任何项目中通常都不会使用太多,因此几乎没有混淆或冲突的危险。)