Requisitos de instalação no Windows
native tools
Configurar no bash do git (ainda não deu certo)
native tools
e depois de abri-lo rodando echo %PATH%
export PATH="${PATH}:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/VC/VCPackages:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TestWindow:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Current/bin/Roslyn:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/devinit:C/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x64:C/Program Files (x86)/Windows Kits/10/bin/x64:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools//MSBuild/Current/Bin:C/Windows/Microsoft.NET/Framework64/v4.0.30319:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/:C/Program Files/ImageMagick-7.0.10-Q16:C/Windows/system32:C/Windows:C/Windows/System32/Wbem:C/Windows/System32/WindowsPowerShell/v1.0/:C/Windows/System32/OpenSSH/:C/Program Files (x86)/NVIDIA Corporation/PhysX/Common:C/Program Files/Git/cmd:C/WINDOWS/system32:C/WINDOWS:C/WINDOWS/System32/Wbem:C/WINDOWS/System32/WindowsPowerShell/v1.0/:C/WINDOWS/System32/OpenSSH/:C/Users/Typer/Downloads/Binaries-LuaDist-batteries-0.9.8-Windows-x86/bin:/g/TDM-GCC-64/bin::C/Program Files/Docker/Docker/resources/bin:/g/Program Files (x86)/Bluetooth Command Line Tools/bin:C/Users/Typer/AppData/Local/Microsoft/WindowsApps:C/Users/Typer/Downloads/Binaries-LuaDist-batteries-0.9.8-Windows-x86//bin:C/Users/Typer/.jdks/adopt-openjdk-11.0.7/bin::/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin:/g/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja"
@TargetClass(className = "org.apache.kafka.common.utils.Crc32C$Java9ChecksumFactory")
@Substitute
final class Java9ChecksumFactory {
@Substitute
public Checksum create() {
return new CRC32();
}
}
o comando abaixo vai passar o valor para as classes em tempo de build, se a classe for inicializada em tempo de build então a sua variável estática que tentar acessar a property vai ficar com esse valor preenchido, ja as variaveis de instancia que tentarem acessar essa property soh quuando o binario for iniciado, nao vao achar nada....
TL;DR se quiser prefixar uma property na native-image, crie um valor default dentro dela assim como no java ou inicialize a classe em build time e recupere o valor quando iniciar o binario.
$ native-image -Dk=v
Ex1: binario padrão
native-image --no-server --no-fallback -H:Class=com.mageddo.jdbi.JdbiMain -cp ./build/libs/jdbi-all.jar
Ex2: Quando o jar já tem o main class definido
$ native-image --no-server --no-fallback --target=linux-amd64 -jar helloworld.jar ./build/helloworld
class ReflectionClasses implements Feature {
@Override
public void duringSetup(DuringSetupAccess access) {
ImageSingletons.add(LogHandler.class, new NopLogHanler());
}
}
native-image --expert-options
src/main/resources/META-INF/native-image/io.netty/transport/native-image.properties
Args = -H:ReflectionConfigurationResources=${.}/reflection-config.json
src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json
[
{
"name": "io.netty.channel.socket.nio.NioServerSocketChannel",
"methods": [
{ "name": "<init>", "parameterTypes": [] }
]
},
{
"name": "sun.nio.ch.SelectorImpl",
"fields": [
{ "name": "selectedKeys", "allowUnsafeAccess" : true},
{ "name": "publicSelectedKeys", "allowUnsafeAccess" : true}
]
},
{
"name": "java.sql.Connection",
"allDeclaredFields" : true
},
{
"name": "org.springframework.transaction.TransactionDefinition",
"allDeclaredFields" : true
},
{
"name": "java.sql.Statement[]",
"allPublicConstructors": true,
"allDeclaredConstructors": true
}
]
java -agentlib:native-image-agent=config-output-dir=build/
ou
java -agentlib:native-image-agent=config-merge-dir=/tmp/reflection -cp ./build/libs/jdbi-all.jar com.mageddo.jdbi.JdbiMain
Saber se está rodando em uma NativeImage ou não
ImageInfo.inImageRuntimeCode()
Pegar o path do exectuável que está executando
// /etc/exec.exe
ProcessProperties.getExecutableName()
// /etc
Paths.get(ProcessProperties.getExecutableName()).getParent()
Para que valha em runtime nao precise passar como argumento na hora de rodar o programa
# Build a native image with the default heap settings and override the heap settings at run time
native-image HelloWorld
./helloworld -Xms2m -Xmx10m -Xmn1m
# Build a native image and "bake" heap settings into the image. The specified values will be used at run time
native-image -R:MinHeapSize=2m -R:MaxHeapSize=10m -R:MaxNewSize=1m HelloWorld
./helloworld
Ainda não funciona ele n~ão sabe compilar de forma cross
gu -u install "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/llvm-installable-svm-java19-windows-amd64-22.3.1.jar"
https://www.graalvm.org/22.0/reference-manual/graalvm-updater/#manual-installation
https://github.com/oracle/graal/issues/1446 https://github.com/oracle/graal/issues/407
https://www.graalvm.org/latest/reference-manual/native-image/
$ native-image --expert-options
-H:Optimize="2" Control native-image code optimizations: b - optimize for shortest build time, 0 - no optimizations, 1 - basic
optimizations, 2 - aggressive optimizations.
native-image.properties
Args=-H:DynamicProxyConfigurationResources=${.}/proxy-config.json \
proxy-config.json
[
{ "interfaces": [ "com.sun.jna.platform.win32.Advapi32" ] }
]
Nos meus testes não mudou muita coisa caiu de 8:30 pra 7:50
graalvm commands, graal commands