Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Release 4.3.0 - ???
BoilerpipeContentHandler (tika-handler-boilerpipe) is deprecated (TIKA-5054).

SERVER, PIPES AND OPERATIONS
* Forked pipes JVMs default to the parent's own Java (java.home) instead of java on
the PATH, so tika-app, tika-server and PipesForkParser run from a bundled or jlink
runtime with no Java installed. pipes.javaPath still overrides (TIKA-5080).

* The new tika-pipes-qdrant plugin adds a qdrant-emitter. It writes the vectors in
tk:chunks to a Qdrant collection as points, with one named vector per inference
binding, through the Qdrant REST API (TIKA-XXXX).
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
** xref:advanced/embedded-documents.adoc[Embedded Document Metadata]
** xref:advanced/date-handling.adoc[Date Handling]
** xref:advanced/local-vlm-server.adoc[Running a Local VLM Server]
** xref:advanced/jlink-runtime.adoc[Bundling a Java Runtime (Draft)]
** Integration Testing
*** xref:advanced/integration-testing/tika-app.adoc[Testing with Tika App]
*** xref:advanced/integration-testing/tika-server.adoc[Testing with Tika Server]
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/advanced/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ prioritize the gap.
* xref:advanced/embedded-documents.adoc[Embedded Document Metadata] — how Tika tracks embedded documents and their paths
* xref:advanced/date-handling.adoc[Date Handling] — how dates are parsed, stored, and read back since 4.2.0
* xref:advanced/local-vlm-server.adoc[Running a Local VLM Server] — an OpenAI-compatible endpoint for air-gapped OCR
* xref:advanced/jlink-runtime.adoc[Bundling a Java Runtime (Draft)] — shipping Tika with a trimmed `jlink` runtime so no Java install is needed

== Integration testing

Expand Down
150 changes: 150 additions & 0 deletions docs/modules/ROOT/pages/advanced/jlink-runtime.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
= Bundling Tika with Its Own Java Runtime (Draft)

WARNING: This page is a draft. The recipe has been run on Linux x64 with one JDK and a
handful of files; see <<status>> for exactly what has and has not been checked. Treat the
module list as a starting point, not a guarantee, and please report what you find.

Tika needs Java 17 or later, but the people using your application do not have to
install it. `jlink`, which ships with every JDK, builds a trimmed Java runtime holding
only the parts Tika uses. Put that runtime next to the Tika jars and you have one
self-contained directory to ship inside a desktop application or an installer.

This needs Tika 4.3.0 or later. From 4.3.0, the forked JVMs that Tika Pipes starts use
the same Java as the parent by default, so they run from the bundled runtime with no
`java` on the `PATH` (see `javaPath` in xref:pipes/configuration.adoc[Pipeline Configuration]).

== Recipe

Start from the `tika-app` zip and a JDK for the platform you are building for.

[source,bash]
----
unzip tika-app-<version>.zip -d tika

jlink \
--add-modules java.base,java.compiler,java.desktop,java.logging,java.management,java.naming,java.net.http,java.rmi,java.scripting,java.security.jgss,java.sql,java.xml,java.xml.crypto,jdk.unsupported,jdk.charsets,jdk.crypto.ec,jdk.localedata,jdk.zipfs \
--strip-debug --no-header-files --no-man-pages --compress zip-6 \
--output tika/runtime
----

Run Tika with the bundled runtime:

[source,bash]
----
# one file
tika/runtime/bin/java -jar tika/tika-app-<version>.jar -t my-file.docx

# a directory, each file parsed in a forked JVM
tika/runtime/bin/java -jar tika/tika-app-<version>.jar -i <inputDir> -o <outputDir>
----

Starting a JVM costs about a second, so for many files use the directory form or
xref:using-tika/server/index.adoc[Tika Server], not one invocation per file.

== The module list

The first fourteen modules are what `jdeps` reports for the jars in the `tika-app` zip.
The last four are added by hand, because `jdeps` only sees direct code references and
misses what Java loads by name at run time:

[cols="1,3"]
|===
|Module |Why

|`jdk.charsets`
|Legacy encodings beyond the basic set, such as Shift_JIS, GBK, Big5 and EUC-KR.

|`jdk.crypto.ec`
|Elliptic-curve cryptography. Folded into `java.base` in recent JDKs, where naming it is harmless.

|`jdk.localedata`
|Locale data for languages other than English, used when parsing and formatting dates and numbers.

|`jdk.zipfs`
|The zip file system provider.
|===

To recompute the first part of the list for a different Tika version or a different set
of jars:

[source,bash]
----
for jar in tika/lib/*.jar tika/tika-app-<version>.jar; do
jdeps --ignore-missing-deps --multi-release 17 --print-module-deps -q -cp 'tika/lib/*' "$jar"
done | tr ',' '\n' | grep -E '^(java|jdk)\.' | sort -u
----

If you leave a needed module out, the failure is usually silent: text in an unsupported
encoding comes out wrong, or a date in another language is not recognized. When in doubt,
keep the module.

== Size

Measured on Linux x64 with Temurin 25 and Tika 4.3.0-SNAPSHOT:

[cols="2,1"]
|===
|Piece |Size on disk

|Runtime, the eighteen modules above
|76 MB

|Tika jars and plugins
|63 MB
|===

A full JDK is about 300 MB. `java.desktop` (AWT, which the PDF and image code needs) and
`jdk.localedata` are the largest pieces of the runtime.

== Platforms

A `jlink` runtime only runs on the operating system and CPU it was built for. Build one
per target, either on that platform or by pointing `--module-path` at the `jmods`
directory of a JDK downloaded for it. On Windows the launcher is `runtime\bin\java.exe`.

If you sign or notarize your application, the native libraries inside the runtime need
signing too.

A runtime that `jpackage` builds for itself has no `bin/java`. Tika Pipes then falls back
to `java` on the `PATH`. To keep forked parsing self-contained, build the runtime with
`jlink` as above and hand it to `jpackage` with `--runtime-image`.

== Licensing

The Tika jars are Apache License 2.0. An OpenJDK runtime is GPLv2 with the Classpath
Exception; ship the `legal` directory that `jlink` writes into the runtime.

[#status]
== What has been checked

Checked, on Linux x64, with no other Java on the machine's `PATH`:

* Text extraction from `.doc`, `.docx`, `.xls`, `.ppt`, `.pdf`, `.msg`, `.pst` and TNEF
(`winmail.dat`) test files.
* Directory mode with one forked JVM: a file that runs the fork out of memory and a file
that times out each caused a restart, and every other file in the directory was still
extracted.

Not yet checked:

* macOS and Windows.
* Output compared against a full JDK over a large and varied set of files, including
non-English text and legacy encodings. This is the check that would show a missing module.
* Tika Server, shared server mode, OCR and other external tools.
* JDK versions other than 25.
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/pipes/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ how many forked JVMs to run, timeouts, memory management, and parse behavior.
|JVM arguments for forked processes (e.g., `["-Xmx512m", "-Xms256m"]`). Unless you supply your own, Tika auto-injects `-XX:ActiveProcessorCount` to right-size each fork's GC and JIT thread pools, and `-XX:MaxRAMPercentage` to keep the forks' combined heap ceiling under the host's memory; see xref:pipes/cpu-sizing.adoc[Forked-JVM CPU and Heap Sizing]. This is also where the fork's system properties go, e.g. `-Dtika.pipes.cacheMemoryBudgetBytes` below -- setting them on the parent JVM has no effect on the forks.

|`javaPath`
|`java`
|Path to the Java executable for forked processes.
|the running JVM's `java`
|Path to the Java executable for forked processes. Unset, the forks use the same Java installation as the parent (`java.home`), so a bundled or `jlink` runtime needs no `java` on the `PATH`; if that runtime has no `bin/java`, `java` on the `PATH` is used.

|`maxFilesProcessedPerProcess`
|`100000`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ String[] getCommandline(Path tmpDir) throws IOException {
}

List<String> commandLine = new ArrayList<>();
String javaPath = pipesConfig.getJavaPath();
String javaPath = pipesConfig.resolveJavaPath();
commandLine.add(ProcessUtils.escapeCommandLine(javaPath));

if (!hasClassPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static int defaultNumClients() {
private FetchEmitTuple.ON_PARSE_EXCEPTION onParseException = FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT;

private ArrayList<String> forkedJvmArgs = new ArrayList<>();
private String javaPath = "java";
private String javaPath = null;

/** @deprecated since 4.1, removal planned for 5.0; see {@link #setTempDirectory(String)} */
@Deprecated
Expand Down Expand Up @@ -382,6 +382,23 @@ public void setJavaPath(String javaPath) {
this.javaPath = javaPath;
}

/** The configured javaPath, else the running JVM's own java, else {@code java} on the PATH. */
public String resolveJavaPath() {
if (!StringUtils.isBlank(javaPath)) {
return javaPath;
}
String home = System.getProperty("java.home");
if (home != null) {
for (String name : new String[]{"java", "java.exe"}) {
Path java = Paths.get(home, "bin", name);
if (Files.isRegularFile(java)) {
return java.toString();
}
}
}
return "java";
}

/**
* Get the emit strategy configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ private String[] getCommandline() throws IOException {
}

List<String> commandLine = new ArrayList<>();
String javaPath = pipesConfig.getJavaPath();
String javaPath = pipesConfig.resolveJavaPath();
commandLine.add(ProcessUtils.escapeCommandLine(javaPath));

if (!hasClassPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -56,6 +57,17 @@ void testTempDirectoryIsHonored(@TempDir Path tmp) throws Exception {
assertTrue(Files.isDirectory(made));
}

@Test
void testJavaPathDefaultsToRunningJvm() {
PipesConfig config = new PipesConfig();
Path resolved = Paths.get(config.resolveJavaPath());
assertEquals(Paths.get(System.getProperty("java.home"), "bin"), resolved.getParent());
assertTrue(Files.isRegularFile(resolved), resolved.toString());

config.setJavaPath("/opt/jdk/bin/java");
assertEquals("/opt/jdk/bin/java", config.resolveJavaPath());
}

@Test
void testMaxIpcPayloadBytesDefault() {
PipesConfig config = new PipesConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public PipesForkParserConfig addJvmArg(String arg) {
/**
* Set the Java executable path.
*
* Unset by default: the user config file's {@code javaPath}, else {@code java}, applies.
* Unset by default: the user config file's {@code javaPath}, else the running JVM's java, applies.
*
* @param javaPath path to the java executable
* @return this config for chaining
Expand Down