Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jpype.imports not working accroding on linux user #1183

Open
juszynsk opened this issue Apr 29, 2024 · 3 comments
Open

jpype.imports not working accroding on linux user #1183

juszynsk opened this issue Apr 29, 2024 · 3 comments

Comments

@juszynsk
Copy link

I have problem with usage of jpype.imports on my linux docker environment. I am trying to load activemq client jar file using below code:

import os
import jpype
import jpype.imports

classpath = f'{str.join(":", ["/home/ubuntu/Desktop/tests/jars/"+name for name in os.listdir("/home/ubuntu/Desktop/tests/jars")])}'
jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", ('-Djava.class.path=' + classpath))

import org.apache.activemq.command.ActiveMQTextMessage as TextMessage
text_message = TextMessage()
print(text_message)

When I am using non root user account I receive:

ModuleNotFoundError: No module named 'org.apache'

but when I use root account than everything is fine and I receive java class object:

ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = null, originalDestination = null, originalTransactionId = null, producerId = null, destination = null, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = false, type = null, priority = 0, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false, text = null}

When I use non-root user account I am still able to load class using jpype.JClass like below:

jclass = jpype.JClass("org.apache.activemq.command.ActiveMQTextMessage")
print(jclass())

Could You help me , am I missing something ?

@Thrameos
Copy link
Contributor

You should print the class path using

import jpype
jpype.startJVM(classpath=("directory_with_jars/*", "another_directory_with_jars/*"))
print(jpype.java.lang.System.getProperty("java.class.path"))

@juszynsk
Copy link
Author

Running below code:

jpype.startJVM(classpath=("/home/ubuntu/Desktop/tests/jars/*"))
print(jpype.java.lang.System.getProperty("java.class.path"))

On both users I receive

/home/ubuntu/Desktop/tests/jars/activemq-all.jar

@Thrameos
Copy link
Contributor

Thrameos commented May 1, 2024

Does activemq-all contain orge.apache? If not then there is your problem. If the classpath does not contain all the required Jars it can't possibly work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants