Embedded Python in Java / Coldfusion? - java

I've been trying to excute a Python script from Java or Coldfusion framework (which runs on a JVM), The most documented solution is Jython but it only runs on Python 2.7 which is a problem because I need to use some librairies that runs only on Python 3 .
The JEP (https://github.com/ninia/jep) / JPY (https://github.com/bcdev/jpy) repositories on github really fits my needs but they are not quite responsives to the Github issues .
Has anyone ever done something similar before ?

Unless you really need to embed jython into your application, you may execute a system command (e.g. run a python script) from Java using the method described here.

The issue with Jep wasn't any syntax error, for example jep.eval(' some Python code'); was supposed to run that Python code in Java, If your system environement is well configured then what's left to do is to redirect use Jep's Python redirect_stream() function to redirect the flow of your IDE, worked for me finally .

Related

Can I use MySQL from AWS Lambda in Python?

Is the MySQL connector for Python or some equivalent module available in a form I can zip up and included in an AWS Lambda function, or is that just asking for trouble? Apparently Lambda functions written in Node.js can use a builtin library to talk to MySQL on RDS, but I don't see an obvious way to do that in Python.
I wouldn't want to try to install something that takes a long time or requires any assumptions about the underlying operating system. On Windows at least, it's a whole separate installer.
Same question for Java: does this work out of the box, or are there machinations necessary to package a MySQL jar file?
If in some cases you need to uses native library (which mysql should have), you can uses pure python implementation using PyMySQL, and include it in the deployment package of lambda.
More detail on how to create deployment package for python is here https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
See the advanced version.
For java, I guess it will work out of the box as long as you include all dependency in jar.
I think I got it. Being on Windows added some steps.
I got Python 2.7.10, which comes with Pip. I then installed mysql-connector-python using the trick here.

Debugging between JRuby and Java

I have a large Java project that uses some Ruby scripts (primarily because of Ruby's support for "yield"). The Ruby code calls Java code which calls more Ruby code. It's very interleaved, but everything is driven from Java.
I'm using embedded jruby-standalone and building a jar-with-dependencies (via maven). I'm using a maven plugin to run jrubyc and generate .java files which maven compiles for me.
When I run the jar-with-dependencies, I can attach my debugger to the Java process with no problems, but I'd really love to be able to debug the Ruby code. Is there a solution for this?
I'm not launching any kind of jruby executable to which I could attach arguments. It's embedded in the jar and invoked via java -jar.
You could use the gem pry-remote.
Unlike pry, it does not require the process to be launched from a terminal (or a terminal emulator if you're on Windows).
It's not really a debugger per se, but if you add binding.remote_pry in your code where you wish to observe and react within that context (you could for example catch an exception), this would put pry in waiting mode for a remote connection, and from another terminal you should be able to connect to this process and debug it.
2 minutes hands-on tutorial is available here.
Drawbacks:
you cannot have 2 pry remote sessions.
your code must contain the right 'debugging' condition
I use this in pre-deployment environments when developing web apps with jruby, h2 and jetty server.
Good luck!

Is there a way to run a Java Applet in node.js, at server side?

Is there a way to run a Java Applet in node.js, at server side?
It may sound crazy, but I am looking for a way to run a third party java applet on my node.js app server.
It is used to do a weird calculation that I am not willing to migrate to JavaScript code. Is this possible in any way? Any suggestions? I am in need to send the result of this calculation as a web page to the user, based on a request param.
I was initially thinking of how can I communicate between node.js and an Java Applet running standalone. Googled a bit but no success at all. Can someone suggest how to better google for it or point some good resources???
Using JNI will not help you as applets will not run in a headless environment. Applets are directly dependant on AWT so require a GUI environment to run.
Presuming that the license issues of the applet allow you to reuse the code, then my solution is to decompile the classes for the applet and use the generated java to create a normal java class with main that will run the desired calculations and return the result.
Unless the code is obfuscated, it's relatively simple to understand the decompiled code and should be relatively painless to adapt for what you wish to do.
Once you have your java code working from the command line you can then use the node-java project to call the java code from node.js and get your result.

Definitive fool-proof steps for 0MQ / ZeroMQ and Java on Windows 7?

I've been trying to use 0MQ in my Windows dev environment with Java but I'm having a very difficult experience. It appears there are many issues with PATHs being inconsistent and the Visual Studio command prompt uses a different version of Java than the command prompt where I run my application. The inconsistencies don't stop there, and I feel like I'm not approaching this correctly.
So instead of trying to patch this process, has anyone successfully used ZeroMQ on Windows 7 64-bit and what steps and software stack did you use so that you can run a Java application locally?
Thanks for the help!
I've used zmq with F# on Win7/64bit; it's very easy to make it work there.
As for the Java side of things, I found this documentation: http://www.zeromq.org/bindings:java
and
https://github.com/zeromq/jzmq which is the official binding.

What's the recommended way of running Java from PHP 5.2?

I want to call Java from PHP 5.2, running either on a webserver or from a command line script.
From PHP 4, this seems to be simple, and just involves installing the PECL Java extension.
Example code from the PHP 4 extension:
<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br />';
?>
However, this extension doesn't exist on PHP 5.
What is the closest alternative for PHP 5?
edit:
Really I'm looking for an interface similar to either a C PHP extension or to that provided by the PHP 4 Java extension. The Java program is fairly small and only needs to retain a small amount of state between calls and doesn't need to run asynchronously. The PHP script would only be running a small number of instances simultaneously.
This would also need to be deployed to multiple machines (running Ubuntu 9.x and Debian Lenny), so it should be simple to install.
This project seems to be a good bet: http://php-java-bridge.sourceforge.net/pjb/
Since you want to keep state at the java site I'd either use a java process that listens on a plain socket or use a simple embedded webserver (winstone or jetty) if you are more fluent writing servlets. Some other possibilities are listed at this related question: What is the best approach for IPC between Java and C++?
Now quite what you asked for, but you could have a look at Caucho's Resin, and in particular their Quercus which is a 100% Java implementation of PHP, it allows integration of Java and PHP.
I have a project that uses a Java program to fetch some data. It's quite simple, but I found that
$java_command="cd /var/java_dir && java my_java_program $myparam1 $myparam2";
$result=exec($java_command,$output,$return_code);
works just fine.
Zend Server also has a built-in daemon allowing you to access Java functionality from within PHP. It works right out of the box.

Categories

Resources