vba run java class - java

How can I run a java class from VBA. I am trying to post to a server using Excel VBA. I can do this only with VBA on a PC but when using a MAC the DomDocument object returns a compile error. So what I did was create a java class which will post and get a response from the server. Now what I am trying to do is get the VBA to run the java class wait for a return code and process the return. If this can be done in a different language (then Java) I am also open to that. But we prefer Java.
I tried using
Dim obj as Object
Set obj = GetObject("java:SendXML") '(sendXML is class name)
but get a run-time error that automation failed.

There should be no need to use Java for doing HTTP POST, you can use standard VBA libraries. See How can I send an HTTP POST request to a server from Excel using VBA?.
Edit: If you can't get the Mac answer working, I would advise using CURL which is available for lots of platforms: http://curl.haxx.se/download.html.

I tried a similar thing myself, but to me it appeared as if there is (almost) "no way out" of Excel 2012 for Mac. One solution I considered is to use AppleScript, there are a few examples here: http://www.rondebruin.nl/mac.htm
If you could use OpenOffice / LibreOffice you could try Obba (Java Object Handler for Excel and OpenOffice). This works for Excel on Windows too and I tried to add Mac support to Obba, but so far found no solution.

Related

How to read console output from Grails [duplicate]

This question already has answers here:
How to read console ouput
(2 answers)
Closed 8 years ago.
My grails app has an external java library which I developed. I want my grails app to be able to display my java library system.out statements (console output). How do I go about doing that?
I would rather not have to write it out to a file then read it in grails. There must be a better way of doing this.
**I want grails to display these to a text box as the happen(In a browser while its running(so the user can see))
Afer trying several of my own ways I have to settle for this way which I will post here. Thanks #Shaunak for your help and understanding.
**How I solved it.
In my java library I created a global class which all the System.outs will be wrote to
writeSouts(String sout){
//store here in a global string and keep appending to it as needs be
}
Then in grails constantly call the java library method. and using Ajax write it out to the browser window.
Hope this helps anyone in the future who encounters the same problem.
Also it is not for testing but an integral part of my web app so that the user of the web app can was the java library is doing in the background.
Without much details on how exactly you are invoking the Java Library, I will assume here that it is just some code that writes to console, and you want to invoke and read it from inside Grails controller and send it back to HTML. Here's what I would suggest. Instead of including the Java Code as a library, create a command line utility out of it.
So your java program will be invoked for testing like so,
java MyLib -arg1 -arg2
This will should out put something like this on the command line:
> This is my nice output
Now to to invoke and read this from grails, you can use Groovy's External Process Management
and do something like this to invoke and read the output:
def process = "java MyLib -arg1 -arg2".execute()
def response = "Found text ${process.text}"
Your response var should now have value
Found Text This is my nice output
You can now use this to do what ever in a grails controller, like send it back to HTML..

Using itext/xfaworker from IBM Notes/Domino via LS2J

I have used itext in the past where I have created a Java library with a class using the iText jars. This has worked perfectly in the past.
I now have some PDF's the gets corrupted when using setFormFlattening(true), therefor I have tried using the XFAFlattener, and this one works fine.
My problem is that I now need to load a license file via LicenseKey.loadLicenseFile and this works fine if I use my Java class from a Java agent. But if I try to use my Java class form a LotusScript agent, I get an "Certificate not found" error when LicenseKey.loadLicenseFile is called.
I can see that there is a itext.cer certificate inside the itext-licensekey-1.0.3.jar file. I guess it is this certificate that can't be found when running from a LotusScript agent.
Anyone knows how to get this to work?, maybe someone with deep iText knowledge know how this certificate is being loaded from the iText LicenceKey code, and can figure out what the problem can be.
There is no way to read a resource file in Java code if Java code is executed by LS2J.
As a workaround in my LS2J projects, I put the file content into a constant as base64 string and read this instead of resource file.
Another way is to put the code into an Java agent and to call the agent from LotusScript. This way Java code works as expected. Use an in-memory-document to "communicate" between LotusScript and Java.

How to execute java functions/script in PHP

I have a system which is implemented using PHP(Joomla). Now the client wants to integrate a SMS gateway. Unfortunately SMS gateway does not supoort PHP. It's written in Java and All the examples are written in JAVA.
I'm supposed to include webservices‐rt.jar to my program and run a example script as below.
lk.mobitel.esms.User user = new lk.mobitel.esms.User (); user.setUsername(“TestUser”);
user.setPassword(“Password”);
lk.mobitel.esms.test.ServiceTest st = new lk.mobitel.esms.test.ServiceTest ();
System.out.println(st.testService(u));
According to my knowledge I can run a .jar as below using PHP
<?php exec("java -jar filename.jar arguments",$output); ?>
How can I run a JAVA script like above in PHP? Is it possible? Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.
I never did this, but PHP Manual gave a link for PHP-Java Bridge for PHP5 as PHP/Java Bridge. If it is what you are looking for ?
It's not possible to combine PHP and Java in the same script and have them executed in one run.
Your exec approach is the way to go, if you are approaching from PHP. But you should rather use passthru as exec does not return anything. With passthru you can get the shell response of your java command and act accordingly.
Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.
Simple answer:
Bridge using data-exchange layer. :)
Hint (in super simple language): My favorite webservice uses PERL to process their scripts and I fetch them using XML.
Groupon is made on RoR but, I happily get tweets, thanks to their API which outputs a JSON.
Simple? :)

How PHP script can be called using Java Applet

I want to access user's scanner using PHP script. I know this can be done by using PHP script on Linux based machine.
I want to put this script on the server and wanted to run it via Java Applet I don't know Java much also I am not sure if this task can be done by this way.
Please suggest if this is correct way and How to proceed on it.
Thanks for your time!
Can the scanner PHP code be operated purely via parameters in the URL? If so, then a Java applet could connect to those URLs passing parameters as necessary, and if the PHP script returns information in the HTML output stream (as if it were returning a web page), then the applet can parse the page it 'downloads' from that URL to get the information out. Not elegant, but do-able.

PHP get data or interact with a running Java process. (I think different than PHP/Java bridge)

I have an apache2 webserver with php installed and working. I am wondering if there is any way I can get a PHP script to access a Java program that is constantly running, mostly to just get information that the process keeps track of. The Java program is not a webapp or running within the apache server. It is a separate program.
Ive been looking into PHP/Java Bridge systems, and all they seem to do is let you run Java programs from PHP and vice-a-versa, which is not what I need. I can think of a way to do this via a web service and SOAP running on localhost, but if there is a way to avoid this and I can gain direct access to the Java program, I could get my webapp to run much faster.
The Java app that I am trying to "talk to" is a program that I wrote so I have access to the source code to make the necessary changes if something within the Java program needs to be set up.
Thanks in advance, I've been looking all over for something like this.
You'll need to communicate with the Java process in one way or another. As a web service is too heavy, you could simply communicate over a socket with a custom text or binary protocol.
Or you could also perhaps make the Java program write to a database every n seconds, and read from the database in your PHP script.
EDIT :
Look at http://www.php.net/manual/en/sockets.examples.php for a socket client example in PHP.
Look at http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html for a server socket example in Java.
PHP/Java Bridges let you call a running Java program from PHP.
Read: http://en.wikipedia.org/wiki/PHP/Java_Bridge
Read: http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php
The bridges actually use local socket communication, from the faq:
<?php
include_once("Java.inc");
$i1 = new Java("your.class", "1");
$i2 = new Java("your.class", "2");
$i3 = $i1->add($i2);
echo $i3->toString() . "\n";
?>
See Java.inc.
And edit your java code to contain the following line:
static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner.getInstance("9267");
Hey, so basically you need to run java application from php and get response from java application?
If its that so - I can't see any problem fro php/java-bridge. For example I've successfully run java encryption method for custom encryption in php.
You might look into Quercus/Resin. PHP runs inside Java on a Java web server. You can call Java code as if it was PHP functions/commands. All PHP commands are not supported, both most are. For example, you can run WordPress under Quercus.
http://www.caucho.com/resin-3.0/quercus/

Categories

Resources