oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.26k stars 1.62k forks source link

ZipException: zip END header not found(Workaround for win11) #7137

Open ZY945 opened 1 year ago

ZY945 commented 1 year ago

Describe the issue

This issue is a workaround to summarize the problem. If your question is as follows

The scenario in which the problem occurs

Upgrade the Spring project's jar first, and then try native-image to generate the exe file

Scene reproduction

mvn package
native-image -jar .\Graalvm-SpringBoot-Demo-0.0.1-SNAPSHOT.jar --no-fallback

You will notice that the exe file appears, but the execution fails image

The way of solve

spring doc:https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html You can do this successfully with Spring's plugin

<build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <!-- imageName用于设置生成的二进制文件名称 -->
                    <imageName>${project.artifactId}</imageName>
                    <!-- mainClass用于指定main方法类路径 -->
                    <mainClass>${main-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>build-native</id>
                        <goals>
                            <goal>compile-no-fork</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
mvn clean package -Pnative

image image image

ZY945 commented 1 year ago

This issue is used to help people with the same problem later to solve it temporarily

oubidar-Abderrahim commented 1 year ago

Thank you for sharing this workaround, it is very helpful of you