Is it possible to call progress program (.p file) from java code - java

Here's a Progress program that creates a record in the Symix database:
create audit.
assign audit.table_name = "JavaSample"
audit.key_id = "12345"
audit.field_name = "<FieldName>"
audit.audit_dt = today
audit.audit_tm = time
audit.audit_user_id = "javauser".
I want to call this .p file from the java code.

Progress offers Open Client runtime package to call .p through AppServer.
It is required to generate java classes from compiled .r file using ProxyGen from Progress OpenEdge Studio installation, then put those generated classes put into Java project.
But this variant is complicated and not easy to use, especially if parameters changes frequently.
Alternative way to ProxyGen is to use opa library. It simplifies Progress .p procedures call from Java.
All you need is this case - it is to create a simple parameters object and to call runProc method. Parameters will be mapped on the fly.
Of course, you still require an AppServer on Progress side to run those .p.
More info in https://github.com/labai/opa

When using the AppServer you can run the .p file on the AppServer using the OpenClient proxies for Java:
http://documentation.progress.com/output/OpenEdge116/pdfs/dvjav/dvjav.pdf

You could use Runtime to execute a shell script, as covered in for example this question: How to run Unix shell script from Java code?

Related

How to pass system system properties from jruby to Rails server

I'm running a local Rails server (WEBrick) via JRuby and want to test some code that will eventually be running on Torquebox. I'm trying to access some custom Java system properties via ENV_JAVA. These system properties will be available when running on Torquebox so to test my code locally, I'm passing in the system properties on the command line using the "-J" argument.
When I run just JRuby, everything works fine, I can access my custom property.
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value -e "puts ENV_JAVA['my_prop']"
This simply prints "my_value" to output.
My problem is trying access these custom properties when running a local Rails server. My command line to startup the local Rails server looks something like this:
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value C:\jruby\jruby-1.7.24\bin\rails s
When WEBrick starts up, my custom property "my_prop" is no longer in ENV_JAVA. It looks like this is because inside the railties Rails::AppRailsLoader module, exec_app_rails simply replaces the current process with another one by calling the Kernel exec method and passing in the command arguments.
This does NOT keep the custom properties around. Does anyone know how I can work around this? I'm currently running Rails 4.2.6. It looks like in Rails 5 the module name changed to Rails::AppLoader.
So I figured out a better(?) way to handle this. Instead of:
exec RUBY, exe, *ARGV
I can do this:
custom_sys_props = {}
current_sys_props = ENV_JAVA.to_hash
default_sys_props = eval(%x(#{RUBY} -e "puts ENV_JAVA"))
current_sys_props.each {|k,v| custom_sys_props[k] = v if default_sys_props[k] != v }
jruby_props = []
custom_sys_props.each{|k,v| jruby_props << "-J-D#{k}=#{v}"}
exec RUBY, *jruby_props, exe, *ARGV
Its ugly and really only works for JRuby, but I dont know of a better way to handle it. Still a shame that this hasn't been addressed before
After discussing with a colleague, turns out I can run my rails server by calling
jruby.exe -J-Dmy_prop=my_value script/rails
from within my project directory. So I dont even need to run the rails.bat script. Hope this helps someone

How can Java Applications communicate with MATLAB

I have some mex files that urgently need to be called via MATLAB, there is currently no way around. However, I really despise MATLAB's GUI (in)possibilities and would like to create some e.g. JavaFX Apps.
My question: how can a Java app's communicate with a running MATLAB instance?
I know that you can include Java objects into MATLAB, however I would prefere to have a standalone Java app.
Java can execute commands via command line for example:
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
So it is possible to execute a MATLAB script via command line in Java.
In MATLAB it is possible to write files with any data needed. I don't remember the exact way you may do this. http://www.mathworks.com/help/matlab/ref/fprintf.html gives an example:
x = 0:.1:1;
A = [x; exp(x)];
fileID = fopen('exp.txt','w');
fprintf(fileID,'%6s %12s\n','x','exp(x)');
fprintf(fileID,'%6.2f %12.8f\n',A);
fclose(fileID);
It is some kind of a workaround but it should work and it is not really hard to implement.
Update.
If Matlab is already running and you want to communicate with it in another application (Java), it may be done using a network connection through the localhost. Matlab may listen to some predefined port (for code example see http://www.mathworks.com/matlabcentral/fileexchange/11802-matlab-tcp-ip-code-example ) and do some action when a "start" trigger is sent via Java (or even some data along with the trigger). In Java you may use the Socket class (some code example may be found here http://www.javaworld.com/article/2077322/core-java/core-java-sockets-programming-in-java-a-tutorial.html ).
Also it may be done writing data into files. For example, Java adds some command to some file with predefined name (command.txt). Matlab scans this file in a loop and when something is found there it starts calculation (and Java application waits for results in some results.txt file).
I would suggest to start a server in Matlab that listens on a specific port to send/receive data to/from a Java client. By using the eval Matlab command you could even invoke scripts/command/etc. remotely controlled by a Java client.
You might want to have a look at this code example.

How do I modify permissions to a shared folder with java?

I have the following problem:
I have a shared folder on my computer(Windows OS). I need a script in Java that when runned blocks the acces of network users to this folder so that I am allowed to modify its content.
Any suggestions or ideas?
If you are using Java 7 or later, you could use the java.nio.Files.setAttribute to set the DOS permissions using the relevant attributes from the DosFileAttributeView.
(You might also be able to do it using AclFileAttribute or PosixFileAttribute ... depending on the true nature of the folder you are attempting to modify.)
For Java 6 or earlier, you would need to resort to a 3rd-party library, JNI/JNA calls, or using Process to run an external command.

Java codes for USB

I want to create a program using Java for Automatically copied USB's data when it's insert to machine. How I do it?
There is no such thing as "USBs data", the very concept doesn't exist.
There is nothing specific in Java SE for do this job.
I may think of two ways to get that working:
Write a Java program that starts on boot (maybe a service), the prog scans continously available "drives" (D:,E:,F: ... in Windows, mount on Linux), the USB flash may be marked with a specific folder/file name (eg. COPY_USB_). That can be done with the File class.
Write a Java program that get invoked on plug-in. I know that can be done on Linux with hotplug-script support.

Starting other Applications with Java

Is it possible to start other application that are installed on the system with my java app and pass a file as a parameter to them? I have a client which receives videos from a server and I want my client program to start, lets say the VLC player with the file that I received. How do I manage to do that?
Use Desktop#open(). It will launch the platform default associated application to open the given file.
File file = new File("/absolute/path/to/file.vlc");
Desktop.getDesktop().open(file);
No need to hassle with Runtime#exec() or ProcessBuilder for which you would have to add platform detection and to write platform specific logics for.
Quite simply:
Runtime.getRuntime().exec("vlc [arguments]"); //Write all arguments as you would in your shell.
Make sure you catch all relevant exceptions
You can call the exec method on the Runtime object.
Runtime.getRuntime().exec("System specific command line text here");
You can run an external program pretty easily on Java 5+ with ProcessBuilder, including passing arguments and handling input/output streams.
eg.
ProcessBuilder movieProcess = new ProcessBuilder("/path/to/movieplayer", "/path/to.moviefile");
movieProcess.start();
Only used it myself executing non-UI stuff, I'll give it a quick go and see what happens with something like VLC.
Update - works a treat for flv on Ubuntu, UI is visible and accepts file arguments.

Categories

Resources