I'm developing collection of monitoring script and templates for zabbix. It's called ZTC and all script are on python.
Now I want to add support for some java monitoring. I've not found the way to do it from CPython - only from java or jython. Since all project is on python, I've decided to write a simple script on jython, which would be called from my cpython classes.
Here is how my code looks like:
#!/usr/bin/env jython
#Java Dependencies
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.lang.management.ManagementFactory;
#Python Dependencies
import sys, cmd, socket
def usage():
print """Usage:
jmxclient.py -h
jmxclient.py <connect_url> <jmx_attribute_path> <jmx_property>"""
class JMXClient:
remote = None
def connect(self, connect_url):
if self.remote:
return True
#Establish Connection to JMX Server
url = javax.management.remote.JMXServiceURL(connect_url);
connector = javax.management.remote.JMXConnectorFactory.connect(url);
self.remote = connector.getMBeanServerConnection();
def getAttribute(self, mbean_path, attribute):
"""Query the mbean server for a specific attribute and return the
result"""
obn = javax.management.ObjectName(mbean_path);
result = self.remote.getAttribute(obn, attribute);
return result
if len(sys.argv) <= 1:
usage()
sys.exit(2)
if sys.argv[1] in ('-h', '--help'):
usage()
sys.exit(2)
if len(sys.argv) <> 4:
usage()
sys.exit(2)
(connect_url, mbean_path, attribute) = sys.argv[1:]
j = JMXClient()
j.connect(connect_url)
print j.getAttribute(mbean_path, attribute)
Ok, now I'm trying to get some attribute from terracotta server. It uses jmxmp with url service:jmx:jmxmp://0.0.0.0:9520.
So, I'm running my script as follows:
$ ./jmxclient.py service:jmx:jmxmp://localhost:9520 java.lang.ClassLoading LoadedClassCount
Traceback (innermost last):
File "./jmxclient.py", line 87, in ?
File "./jmxclient.py", line 61, in connect
at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:327)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:207)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.net.MalformedURLException: java.net.MalformedURLException: Unsupported protocol: jmxmp
(line numbers not relevant due to some stripped comments)
How do I add support of this jmxmp protocol?
I've found that it seems it might be enabled by jmxremote_optional.jar. How do I add this jar to my jython (pref. not system-wide)?
UPDATE:
As suggested, I've added jmxremote_optional.jar and jmxremote.jar from jmxremote-1_0_1-ri-bin-b58.zip reference implementation: jython -Djava.endorsed.dirs=. -Dpython.path=.../jmxremote_optional.jar:.../jmxremote.jar:.../jmissl.jar jmxclient.py service:jmx:jmxmp://localhost:9520 java.lang.ClassLoading LoadedClassCount, but still getting the same error. I'm sure that jmxremote_optional.jar is in classpath, and code seems to be very similar to reference examples.
After reading api docs, I've tried following changes:
url = javax.management.remote.JMXServiceURL('jmxmp', 'localhost', 9520);
connector = javax.management.remote.jmxmp.JMXMPConnector(url)
connector.connect()
self.remote = connector.getMBeanServerConnection();
which leads me to another exception:
Traceback (innermost last):
File "../src/jmxclient.py", line 87, in ?
File "../src/jmxclient.py", line 61, in connect
at com.sun.jmx.remote.opt.security.AdminClient.connectionOpen(AdminClient.java:209)
at com.sun.jmx.remote.generic.ClientSynchroMessageConnectionImpl.connect(ClientSynchroMessageConnectionImpl.java:72)
at javax.management.remote.generic.GenericConnector.connect(GenericConnector.java:177)
at javax.management.remote.jmxmp.JMXMPConnector.connect(JMXMPConnector.java:119)
at javax.management.remote.generic.GenericConnector.connect(GenericConnector.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.io.IOException: java.io.IOException: javax.management.remote.message.HandshakeBeginMessage
Jython version is 2.2 and I don't like to use later version, because this scripts is mostly being used on RHEL5 boxes, and they only have jython 2.2.1.
PS: marking question as answered, because I've decided to give up and use jmxterm or similar tool, which all seems to work with jmxmp by just adding -Djava.endosed.dirs=/path/to/dir_with_jmxremote_optional/.
But I'd still like to see jython solution.
Man, I read that post about 7 times .....
Anyways, here's what I think is going on. The jmxmp protocol is not packaged in the standard J2SE runtime. See this page. To quote:
Note – If you want to use a JMXMP connector, download the JSR 160 Reference Implementation from http://java.sun.com/products/JavaManagement/download.html, and add the jmxremote_optional.jar file to your classpath. You will find examples of use of the JMXMP connectors in the JMX Remote API Tutorial included with the JSR 160 Reference Implementation.
I'm not that familiar with jython, but it looks like this post should hook you up.
I've faced the same problem. The solution is to use a different method of importing jar jmxremote_optional.jar. It's described here https://stackoverflow.com/a/11638390/9209536
This code works in Jython 2.7
def importJar(jarFile):
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
m.invoke(ClassLoader.getSystemClassLoader(), [File(jarFile).toURL()])
importJar("opendmk_jmxremote_optional_jar-1.0-b01-ea.jar")
from javax.management.remote import JMXServiceURL
from javax.management.remote import JMXConnector
from javax.management.remote import JMXConnectorFactory
jmx_url = JMXServiceURL("service:jmx:jmxmp://server:port/")
jmx_connector = JMXConnectorFactory.connect(jmx_url)
Another option could be to use a different stack like Jolokia which exports JMX information via HTTP and JSON. There a already various client binding (Perl via Jmx4Perl, Javascript, Java) although no Python yet. But it shouldn't be hard to build one from scratch, the protocol is described in detail here.
Related
We are successfully using the AmazonPay API for Java (amazon-pay-api-sdk-java-2.2.2.jar) in Adobe ColdFusion. We recently introduced Lucee (on Jetty, also running on OpenJDK 8) and attempted to run the same code (relevant excerpt):
payConfig = createObject("java", "com.amazon.pay.api.PayConfiguration").init();
payConfig.setPrivateKey("...");
However, upon calling setPrivateKey, which will arrive at Security.addProvider(new BouncyCastleProvider()); through PayConfiguration, we receive a java.lang.ClassNotFoundException:
lucee.runtime.exp.NativeException: org.bouncycastle.jce.provider.BouncyCastleProvider
at com.amazon.pay.api.PayConfiguration.setPrivateKey(PayConfiguration.java:77)
[...]
at java.lang.Thread.run(Thread.java:823)
Caused by: java.lang.NoClassDefFoundError: org.bouncycastle.jce.provider.BouncyCastleProvider
... 57 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider not found by amazon.pay.api.sdk.java.2.2.2 [49]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.lang.ClassLoader.loadClass(ClassLoader.java:881)
... 57 more
We have placed all dependencies (bcprov-jdk15on-1.65.jar being BouncyCastle) in /lucee-server/context/lib. Creating BouncyCastleProvider within a .cfm/.cfc does work as expected:
createObject("java", "org.bouncycastle.jce.provider.BouncyCastleProvider").init()
I don't understand what Lucee's classloader is doing here. What am I missing?
I don't know what Lucee's classloader is doing either to be honest, but this kind of error seems to be quite common when loading certain more complex jars via the Lucee /lib path. It's likely there are "class clashes" going on somewhere.
Lucee is now OSGi based which means the best way of avoiding this is to load third-party java libraries as OSGi bundles. Some libraries are already packaged for OSGi and others can be converted fairly easily. More details here.
The Amazon library doesn't seem to be OSGi friendly, although it could probably be converted without too much effort.
For now, I would look at JavaLoader as the simplest way of getting it working. I don't have any valid Amazon keys to test fully with, but using JavaLoader I was able to at least call the payConfig.setPrivateKey() method without getting a ClassNotFoundException error.
I'm getting an InvalidJarIndexException when trying to utilize Jython standalone JAR inside my application and I'm unable to figure out what I'm doing wrong.
As soon as I attempt to execute a Python script with an import statement for any Java class from a package starting with "com.", e.g.: "com.foo.Bar", the following exception is thrown (truncated):
Traceback (most recent call last):
File "<string>", line 1, in <module>
sun.misc.InvalidJarIndexException: Invalid index
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1152)
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1062)
at sun.misc.URLClassPath$JarLoader.findResource(URLClassPath.java:1032)
at sun.misc.URLClassPath.findResource(URLClassPath.java:225)
at java.net.URLClassLoader$2.run(URLClassLoader.java:572)
at java.net.URLClassLoader$2.run(URLClassLoader.java:570)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:569)
at java.lang.ClassLoader.getResource(ClassLoader.java:1089)
at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:233)
at org.python.core.ClasspathPyImporter.tryClassLoader(ClasspathPyImporter.java:221)
at org.python.core.ClasspathPyImporter.makeEntry(ClasspathPyImporter.java:208)
at org.python.core.ClasspathPyImporter.makeEntry(ClasspathPyImporter.java:18)
at org.python.core.util.importer.getModuleInfo(importer.java:174)
at org.python.core.util.importer.importer_find_module(importer.java:98)
at org.python.core.ClasspathPyImporter.ClasspathPyImporter_find_module(ClasspathPyImporter.java:134)
at org.python.core.ClasspathPyImporter$ClasspathPyImporter_find_module_exposer.__call__(Unknown Source)
at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:48)
at org.python.core.imp.find_module(imp.java:761)
at org.python.core.imp.import_next(imp.java:1158)
at org.python.core.imp.import_module_level(imp.java:1350)
at org.python.core.imp.importName(imp.java:1528)
at org.python.core.ImportFunction.__call__(__builtin__.java:1285)
at org.python.core.PyObject.__call__(PyObject.java:433)
at org.python.core.__builtin__.__import__(__builtin__.java:1232)
at org.python.core.imp.importOneAs(imp.java:1564)
at org.python.pycode._pyx0.f$0(<string>:1)
at org.python.pycode._pyx0.call_function(<string>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1687)
at org.python.core.Py.exec(Py.java:1731)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:268)
at com.so.Script.execute(Script.java:20)
Here's all I'm doing in my code (I'm actually invoking this via a Swing action on a JMenuItem calling new Script().execute(), which is most likely irrelevant):
package com.so;
import org.python.core.PyDictionary;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;
public class Script {
public Script() {
}
public void execute() {
PyDictionary table = new PyDictionary();
PySystemState state = new PySystemState();
PythonInterpreter interp = new PythonInterpreter(table, state);
String script;
script = "" +
"import com.foo.Bar as Bar\n" +
"";
interp.exec(script);
}
}
It doesn't even matter that there is no such package/class in my classpath. But what baffles me the most is that when I, thinking this has to be classpath related, created a separate mock project with the exact same classpath (same JAR files from the same locations on disk), the other project works just fine when run and it executes the actual script.
What could I be doing wrong here?
This happens with Java 1.8u241 (x64) and both jython-standalone-2.7.2.jar and an earlier 2.7.1 version. The ClassLoader in the stack trace is attempting to resolve "com".
I found the culprit entirely by accident.
My broken project used an older (ancient) version of the Glazed Lists library, namely glazedlists-1.8.0_java15.jar. This JAR seems to be directly incompatible with jython-standalone-2.7.2.jar. As soon as you put them on the same classpath and attempt to execute a python script, which imports any Java package starting with "com.", you end up with an InvalidJarIndexException. Updating to a newer version of said JAR resolved the issue.
Therefore, if you encounter a similar exception trying to run Jython, I suggest you update all dependencies of your project to latest or newer versions of them. In fact this would probably be the solution, even if not using Jython at all.
I want to do a small test with a nanoCUL868 USB device in order to transmit some signal to remote devices. The stick works with some 3rd party software and I was able to communicate with the remote device. I now want to test this stick with the following code in JAVA:
package de.saltest.home;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Logger;
import org.openmuc.jrxtx.Parity;
import org.openmuc.jrxtx.SerialPort;
import org.openmuc.jrxtx.SerialPortBuilder;
public class SomfyCULTest {
private static final Logger log = Logger.getLogger(SomfyCULTest.class.getName());
public static void main(String[] args) throws IOException {
log.info("Opening port ttyUSB0");
SerialPort port = SerialPortBuilder.newBuilder("/dev/ttyAMA0").setBaudRate(9600).setParity(Parity.NONE).build();
OutputStream out = port.getOutputStream();
String commandLEDOn = "l01\n";
String commandLEDOff = "l00\n";
String encryptionKey = "A1";
// C - Command (1 = My, 2 = Up, 4 = Down, 8 = Prog)
String command = "2";
String rollingCode = "001D";
String address = "000029";
String somfyCommand = "Ys" + encryptionKey + command + "0" + rollingCode + address + "\n";
out.write(somfyCommand.getBytes());
out.close();
port.close();
log.info("Closed port");
}
}
I have installed Oracle Java on a Rasperry Pi 3 and also got the librtrx-java via apt-get. A dpkg-query -L librxtx-java yields:
/usr/lib/jni/librxtxRS485.so
/usr/lib/jni/librxtxRaw.so
/usr/lib/jni/librxtxI2C.so
/usr/lib/jni/librxtxParallel.so
/usr/lib/jni/librxtxSerial.so
/usr/share/java/RXTXcomm.jar
So, I assume those libraries are correctly installed for the right platform.
If I use javac to compile my code:
I get the following error message:
javac -classpath /usr/lib/jni -cp /usr/share/java/RXTXcomm.jar:. src/main/java/de/saltest/home/SomfyCULTest.java
src/main/java/de/saltest/home/SomfyCULTest.java:7: error: package org.openmuc.jrxtx does not exist
import org.openmuc.jrxtx.Parity;
^
I have also a maven project which compiles fine using this code, however, I cant execute it because of the following error:
mvn exec:java -Dexec.mainClass=de.saltest.home.SomfyCULTest
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) # serialTest ---
Okt 07, 2018 3:25:41 PM de.saltest.home.SomfyCULTest main
INFORMATION: Opening port ttyUSB0
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:85)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:104)
at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
at de.saltest.home.SomfyCULTest.main(SomfyCULTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(Thread.java:748)
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
From here I'm lost. I have tried many things like copying libraries to different places like suggested in some other posts. I have also changed the classpath and many other things I could think of. However, nothing seems to work. The only thing I find strange is that I try to use java.io. but the code tries to load gnu.io. May be there is some mismatch?
Any help or solution is really appreciated.
Thanks!
What seems to be the solution is to add a plugin to the maven build which produces a JAR with all dependencies included. Like described here: https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/
However, what's still odd, you have to add the library path like mentioned above:
-Djava.library.path=/usr/lib/jni
For my understanding this should not be necessary anymore. Nevertheless, without the path it is not working.
Did you try to add the native path of the library as start parameter:
-Djava.library.path=/usr/lib/jni
I face the same issue, for resolve the issues, steps that worked for me
Step1. add RXTXcomm.jar and RXTXcomm-2.2pre2.jar in JAVA_HOME/jre/lib/ext
Step2:- create war file using eclipse or anything
Step3: On the client environment these jar should be store in same location
Step4: Add RXTXcomm.jar and RXTXcomm-2.2pre2.jar in JAVA_HOME/jre/lib/ext of client environment.
Note:- If you not geting the data from serial device then check locks on the serial port, It may be other thread or process already occupied or not release the lock.
For checking locks on port,
command is fuser /dev/ttyS0 then
kill -9 PID
I hope this will be work.
Working with centos7
I am trying to install Matlab on a Linux machine, but setting LD_LIBRARY_PATH (as the installation requires) breaks other library files. I am not an Linux expert, but I have tried several things and cannot get it working correctly. I have even contacted Matlab support, got the issue elevated to the dev team, and was basically told "haha sucks to suck". I have seen a few other people online have had the same issue, but either their questions were never answered or they had a slightly different problem and their solution didn't apply to me.
Installing on a VM running Ubuntu:
I set LD_LIBRARY_PATH as the instructions say, then it breaks network files. I can ping google.com, but I cannot nslookup google.com or visit it in a browser. Nslookup provides this error:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)
03-Feb-2016 11:32:22.361 ENGINE_by_id failed (crypto failure)
03-Feb-2016 11:32:22.362 error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
03-Feb-2016 11:32:22.363 error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:447:
03-Feb-2016 11:32:22.363 error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:418:id=gost
(null): dst_lib_init: crypto failure
The installation worked though (I can run my Java programs that reference compiled Matlab functions). Unsetting LD_LIBRARY_PATH fixes the network files but then I can't run programs anymore.
Installing on EC2 instance:
On an EC2 instance it does not break the network files (nslookup is fine). Instead it messes up Python library files. Trying to use any aws cli command, I get the error:
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
File "/usr/lib/python2.7/dist-packages/awscli/clidriver.py", line 16, in <module>
import botocore.session
File "/usr/lib/python2.7/dist-packages/botocore/session.py", line 25, in <module>
import botocore.config
File "/usr/lib/python2.7/dist-packages/botocore/config.py", line 18, in <module>
from botocore.compat import six
File "/usr/lib/python2.7/dist-packages/botocore/compat.py", line 139, in <module>
import xml.etree.cElementTree
File "/usr/lib64/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"
Printing sys.path in Python shows lib-dynload is already there though, so it doesn't seem to the problem.
And when trying to run the program, I get:
Exception in thread "main" java.lang.LinkageError: libXt.so.6: cannot open shared object file: No such file or directory
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.dlopen(Native Method)
at com.mathworks.toolbox.javabuilder.internal.DynamicLibraryUtils.loadLibraryAndBindNativeMethods(DynamicLibraryUtils.java:134)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1529)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:48)
at VectorAddExample.VectorAddExampleMCRFactory.newInstance(VectorAddExampleMCRFactory.java:59)
at VectorAddExample.VectorAddClass.<init>(VectorAddClass.java:62)
at com.mypackage.Example.main(Example.java:13)
I'm at a brick wall and really have no clue how to proceed.
Maybe something else already needs LD_LIBRARY_PATH set to work. Make sure you prepend not overwrite:
export LD_LIBRARY_PATH=new/path:$LD_LIBRARY_PATH
Edit:
OK, if LD_LIBRARY_PATH was initially empty, this suggests that Matlab comes with shared libraries that are incompatible with your system ones:
nslookup: /usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64/libcrypto.so.1.0.0: no version information available (required by /usr/lib/libdns.so.100)
suggests that /usr/lib/libdns.so.100 needs libcrypto.so.1.0.0, which is now being resolved to the one that comes with MATLAB, which is incompatible.
You can check the dependencies of a dll by
ldd /usr/lib/libcrypto.so.1.0.0
and hopefully you can find a configuration that keeps both MATLAB and your system happy. Unfortunately, this may involve a lot of trial and error.
If there is no such configuration, you can try setting LD_LIBRARY_PATH only when you run MATLAB:
LD_LIBRARY_PATH=$MATLAB_LD_LIBRARY_PATH matlab
Edit 2:
Well, for the Python issue, it seems to boil down to pyexpat, which is a wrapper around the standard expat XML parser. Try doing (name guessed since I don't have a Linux right now):
ldd /usr/local/lib/python2.7/site-packages/libpyexpat.so
and see what that depends on. Probably, it will be libexpat.so, which is now being resolved to MATLAB's version.
try the following command:
export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os‌​/glnxa64:$LD_LIBRARY_PATH
Perhaps not helpful for OP but if you are generating a python package with MATLAB, you could modify the generated __init__.py file MATLAB creates for your package.
Specifically, the generated __init__.py file contains the following line (as of MATLAB 2017a):
PLATFORM_DICT = {'Windows': ['PATH','dll',''], 'Linux': ['LD_LIBRARY_PATH','so','libmw'], 'Darwin': ['DYMCR_LIBRARY_PATH','dylib','libmw']}
For Linux platform, you could simply replace LD_LIBRARY_PATH with something else such as MCR_LIBRARY_PATH to prevent mucking with your shared libs.
sed -i -e 's/LD_LIBRARY_PATH/MCR_LIBRARY_PATH/g' /MY/PACKAGE/BUILD/PATH/__init__.py
Then obviously export MCR_LIBRARY_PATH before using python.
I am having trouble setting up the Php-Java Bridge setup properly.
I will explain what I have done.
My site is in pure php
For our payment transaction process we need to set up a php-java bridge
I followed this link to setup the bridge PHP-JAVA BRIDGE INSTALATION.
Here I learned that I need to have a private jvm to install the bridge.
So 1st i installed apache-tomcat-6.0.14 in Private JVM using my c-panel. After instalation it asked me to Map a domain to private JVM. So I mapped my domain example.com (which is the only option available) to it.
Then it asked to enable a traffic redirection from Apache web server to my Java application server (there was a check box and i clicked it)
Finally it asked me to deploy the WAR File (JavaBridge.WAR was my file) and everthing seems fine
Now when i go to http://example.com/JavaBridge/ I could see the javabridge examples and it works fine.
SO FAR SO GOOD
Now my problem starts here when I try to access a java class file from php. A sample test.php is what I create and put the following code into it.
<?php
require_once("http://example.com:portnumber/JavaBridge/java/Java.inc");
$System = java("java.lang.System");
echo $System->getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly
$path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder
java_require($path_e24class);
$pipe = new Java("e24PaymentPipe");
$pipe->setAction("1");
?>
My site contents reside in the public_html folder and the WAR file are deployed in private jvm.
These are the error message am getting.
1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM: 1.6.0_22#http://java.sun.com/" at: #-10
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8
java.lang.Class.forName0(Native Method) #-7
java.lang.Class.forName(Class.java:247) #-6
php.java.bridge.Util.classForName(Util.java:1518) #-5
php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4
php.java.bridge.Request.handleRequest(Request.java:458) #-3
php.java.bridge.Request.handleRequests(Request.java:500) #-2
php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1
php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0
http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1
Finally I don't know much about the java. So am stuck here not knowing what to do.
Here is a great step by step tutorial you can follow, which shows everything required! It is a little old (2007) but helped me a while ago.
There is also another option. You can install Apache Tomcat and deploy your war there. You can have even multiple tomcat instances simultaneously with your httpd running at the same time on the same machine, as long as you respect the port settings. You can even front them with Apache httpd.
you can try this:
package your code to jar, and copy it to java.ext.dirs which you can found in JavaBridge.log
copy the related class libraries to java.ext.dirs
restart the service of JavaBridge
good luck!
<?php require_once("JavaBridge/java/Java.inc");
try {
$hd = new java("hdfs.HDFS");
$hd->get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png");
} catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "<br>\n";}
?>
You can use this php implementation on github that works with php 5.3.
See credits on the git readme for more information.
You can try this; put the JavaBridge.jar in tomcat's lib folder e.g. apache-tomcat-7.0.12/lib.
Restart tomcat server and then,
$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe");
$pipe->setAction("1");
This way I created the php version of the object.
Why don't you put the e24PaymentPipe class in your Java application's classpath and skip the two lines below:
// $path_e24class = getcwd(). '/e24PaymentPipe.class';
// java_require($path_e24class);
$pipe = new java("fully.qualified.classpath.e24PaymentPipe");
You are mixing PHP side and Java side operations. in theory the java_require (which is deprecated) was designed to work on the Java side. You are specifying a PHP side path.
You can save yourself a lot of grief by using a pure PHP implementation of the e24PaymentPipe library.
Disclaimer
The link is to my github repo of the library, but I did not write it. See the readme in for original credits.