I have a java application(runnable jar) and VB scripts which I'm using to telnet to a remote machine and executing some cmds. So, I first execute the vbs files and then run my jar(in all everything is working fine).
But, now I want to integrate scripts and my java jar such that, running the jar should first trigger the script followed by Java related task.
Few thing which I've come across are -
I cannot trigger Vbs from Java(javax.script - correct me if I'm wrong). So, possible options to rewite the script in are -
Javascript(have no idea what my Javascript file would have so that after reading it inside java class I can write it to the Socket output stream.)
PHP(I tried this using Java bridge but it gives some error saying cgi needs to installed. And, I believe it also requires PHP to be installed on the host machine before executing my jar. So I'm not going any futher with this approach.)
Long story short, I don't want to create any dependencies - I am looking for something like where I can package any external lib with my jar(if required) and use it to execute my scripts.
You can execute the VB-Script in an external command. There are a lot of resources on the internet that explain how to do that - for instance this link also explains how to start a VB-Script from within java. However I do not know if you need the output from the script within the Java. If so you'll have to listen to the outputstream of the created process. You should find an example for that as well with that link (using the processbuilder)
If you have the script packaged within your jar, I fear you'll have to unpack it to a temporary folder and execute it there.
The closest I have seen about VB script as a JVM language is in answer here.
Visual Basic or VBScript as Java Scripting Engine
Have you seen this wikipedia entry about JVM languages?
http://en.wikipedia.org/wiki/List_of_JVM_languages
Also, have you considered using Ant and using it programmatically from java?
Another option is to use groovy/Ant from Java.
Related
Currently I am working on a Java web app implementing the Spring Framework + MVC structure. I have ~10 different Python scripts that all query an API, perform some data analysis and manipulation, and save the results. All of the python scripts are in the same directory.
I would like to know how/ what would be the most efficient way to run these files from my service's Controller. Browsing around, I've seen solutions similar to this:
String command = "python /c start python path\to\script\script.py";
Process p = Runtime.getRuntime().exec(command);
However, since they are all in the same directory, I was wondering if there is a more efficient way to run the files. Perhaps another 'driver' script that calls each of the ~10 files, and then running that 'driver' from my Java file?
Any advice or suggestions would be appreciated. Let me know if any additional information is required.
I have no trouble reading files of different types using GDAL's Java bindings (version 2.2.1) via the org.gdal.ogr.ogr.OpenShared(filePath) method to create a DataSource. If I want to create a SQLite file from a DataSource, however, how would I do it?
Looking in the JavaDocs, I've found some ExportTo methods on the Geometry object that you can use to manually build GeoJSON, WKT, KML and others: http://gdal.org/java/org/gdal/ogr/Geometry.html
There doesn't seem to be anything in the Driver class that would let you use them to export a DataSource however.
Using ogr2ogr it would be as simple as running the following:
ogr2ogr -f "SQLite" ./output.sqlite3 ./input.geojson
And there is this technique for running ogr2ogr from within Java, but I would have assumed there'd be something native in the Java bindings.
I've accepted that the best way to do this is to simply include the ogr2ogr.java file from the GitHub repo in my project and wrap it in a function that makes it cleaner to access. It is almost a direct port of the original C++ GDAL file.
The one change I made was to rename the ogr2ogr main function to execute so that it didn't confuse application when I ran it.
I have a Java jar file that I run from a Windows command prompt: java jar-file class argsā¦. I would like to use it in a web app, where it would run on the client side; more or less as an applet rather than a servlet. Is there an easy way to do this? Short of decompiling, I don't have access to the Java source code, but I would be willing to add additional classes to the jar file. One other complication: the arguments to the jar command include the names of an input and output file. I'm pretty sure I can replace them with i/o stream objects but a solution would need to translate data urls.
Is there an easy way to do this?
No. You might write a (trusted) applet wrapper that redirects the system out and in streams to use them in the applet, but applets are never easy.
I am currently writing a program in JAVA that examines the behavior of external executable. One of the requirements is to observe the file operations of the external executable in real time (check if the executable creates/ deletes/modifies any file). I tried to find a suitable API in java to help me do this though it was not possible to find one. I have found the Class FileAlterationObserver which is not suitable for my program since you have to specify manually all the directories you want to monitor.
I was wondering if any of you knows a good API to use?
Thanks for your time in advance.
Without java, you could use the linux lsof command to list the open files in the system. Alternatively, and with Java, you can use libnotify, but you will need to specify the folders. I can't see any other way of doing this with pure java.
EDIT #Keppil linked you to the file change notification API that looks way more suitable than libjnotify. I wasn't aware it existed!
I just got a requirement to create a small (I assume standalone) utility to hit some code in our web application to do some custom processing of files from the app and then dump the files into a shared drive. My question is what is the best way for doing this? Do I just create a small app and then jar it up and run it off a command line or is there a better way?
Sorry, I didn't give enough detail. It's an old application, like over 10 years, so while it's been upgraded to jdk 1.6, most of the code uses the old collections, old loops, etc... There aren't any interfaces, very tightly coupled code that uses inheritance with lots of nested objects. The web app will do the processing. I think what they want is create some code outside of the application code that will login and then fire off the file processing code. Prior to this I had upgraded their version of Windward Reports in a separate branch and they want to make sure that the processed files: contracts, forms, etc.. don't get altered greatly as there are legal requirements on fonts and layouts. So this utility will go in, fire off the list of reports (a few thousand) dump it to a share drive so they can view them with another tool for comparision based on rules you can automate with that commercial tool, en masse. I was thinking create a small class with a main method, then jar it up and while the web server is running with my upgraded branch code, run the utility off the command line to fire it off.
There's not enough to go on here. How is the web app's functions exposed? If it's a REST interface then wget/curl/spring-rest-template are the way to go. If it's something like a JFS app then you're going to need something like Selenium to imitate a browser. If the functionality is in a shared library (JAR) then there web never even comes into play.
Well, I was originally looking at creating a standalone utility jar that I would run off the command line to connect with URLConnection to the app, but I found there is already testing code built into the application that I can run from a command line as long as I deploy the new code with the existing code. The utility will dump out the files to a shared drive and then XTest can be run to compare files. After reviewing the capabilities of XTest, it appears that it can handle the comparison of files well.