@@ -727,28 +727,40 @@ private static PipesParsingHelper initPipesParsingHelper(TikaServerConfig tikaSe
727727
728728 /**
729729 * Resolves the default plugins directory. Looks for a "plugins" directory
730- * next to the running jar first, then falls back to the current working directory.
730+ * next to the jar this class was loaded from, then next to that directory's
731+ * parent (the class may live in a "lib" directory beside the server jar),
732+ * then in the current working directory. Always returns an absolute path,
733+ * so the forked pipes server does not depend on its own working directory.
731734 */
732735 private static String resolveDefaultPluginsDir () {
736+ Path codeSourceDir = null ;
733737 try {
734738 Path jarPath = Path .of (
735739 TikaServerProcess .class .getProtectionDomain ()
736740 .getCodeSource ().getLocation ().toURI ());
737- Path jarDir = jarPath .getParent ();
738- if (jarDir != null ) {
739- Path pluginsNextToJar = jarDir .resolve (DEFAULT_PLUGINS_DIR );
740- if (Files .isDirectory (pluginsNextToJar )) {
741- return pluginsNextToJar .toAbsolutePath ().toString ();
742- }
743- }
741+ codeSourceDir = jarPath .getParent ();
744742 } catch (Exception e ) {
745- // Fall through to cwd-relative
743+ // no code source, probe the working directory only
746744 }
747- Path cwdPlugins = Path .of (DEFAULT_PLUGINS_DIR );
748- if (Files .isDirectory (cwdPlugins )) {
749- return cwdPlugins .toAbsolutePath ().toString ();
745+ return resolveDefaultPluginsDir (codeSourceDir , Path .of ("" )).toString ();
746+ }
747+
748+ // package-private for testing
749+ static Path resolveDefaultPluginsDir (Path codeSourceDir , Path cwd ) {
750+ if (codeSourceDir != null ) {
751+ Path nextToJar = codeSourceDir .resolve (DEFAULT_PLUGINS_DIR );
752+ if (Files .isDirectory (nextToJar )) {
753+ return nextToJar .toAbsolutePath ();
754+ }
755+ Path parent = codeSourceDir .getParent ();
756+ if (parent != null ) {
757+ Path nextToParent = parent .resolve (DEFAULT_PLUGINS_DIR );
758+ if (Files .isDirectory (nextToParent )) {
759+ return nextToParent .toAbsolutePath ();
760+ }
761+ }
750762 }
751- return DEFAULT_PLUGINS_DIR ;
763+ return cwd . resolve ( DEFAULT_PLUGINS_DIR ). toAbsolutePath () ;
752764 }
753765
754766 /**
0 commit comments