我在我的项目中添加了graal库来执行Java中的JavaScript。我的项目在spingboot框架上工作。
compile group: 'org.graalvm.sdk', name: 'graal-sdk', version: '1.0.0-rc9'
compile group: 'org.graalvm.js', name: 'js', version: '1.0.0-rc9'
compile group: 'org.graalvm.js', name: 'js-scriptengine', version: '1.0.0-rc9'
compile group: 'org.graalvm.tools', name: 'profiler', version: '1.0.0-rc9'
compile group: 'org.graalvm.tools', name: 'chromeinspector', version: '1.0.0-rc9'
compile group: 'org.graalvm.truffle', name: 'truffle-api', version: '1.0.0-rc9'
Run Code Online (Sandbox Code Playgroud)
如果我将项目投标到包含所有库的胖罐中,graal初始化将失败并抛出FileSystemNotFoundException。
java.nio.file.FileSystemNotFoundException: null
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:169)
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:155)
at java.base/java.nio.file.Paths.get(Paths.java:143)
at com.oracle.truffle.polyglot.LanguageCache.collectLanguages(LanguageCache.java:284)
at com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:211)
at com.oracle.truffle.polyglot.LanguageCache.languages(LanguageCache.java:201)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.initializeLanguages(PolyglotEngineImpl.java:480)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:168)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:152)
at com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:197)
at org.graalvm.polyglot.Engine$Builder.build(Engine.java:488)
at org.graalvm.polyglot.Context$Builder.build(Context.java:1083)
at org.graalvm.polyglot.Context.create(Context.java:660)
at ocpm.pcf.policyengine.engine.cache.JavaScriptPolicyParser.graalParse(JavaScriptPolicyParser.java:48)
Run Code Online (Sandbox Code Playgroud)我在异常堆栈中调试了ponit,发现graal希望在js-1.0.0-rc9.jar中初始化“启动”配置文件。但是在上述情况下,它使用了不同的URI模式。
- In …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Java 编译为 WebAssembly。这可能吗?我最初的方法是采用这篇博文中描述的示例
博文中描述的方法如下:
我进行到步骤 4,但之后我无法将 LLVM IR 位代码编译为 wasm。
我从 LLVM 收到以下错误:
LLVM ERROR: unsupported GC: compressed-pointer
Run Code Online (Sandbox Code Playgroud)
有没有人尝试过这个并成功了?
我正在尝试在项目中使用 GraalVM 来添加简单的脚本功能。我使用 Maven 进行依赖项管理来加载 Graal 的基本依赖项。这是我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cx.matthew</groupId>
<artifactId>graaltest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<graalvm.version>19.0.2</graalvm.version>
<compiler.dir>${project.build.directory}/compiler</compiler.dir>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>profiler</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>chromeinspector</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>19.0.0</version>
<scope>compile</scope>
</dependency>
<dependency> …Run Code Online (Sandbox Code Playgroud) 我有一个研究项目(在 Java 8 中实现),在 Eclipse 中包含几个类、几个主要函数和超过 10000 行代码。当输入不小时,程序就会内存不足。
我想看看如果编译为本机应用程序,它是否会使用更少的堆栈内存。
我没有找到在 Eclipse 中执行此操作的方法。
我做到了,
$GRAALVM_HOME/bin/javac /home/appu/Downloads/2019/June/20/HelloWorld.java
它有效。我得到了一个可以工作的二进制文件。
我尝试了
/home/appu/Downloads/Apps/GraalVM/2019-06-20/graalvm-ee-19.0.2/bin/native-image /home/appu/eclipse-nimi/NimishaGraalEE19/bin/nimi/decimate/Decimate.class
我得到Main entry point class '/home/appu/eclipse-nimi/NimishaGraalEE19/bin/nimi/decimate/Decimate.class' not found.
我尝试了
/home/appu/Downloads/Apps/GraalVM/2019-06-20/graalvm-ee-19.0.2/bin/native-image /home/appu/eclipse-nimi/NimishaGraalEE19/bin/*
我得到Main entry point class '/home/appu/eclipse-nimi/NimishaGraalEE19/bin/nimi' not found.
经典
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}
Run Code Online (Sandbox Code Playgroud)
被编译成“HelloWorld.class”
它给出了一个可执行文件“helloworld”,它是可执行的(application/x-executable)。
我可以从 Eclipse 得到同样的东西吗?对于多类文件,我可以从命令行获得相同的结果吗?
当我将上面的代码更改为
public class HelloWorld
{
public static void hello()
{
System.out.println("Hello, World!");
}
}
Run Code Online (Sandbox Code Playgroud)
并添加另一个类
public class Main
{
public static void …Run Code Online (Sandbox Code Playgroud) 我对 GraalVM 的东西有点陌生,所以请帮助我。我使用 IntelliJ IDEA 作为我的 IDE,使用 Gradle 作为我的标准构建系统。我的所有项目都使用内置的 GraalVM JDK(它基于 Java 11)。所以,我的问题是,当我尝试导入该org.graalvm.polyglot包或任何此类包时,它会在导入下方绘制一条波浪线,这表示 IntelliJ IDEA 无法识别该包并且尚未对其建立索引。但是当我使用 gradle 或任何方法运行它时,导入的包可以工作。IDE 的自动完成功能不起作用。就像在记事本中编程一样,输入类和方法的完整名称有点令人恼火。我看过一些相关教程,建议我将其添加graal-sdk.jar为依赖项,但在 Java 11 版本的 GraalVM 中找不到该 jar 文件。我什至将整个lib文件夹添加到 IntelliJLibraries中的部分Project Structure。所有这些都没有成功。有人可以帮我解决这个问题吗?
我尝试运行两个心轴:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel:20.3.2.0-Final-java11
Run Code Online (Sandbox Code Playgroud)
和 GraalVM 版本:
./mvnw package -Pnative -Dquarkus.native.container-build=true
Run Code Online (Sandbox Code Playgroud)
但他们只是卡在构建上,我有 M1 的最新 Docker,这是来自 mandrel 的示例,它只是使用 300% cpu 停留在那里:
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] docker run -v lambda-0.0.1-SNAPSHOT-native-image-source-jar:/project:z --env LANG=C --rm quay.io/quarkus/ubi-quarkus-mandrel:20.3.2.0-Final-java11 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dcom.mysql.cj.disableAbandonedConnectionCleanup=true -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 -J-Duser.language=en -J-Dfile.encoding=UTF-8 --report-unsupported-elements-at-runtime --enable-all-security-services --allow-incomplete-classpath -H:DynamicProxyConfigurationFiles=dynamic-proxies.json -H:ResourceConfigurationFiles=resources-config.json -H:ReflectionConfigurationFiles=reflection-config.json --initialize-at-run-time=com.common.utils -H:+ReportExceptionStackTraces --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -jar lambda-0.0.1-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:+AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:-UseServiceLoaderFeature -H:+StackTrace lambda-0.0.1-SNAPSHOT-runner
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform …Run Code Online (Sandbox Code Playgroud) 我开始玩 quarkus 和 graalvm。我将文件(txt 和 jpg)添加到项目 ( src/main/resources/) 中的资源中。为了确保我可以在控制器中访问该文件,我显示了它的大小:
URL url = Thread.currentThread().getContextClassLoader().getResource("/Resource2.txt");\nFile file = new File(url.toURI());\nreturn "Hello My Friend! File size in bytes = " + file.length();\nRun Code Online (Sandbox Code Playgroud)\n当我用 maven ( mvn quarkus:dev) 运行它时,它就可以工作了。控制器代码在这里。
当我创建本机 Quarkus 应用程序并尝试在 docker 内运行时出现问题。\n为了确保该文件包含在本机映像中,我添加了一个大 jpg 文件 (3.3MB),创建了resources-config.json:
{ "resources": \n { "includes": [\n { "pattern": "IMG_3_3M\\\\.jpg$"},\n { "pattern": "Resources2\\\\.txt$"}\n ]\n}}\nRun Code Online (Sandbox Code Playgroud)\n并application.properties添加:\n quarkus.native.additional-build-args = -H:ResourceConfigurationFiles=resources-config.json。原生跑步者尺寸增加自:
39M Mar 21 12:48 hello-quarkus-1.0-SNAPSHOT-runner …我们有一个 Java 17 Quarkus 应用程序编译为本机可执行文件 (ubi-quarkus-native-image:22.2-java17),在 Kubernetes 中运行。它使用 SSL 连接到旧的集成服务器,发出 HTTP 请求。我们的应用程序使用套接字工厂创建 SSLSocket 并连接它;请求成功。完成后,我们调用 SSLSocket#close。这也有效,但在另一边他们记录了这个:
12:51:16 : ssl_debug(58): Shutting down SSL layer...
12:51:16 : ssl_debug(58): Sending alert: Alert Warning: close notify
12:51:16 : ssl_debug(58): Read 15328 bytes in 3 records, 15214 bytes net, 5071 average.
12:51:16 : ssl_debug(58): Wrote 175 bytes in 1 records, 152 bytes net, 152 average.
12:51:16 : ssl_debug(58): Closing transport...
12:51:16 : ssl_debug(58): Waiting on peer close notify...
12:51:16 : ssl_debug(58): Received alert message: Alert Warning: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 spring boot 3、graalvm、lombok 和 jpa 创建一个示例项目。当我使用 main 方法执行测试时,一切看起来都很完美。但是当我运行本机二进制文件时遇到问题。
首先我创建二进制文件:
mvn -Pnative native:build
Run Code Online (Sandbox Code Playgroud)
然后我运行该项目:
./target/demo
Run Code Online (Sandbox Code Playgroud)
项目开始正常,但是当我尝试使用curl 创建新记录时:
curl --location --request POST 'localhost:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "test",
"surname": "surname"
}'
Run Code Online (Sandbox Code Playgroud)
我在控制台中看到此错误:
2022-12-21T01:51:48.055+01:00 WARN 105751 --- [nio-8080-exec-2] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.example.demo.dto.ExampleDto]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Builder class `com.example.demo.dto.ExampleDto$ExampleDtoBuilder` does not have build method (name: 'build')
2022-12-21T01:51:48.055+01:00 WARN 105751 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/json;charset=UTF-8' is not supported]
Run Code Online (Sandbox Code Playgroud)
我的 DTO …
我刚刚使用 Maven 将几个项目升级到 Java 19、Spring Boot 3.0.2、Kotlin 1.8.0,我希望 Spring Boot 生成本机映像。
<java.version>19</java.version>
<kotlin.version>1.8.0</kotlin.version>
Run Code Online (Sandbox Code Playgroud)
配置的相关部分spring-boot-maven-plugin是:
<configuration>
<image>
<env>
<BP_JVM_VERSION>19.*</BP_JVM_VERSION>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:+HeapDumpOnOutOfMemoryError -XX:MaxDirectMemorySize=64M</BPE_APPEND_JAVA_TOOL_OPTIONS>
<BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是,当我使用以下命令构建其中一个项目时
mvn -Pnative spring-boot:build-image
Run Code Online (Sandbox Code Playgroud)
然后构建失败并显示以下错误消息:
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 9.10.2
[INFO] [creator] unable to find dependency
[INFO] [creator] no valid dependencies for native-image-svm, 19.*, and io.paketo.stacks.tiny in [(jdk, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (native-image-svm, …Run Code Online (Sandbox Code Playgroud) graalvm ×10
java ×5
spring-boot ×3
quarkus ×2
apple-m1 ×1
bukkit ×1
docker ×1
eclipse ×1
jackson ×1
javascript ×1
llvm ×1
lombok ×1
maven ×1
native ×1
ssl ×1
substratevm ×1
webassembly ×1