I'm trying to finish a task which requires me to write a standalone java application that can be invoked by a single script and run automatically. Java JDK location and other arguments like output path are all needed to be involved in the command line, 'cause as well they also need to be tested. I've no experience of writing this kind of script, can anybody give me some hints? Many thanks.
Write some sort of shell script which calls your Java program with the necessary arguments. It could be as simple as one or two lines.
You may find this easier if you package your Java program as a JAR which includes all of its required dependencies.
Related
I am writing the python module where I need to interact with java module for some work.
I have already jar for java layer.
I can I invoke the jar files and call the class/Methods which are there in Jar files.
I don't want to use the Jython since major of my code is pure python
I tried subprocess.call()
but it's not serving my purpose
subprocess.call(['java','-jar', 'my.jar'])
EDIT:
I need to call the java layer because I need some input to my python module from there.
I tried py4j but no successes
JPype is an alternative to Jython that I made some good experience with. If it is not enough to call the java program and work with the output (it's hard to tell from your question), then JPype can be used to (more or less) transparently work with Java object in Python code.
I works by starting a JVM and handing requests to said JVM.
So, I'm writing a program(mostly for practice, kind of for future convenience) that will show a java front-end when run, and depending on the input, will use a python script to crawl and interpret a webpage, then send the interpreted data back to java to format for the front end. I'm sure I can get this running on my own computer, but when I want to distribute my program for my friends to use, how can I ensure my java program, mainProgram.jar can find my python code, script_x.py. Is there a way I can assure my python script will be supported. I've read that there are ways to include the necessary runtimes and such with your program when you build it, but would it still interact the same way with my java program if it was bundled with it's dependencies? I can provide some sample code soon, but it's still a work in progress, as I don't have the python script finished yet.
here is a link https://bytes.com/topic/python/insights/949995-three-ways-run-python-programs-java
use Jython (compiles to java byte code) https://en.wikipedia.org/wiki/Jython
distributing Jython applications: https://wiki.python.org/jython/JythonFaq/DistributingJythonScripts
I want to execute some java class for doing some bacground work,(have no any ui related task).like file read, write in a specific location. My main server side is done by php. I want to call these java program from php file. I study about Java/PHP Bridge. But i could not understand what i have to use like jse program(not suitable in server),jsp application (have no gui), or by a ejb. Please tell me what will be the best option to do that?
You can execute a program in a couple of ways:
exec()
system()
passthru()
shell_exec() or the shell execution operator (the backticks, ``)
Which one to use depends on what you want. You should study the above links and figure out which one to use.
Use the exec() function:
exec("java Main.class");
I have an executable JAR which runs in the command line. I would like to create a GUI for this program using VC++ for windows. Is there any way to 'hook into' the Java thread from the native C++, or launch the JAR from within the C++ thread? I have looked at the JNI, but it appears that the Java needs to be written to take this functionality into account. At the moment, I do not have the capability to modify the pre-compiled JAR. Is what I'm trying to do even possible?
Thanks in advance for any advice you can give.
The java only needs to be written with JNI functionality if you want to call C++ from Java. If you want to call Java from C++ it will work fine without any changes to the JAR. If you look at the source code to java.exe you can see an example of this.
Look at around lines 540-610 in the java.exe source code
What would you like to do with it? The easy way to simply launch would be to use the system() call, which can call any executable file, including .bat ones. A more complicated approach would have them be a client-server application and talk via localhost (example being a lot of network-based daemons like IRCd)
I'm making an application where people can upload a java code and do stuff with it.
The application i'm making is in Python. I was wondering whether it was possible to call the 'javac' command from within python, in order to compile the uploaded java file
I'm also using JPype
http://docs.python.org/library/subprocess.html
But are you sure that allowing people to submit arbitrary code is a good idea? There are security aspects of that to consider...
Entirely possible: just use the system command and invoke the java compiler. You'll probably need to set class paths and things of that nature, but it should work fine.
EDIT: see http://docs.python.org/library/os.html#os.system and http://docs.python.org/library/subprocess.html#module-subprocess for detail on invoking sub processes. You'll probably want to capture the output to return to the user in the event of a compile error.