сб, 10 апр. 2021 г. в 21:50, Rony G. Flatscher (Apache) <r...@apache.org>: > > Is it possible to place and use binaries (including shared libraries) in a > webapp? Very much like > supplying jars to the "lib"-directory? > > Use case: if possible, I would like to create a webapp that includes non-Java > binaries (executable, > image and shared libraries) that get interfaced with via JNI. > > If this is possible then how so? Any pointers/hints would be highly > appreciated!
Hi, Rony! 1) You may look for an inspiration on how Tomcat Navive library is loaded https://tomcat.apache.org/tomcat-9.0-doc/apr.html https://tomcat.apache.org/native-doc/ Note that "64-bit Windows zip" binary distribution includes the library (tcnative-1.dll). https://tomcat.apache.org/download-90.cgi In the source code, look at org.apache.tomcat.jni.Library org.apache.catalina.core.AprLifecycleListener and its message resources, java/org/apache/catalina/core/LocalStrings.properties You may find examples of System.load(), System.loadLibrary(), System.mapLibraryName() calls in the Library class. See also the system property "java.library.path". 2) JVM has a limitation that a library is allowed to be loaded by one classloader only. That is why using a web application classloader looks to be a poor place for loading a library, if you are ever going to use its full features (parallel deployment of several web applications, a reload / redeploy without stopping Tomcat, etc.) See https://tomcat.apache.org/tomcat-9.0-doc/class-loader-howto.html 3) It is possible to load any classes when Apache Tomcat starts: a) with a custom Listener, b) abusing a JreMemoryLeakPreventionListener https://tomcat.apache.org/tomcat-9.0-doc/config/listeners.html c) as a custom resource https://tomcat.apache.org/tomcat-9.0-doc/jndi-resources-howto.html#Generic_JavaBean_Resources HTH. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org