Skip to content

Commit 251bfed

Browse files
committed
- fix classpath use
1 parent f26a7c5 commit 251bfed

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,29 @@ running and omit printing the check messages.
126126
Changing the Tika Classpath
127127
---------------------------
128128
You can update the classpath that Tika server uses by
129-
setting
130-
```python
131-
import tika
132-
tika.TikaServerClasspath = '/tmp/keys'
133-
```
129+
setting the classpath as a set of ':' delimited strings.
130+
For example if you want to get Tika-Python working with
131+
[GeoTopicParsing](http://wiki.apache.org/tika/GeoTopicParser),
132+
you can do this, replace paths below with your own paths, as
133+
identified [here](http://wiki.apache.org/tika/GeoTopicParser)
134+
and make sure that you have done this:
134135

135-
Then, kill Tika server:
136+
kill Tika server (if already running):
136137

137138
```bash
138139
ps aux | grep java | grep Tika
139140
kill -9 PID
140141
```
141142

142-
Then, try Tika, and you should see the new classpath.
143+
```python
144+
import tika.tika
145+
import os
146+
from tika import parser
147+
home = os.getenv('HOME')
148+
tika.tika.TikaServerClasspath = home + '/git/geotopicparser-utils/mime:'+home+'/git/geotopicparser-utils/models/polar'
149+
parsed = parser.from_file(home + '/git/geotopicparser-utils/geotopics/polar.geot')
150+
print parsed["metadata"]```
151+
143152

144153
New Command Line Client Tool
145154
============================

tika/tika.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@
125125
'TIKA_TRANSLATOR',
126126
"org.apache.tika.language.translate.Lingo24Translator")
127127
TikaClientOnly = os.getenv('TIKA_CLIENT_ONLY', False)
128-
129-
TikaServerClasspath = os.getenv('TIKA_SERVER_CLASSPATH', "")
128+
TikaServerClasspath = os.getenv('TIKA_SERVER_CLASSPATH', '')
130129

131130
Verbose = 0
132131
EncodeUtf8 = 0
@@ -311,12 +310,15 @@ def getConfig(option, serverEndpoint=ServerEndpoint, verbose=Verbose, tikaServer
311310

312311

313312
def callServer(verb, serverEndpoint, service, data, headers, verbose=Verbose, tikaServerJar=TikaServerJar,
314-
httpVerbs={'get': requests.get, 'put': requests.put, 'post': requests.post}, classpath = TikaServerClasspath):
313+
httpVerbs={'get': requests.get, 'put': requests.put, 'post': requests.post},classpath=None):
315314
"""Call the Tika Server, do some error checking, and return the response."""
316315

317316
parsedUrl = urlparse(serverEndpoint)
318317
serverHost = parsedUrl.hostname
319318
port = parsedUrl.port
319+
if classpath is None:
320+
classpath = TikaServerClasspath
321+
320322
global TikaClientOnly
321323
if not TikaClientOnly:
322324
serverEndpoint = checkTikaServer(serverHost, port, tikaServerJar, classpath)
@@ -343,8 +345,10 @@ def callServer(verb, serverEndpoint, service, data, headers, verbose=Verbose, ti
343345
return (resp.status_code, resp.text)
344346

345347

346-
def checkTikaServer(serverHost=ServerHost, port = Port, tikaServerJar=TikaServerJar, classpath = TikaServerClasspath):
348+
def checkTikaServer(serverHost=ServerHost, port = Port, tikaServerJar=TikaServerJar,classpath=None):
347349
"""Check that tika-server is running. If not, download JAR file and start it up."""
350+
if classpath is None:
351+
classpath = TikaServerClasspath
348352
urlp = urlparse(tikaServerJar)
349353
serverEndpoint = 'http://%s:%s' % (serverHost, port)
350354
jarPath = os.path.join(TikaJarPath, 'tika-server.jar')
@@ -374,14 +378,17 @@ def checkJarSig(tikaServerJar, jarPath):
374378
return existingContents == m.hexdigest()
375379

376380

377-
def startServer(tikaServerJar, serverHost = ServerHost, port = Port, classpath = TikaServerClasspath):
381+
def startServer(tikaServerJar, serverHost = ServerHost, port = Port, classpath=None):
382+
if classpath is None:
383+
classpath = TikaServerClasspath
384+
378385
host = "localhost"
379386
if Windows:
380387
host = "0.0.0.0"
381388

382-
if classpath :
389+
if classpath:
383390
classpath += ":" + tikaServerJar
384-
else :
391+
else:
385392
classpath = tikaServerJar
386393

387394
cmd = 'java -cp %s org.apache.tika.server.TikaServerCli --port %i --host %s &' % (classpath, port, host)

0 commit comments

Comments
 (0)