Unable to access jarfile

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Rakshan
User
Beiträge: 4
Registriert: Dienstag 27. Juli 2021, 13:02

Excuse my English, mein Deutsch is nicht gut.

I had a java application which was testing servers. We are migrating to python, and for a start we are making use of the jar from the java application.

I use the jar in my python script, and call the

```
subprocess.call(
['java', '-jar', 'XYZ.jar', '-url', 'opc.tcp://localhost:XXXX', '-check', 'AB', '-specVersion', '2.0', '-test', 'testclient.TestGeneral'])

```
This works perfect!
However, we plan to have a clear structure by using classes(OOP).

So I make some modifications and I write the below

```
class TestClient:

def performTest(self):

subprocess.call(['java', '-jar', 'XYZ.jar', '-url', 'opc.tcp://localhost:XXXX', '-check', 'AB', '-specVersion', '2.0', '-test', 'testclient.TestGeneral'])


if __name__ == "__main__":
client = TestClient()
client.performTest()
```

I get an error saying

```
Error: Unable to access jarfile XYZ.jar
```

How is it that the jar becomes unaccesable? Am i missing something here? Please let me know
Sirius3
User
Beiträge: 17712
Registriert: Sonntag 21. Oktober 2012, 17:20

Methodes are written in Python all lower case: perform_test.
Use only classes, if you really need them. In contrast to Java, you don't have to put everything in classes.

Besides introducing classes you also changed something in running your program. The file XYZ.jar is not in your current working directory.
Rakshan
User
Beiträge: 4
Registriert: Dienstag 27. Juli 2021, 13:02

Thank you for your reply.
I figured out the error. In pycharm IDE, I had not added the working directory for the run configuration. My silly mistake
Benutzeravatar
DeaD_EyE
User
Beiträge: 1012
Registriert: Sonntag 19. September 2010, 13:45
Wohnort: Hagen
Kontaktdaten:

sourceserver.info - sourceserver.info/wiki/ - ausgestorbener Support für HL2-Server
Benutzeravatar
__blackjack__
User
Beiträge: 13006
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

NB: I would use `run()` instead of `call()`. See the documentation for more information. And ``check=True`` so error exit codes are not silently ignored in the Python program.

To second Sirius3: classes are there for a reason, and that reason ist *not* to write simple functions in a more complicated way that they need to be. If you don't use `self` or just have one method besides `__init__()` so `__init__()` basically is just an extra step to get arguments to that one method, there is a good chance you don't really have a use case for a class.
“Most people find the concept of programming obvious, but the doing impossible.” — Alan J. Perlis
Rakshan
User
Beiträge: 4
Registriert: Dienstag 27. Juli 2021, 13:02

Thanks for the suggestion . I had missed adding the directory path for my new run configuration in pycharm. Got it working through that
Antworten