Linux command
native-image 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Compile Java to native executable
native-image -jar [app.jar]
Compile with specific output name
native-image -jar [app.jar] -o [myapp]
Run JavaScript file
js [script.js]
Run Python file
graalpy [script.py]
Install additional language
gu install [python]
List installed components
gu list
Show GraalVM version
java -version
Compile with build report
native-image --diagnostics-mode -jar [app.jar]
说明
GraalVM is a high-performance JDK with ahead-of-time native compilation and polyglot support. It runs Java, JavaScript, Python, Ruby, R, and LLVM-based languages. native-image compiles Java applications to native executables. Benefits include instant startup, reduced memory, and no JVM dependency. Requires closed-world analysis—all code paths must be known at build time. Reflection, dynamic proxies, and resources need configuration files. Use the tracing agent: java -agentlib:native-image-agent=config-output-dir=conf -jar app.jar to generate them. gu (GraalVM Updater) manages optional components. Install language runtimes like Python (graalpy), Ruby (truffleruby), or LLVM toolchain. GraalVM's Truffle framework enables high-performance language implementations. Languages can interoperate—call JavaScript from Java or vice versa.
FAQ
What is the native-image command used for?
GraalVM is a high-performance JDK with ahead-of-time native compilation and polyglot support. It runs Java, JavaScript, Python, Ruby, R, and LLVM-based languages. native-image compiles Java applications to native executables. Benefits include instant startup, reduced memory, and no JVM dependency. Requires closed-world analysis—all code paths must be known at build time. Reflection, dynamic proxies, and resources need configuration files. Use the tracing agent: java -agentlib:native-image-agent=config-output-dir=conf -jar app.jar to generate them. gu (GraalVM Updater) manages optional components. Install language runtimes like Python (graalpy), Ruby (truffleruby), or LLVM toolchain. GraalVM's Truffle framework enables high-performance language implementations. Languages can interoperate—call JavaScript from Java or vice versa.
How do I run a basic native-image example?
Run `native-image -jar [app.jar]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more native-image examples?
This page includes 8 examples for native-image, plus related commands for nearby Linux tasks.