当前位置: 首页 > 知识库问答 >
问题:

GraalVM-Spring本机错误:主入口点类的com。springnative。演示。未找到DemoApplication

贺雪松
2023-03-14

我对GraalVM很陌生,我正在努力塑造一个原生形象。

我正在一些官方教程上构建一个简单的示例。我仍然收到一个找不到主类的错误。这是我的pom。我错过了什么?每个设置都到位了。我有一个简单的Rest Controller,带有一个“hello”GetMap。独立的应用程序运行良好。它没有什么特别的,所以我不会发布代码,因为它毫无用处。只有在主类中,我有proxyBeanmethod=false

package com.springnative.demo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication(proxyBeanMethods = false)
@ComponentScan("com.springnative")
public class DemoApplication {
    
    private Log log = LogFactory.getLog(DemoApplication.class);
    
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
    
}


<?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.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.spring-native</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <sring-graalvm.version>0.8.4</sring-graalvm.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.experimental</groupId>
            <artifactId>spring-graalvm-native</artifactId>
            <version>${sring-graalvm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tomcat.experimental/tomcat-embed-programmatic -->
        <dependency>
            <groupId>org.apache.tomcat.experimental</groupId>
            <artifactId>tomcat-embed-programmatic</artifactId>
            <version>10.0.2</version>
        </dependency>


        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <env>
                            <BP_BOOT_NATIVE_IMAGE>true</BP_BOOT_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.graalvm.nativeimage</groupId>
                <artifactId>native-image-maven-plugin</artifactId>
                <version>21.0.0.2</version>
                <configuration>
                    <mainClass>com.springnative.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>native-image</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

错误输出:

[INFO] Executing: C:\Program Files\graalvm-ce-java8-21.0.0.2\jre\lib\svm\bin\native-image.exe -cp C:\Users\dragos.roban\.m2\repository\org\springframework\experimental\spring-graalvm-native\0.8.4\spring-graalvm-native-0.8.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.4.3\spring-boot-starter-data-jpa-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.4.3\spring-boot-starter-aop-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\aspectj\aspectjweaver\1.9.6\aspectjweaver-1.9.6.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.4.3\spring-boot-starter-jdbc-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-jdbc\5.3.4\spring-jdbc-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\jakarta\transaction\jakarta.transaction-api\1.3.3\jakarta.transaction-api-1.3.3.jar;C:\Users\dragos.roban\.m2\repository\jakarta\persistence\jakarta.persistence-api\2.2.3\jakarta.persistence-api-2.2.3.jar;C:\Users\dragos.roban\.m2\repository\org\hibernate\hibernate-core\5.4.28.Final\hibernate-core-5.4.28.Final.jar;C:\Users\dragos.roban\.m2\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;C:\Users\dragos.roban\.m2\repository\org\javassist\javassist\3.27.0-GA\javassist-3.27.0-GA.jar;C:\Users\dragos.roban\.m2\repository\net\bytebuddy\byte-buddy\1.10.20\byte-buddy-1.10.20.jar;C:\Users\dragos.roban\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\dragos.roban\.m2\repository\org\jboss\jandex\2.2.3.Final\jandex-2.2.3.Final.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;C:\Users\dragos.roban\.m2\repository\org\dom4j\dom4j\2.1.3\dom4j-2.1.3.jar;C:\Users\dragos.roban\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.1.2.Final\hibernate-commons-annotations-5.1.2.Final.jar;C:\Users\dragos.roban\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.3\jaxb-runtime-2.3.3.jar;C:\Users\dragos.roban\.m2\repository\org\glassfish\jaxb\txw2\2.3.3\txw2-2.3.3.jar;C:\Users\dragos.roban\.m2\repository\com\sun\istack\istack-commons-runtime\3.0.11\istack-commons-runtime-3.0.11.jar;C:\Users\dragos.roban\.m2\repository\com\sun\activation\jakarta.activation\1.2.2\jakarta.activation-1.2.2.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\data\spring-data-jpa\2.4.5\spring-data-jpa-2.4.5.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\data\spring-data-commons\2.4.5\spring-data-commons-2.4.5.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-orm\5.3.4\spring-orm-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-context\5.3.4\spring-context-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-tx\5.3.4\spring-tx-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-beans\5.3.4\spring-beans-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-aspects\5.3.4\spring-aspects-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-security\2.4.3\spring-boot-starter-security-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter\2.4.3\spring-boot-starter-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.4.3\spring-boot-autoconfigure-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.4.3\spring-boot-starter-logging-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\dragos.roban\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\dragos.roban\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;C:\Users\dragos.roban\.m2\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;C:\Users\dragos.roban\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\dragos.roban\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\dragos.roban\.m2\repository\org\yaml\snakeyaml\1.27\snakeyaml-1.27.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-aop\5.3.4\spring-aop-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\security\spring-security-config\5.4.5\spring-security-config-5.4.5.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\security\spring-security-web\5.4.5\spring-security-web-5.4.5.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-expression\5.3.4\spring-expression-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.4.3\spring-boot-starter-web-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.4.3\spring-boot-starter-json-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.11.4\jackson-databind-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.4\jackson-annotations-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.11.4\jackson-core-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.4\jackson-datatype-jdk8-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.4\jackson-datatype-jsr310-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.4\jackson-module-parameter-names-2.11.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.4.3\spring-boot-starter-tomcat-2.4.3.jar;C:\Users\dragos.roban\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.43\tomcat-embed-core-9.0.43.jar;C:\Users\dragos.roban\.m2\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;C:\Users\dragos.roban\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.43\tomcat-embed-websocket-9.0.43.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-web\5.3.4\spring-web-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-webmvc\5.3.4\spring-webmvc-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\dragos.roban\.m2\repository\org\apache\tomcat\experimental\tomcat-embed-programmatic\9.0.38\tomcat-embed-programmatic-9.0.38.jar;C:\Users\dragos.roban\.m2\repository\com\h2database\h2\1.4.200\h2-1.4.200.jar;C:\Users\dragos.roban\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;C:\Users\dragos.roban\.m2\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-core\5.3.4\spring-core-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\spring-jcl\5.3.4\spring-jcl-5.3.4.jar;C:\Users\dragos.roban\.m2\repository\org\springframework\security\spring-security-core\5.4.5\spring-security-core-5.4.5.jar;C:\CeBAS\Tasks\2366\demo\target\demo-0.0.1-SNAPSHOT.jar -H:Class=com.springnative.demo.DemoApplication
Warning: Ignoring server-mode native-image argument --no-server.
[com.springnative.demo.demoapplication:9848]    classlist:  11,003.49 ms,  1.80 GB
Error: Main entry point class 'com.springnative.demo.DemoApplication' not found.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

共有1个答案

夹谷苗宣
2023-03-14

已解决。您需要在maven buld('mvn清洁包-P之前实际运行

graal`) the `vcvars` command. Goes something like
>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars.bat
>mvn clean package -P graal

对于那些感兴趣的人,我在这里提供了一个配置文件,非常重要的是,spring boot maven插件要在本机image maven插件之后,以避免与boot repackagi冲突

<profile>
    <id>graal</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.nativeimage</groupId>
                <artifactId>native-image-maven-plugin</artifactId>
                <version>21.0.0.2</version>
                <configuration>
                    <mainClass>com.springnative.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>native-image</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <builder>${builder}</builder>
                        <env>
                            <BP_BOOT_NATIVE_IMAGE>true</BP_BOOT_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

现在我有另一个问题,我不知道如何处理。我有Microsoft Visual 2019版。路径已正确配置为包括cl.exe,但不知何故,此stdio。h文件在任何地方都不存在。也许我用错了版本。

Use -Dspring.native.verbose=true on native-image call to see more detailed information from the feature
[com.springnative.demo.demoapplication:1464]        (cap):     427.65 ms,  2.39 GB
[com.springnative.demo.demoapplication:1464]        setup:   2,338.07 ms,  2.39 GB
Error: Error compiling query code (in C:\Users\DRAGOS~1.ROB\AppData\Local\Temp\SVM-4416010879664063627\JNIHeaderDirectives.c). Compiler command ''C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64\cl.exe' /WX /W4 /wd4244 /wd4245 /wd4800 /wd4804 /wd4214 '-IC:\Program Files\graalvm-ce-java8-21.0.0.2\include\win32' '/FeC:\Users\DRAGOS~1.ROB\AppData\Local\Temp\SVM-4416010879664063627\JNIHeaderDirectives.exe' 'C:\Users\DRAGOS~1.ROB\AppData\Local\Temp\SVM-4416010879664063627\JNIHeaderDirectives.c' ' output included error: [JNIHeaderDirectives.c, C:\Users\DRAGOS~1.ROB\AppData\Local\Temp\SVM-4416010879664063627\JNIHeaderDirectives.c(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory]
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1
 类似资料:
  • 运行命令vc时。sql(testsql),出现以下错误 通用域名格式。液火花沃拉。VoraConfigurationException:未找到ZooKeeper主机 动物园管理员在所有三个节点上启动并运行服务。 错误日志显示以下内容: 2016-09-14 15:14:32418-信息[NIOServerCxn.工厂:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactor

  • 我是编程新手,我非常喜欢它。我刚刚下载了Eclipse,我遇到了一个无法帮助我解决的错误。不幸的是,它是德语的,但意思是:“找不到主类”-“Fehler: Hauptcroasse konnte nicht gefunden oder geladen werden” 我知道它与“”有关。因为这对我来说是全新的,所以你能帮我会很酷。 下面的错误源代码;

  • 该链接描述了工具的用法 https://github.com/oracle/graal/blob/master/substratevm/CONFIGURE.md 我无法在JDK11的Graalvm版本19.0.3.2中找到此工具 我在哪里可以得到这个工具?

  • 问题内容: 我有一个由Eclipse生成的.jar,我无法在其他计算机(与Windows XP)上运行。出现“找不到主类。程序将退出”消息。那台计算机可以在Netbeans生成的另一个.jar上正常运行,所以我想JRE并不是问题。我更新了JRE,但没有改变。问题是什么? 更新:我忘了提,我做了一个可运行的jar文件。在另外两台计算机上,它可以正常工作(win 7和XP),但在特定计算机上则不能。

  • 问题内容: 所有, 我的类路径已设置为以下文件夹: 我所有的Java文件和类文件都在中列出的文件夹下。 但是在运行in 文件夹时出现以下错误: 谁能帮我理解这里的原因? 问题答案: 您在包装内。您应该坐在包根目录中。上一个文件夹。 然后使用重新执行它。 就是说,您不应该使用环境变量。您的当前也是无效的。未加引号的路径名中有空格。另外,该文件夹不应放在类路径中。只需使用like这样的参数(坐在包根文

  • 似乎不知道为什么这个简单的程序在我的电脑上停止工作。我编译的程序直到视窗更新都很好,但是当我试图编译一个新程序时,我得到了以下信息。我附上了程序的图片和命令提示符错误信息。我检查了CLASSPATH,它看起来很好。 程序-HelloWorldApp。JAVA 执行javac HelloWorldApp。爪哇——一切都很好 执行java HelloWorldApp- 错误:在HelloWorldAp