Josh Long created FTPSERVER-514:
-----------------------------------
Summary: please add a few configuration files to support GraalVM
native images
Key: FTPSERVER-514
URL: https://issues.apache.org/jira/browse/FTPSERVER-514
Project: FtpServer
Issue Type: Improvement
Components: Server
Affects Versions: 1.2.0
Environment: any os, with graalvm. Im using Graalvm for Java 17
Reporter: Josh Long
Hi - i love your project and use it a lot. Thank you.
I wanted to make it work with GraalVM's `native-image` compiler mechanism.
Here's some quick background on GraalVM native images. If you're interested,
great, please read on. If not, please feel free to skip to the end of the
ticket :).
GraalVM is an OpenJDK replacement with an optional, extra component called the
`native-image` compiler. This compiler takes Java applications (`.class` files,
`.jar`s, etc.) and turns them into _very_ quick, operating-system and
architecture-specific binaries that take vanishingly small amounts of memory.
In order to do this trick, it analyses all the code used in your main
application and looks at all the types that your application uses, and then
looks at all the types your code uses and all the types that it uses, etc.
It does this all at compile time. It keeps those types - from the JRE and from
your classpath - and throws away _everything_ else. This is problematic,
however, because it forecloses on the dynamic behavior of the JVM. Things like
reflection, JNI, serialization, reflection, JDK proxies, loading resources from
the classpath, etc., all beak. Unless that is, you furnish some `.json` files
at compile time that tell it about these dynamic things. Then, they work.
Ideally, each library that an application uses would furnish its own
configuration files. These are trivial files that live in each `.jar`s
`META-INF/native-image` directory.
SO: please add these configuration files to your project. They allowed me to
get a moderately sophisticated implementation of the Apache Mina FTP Server
working. [See this example
]([https://github.com/joshlong/spring-integration-aot-smoke-tests/blob/f63ba03bf70132bf9e4adb5b7ae31005d191647d/ftp-root/ftp-server/src/main/java/aot/ftpserver/FtpServerApplication.java)]
(you don't need that except as background for some of the things I attempt.
You can build a native image by installing GraalVM and then running `mvn
-Pnative -DskipTests clean package` in that project)
1: `src/main/resources/META-INF/native-image/reflect-config.json`
```
[
{
"name": "org.apache.mina.transport.socket.nio.NioProcessor",
"queryAllPublicConstructors": true,
"allPublicConstructors": true,
"queryAllDeclaredConstructors": true,
"allPublicClasses": true,
"queryAllDeclaredMethods": true,
"allPublicMethods": true,
"allPublicFields": true,
"allDeclaredMethods": true,
"allDeclaredFields": true,
"queryAllPublicMethods": true,
"allDeclaredConstructors": true,
"allDeclaredClasses": true
}
]
```
2: `src/main/resources/META-INF/native-image/resource-config.json`
```
{
"resources": {
"includes": [
{
"pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus.properties\\E"
},
{
"pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus_en.properties\\E"
},
{
"pattern": "\\Qorg\/apache\/ftpserver\/message\/FtpStatus_zh-tw.properties\\E"
}
]
}
}
```
You can see how I did it in that Apache 2 licensed code I linked you to.
Thank you for your consideration.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]