473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Call Java Program in PHP

madzman23
Hi guyz, I kinda new here and I dont know if there is post that similar to my question, because I really needed immediately I am posting my question.

Can anyone here help me how to call a Java Program using the PHP.
The PHP code should call a Java program that will extract all the data from the database, I know we can do this in PHP, but I want a more secure one so I want to make a prototype that will call the Java Program that get all the database from the database and make it available for download to the user. I have all my codes done but my last problem is I cant call my Java program even using the exec() and shell_exec() functions. Or I might do it wrong?

Here is my code to call the java program:
I already compiled the program.

Expand|Select|Wrap|Line Numbers
  1. exec("java JavaProgram");
But it doesn't work, I also try to call the firefox to try if I can execute the firefox using the PHP exec() function but it also dont work.
Im using LAMP.

I will gladly appreciate any response from you guyz, I really need your help with this.

Thank you.
Oct 14 '08 #1
5 10745
Dormilich
8,658 Expert Mod 8TB
question, what makes the java DB access more sequre than a PHP DB access (once you have secured the sql input)?
Oct 14 '08 #2
Atli
5,058 Expert 4TB
Hi.

I would also have to question that. What makes your Java application more secure than a it's PHP equivalent?

But... in any case.

Can you execute that command in a command line?
Meaning; does this work outside PHP or is it only failing from withing PHP?

Could it be that you need to set an absolute path, rather than just the file name?
Like say "Java /path/to/Java/application"
Oct 14 '08 #3
Yeah, I did it on the command line. I have been able to run the application in the line. Do you guyz know some other function that I can use to call and execute a program using PHP?

Well, as I know it Java is more secured than PHP base on the server side programming. And I am really have no choice but to do it because my new project requires to have that and I will like to really know if its feasible to have it that way.
I want to ask you guyz if you make a project similar to this because I am new in PHP. Well, if you guyz dont think its feasible, well I think my prototype is a failure.
Oct 15 '08 #4
Atli
5,058 Expert 4TB
Yeah, I did it on the command line. I have been able to run the application in the line. Do you guyz know some other function that I can use to call and execute a program using PHP?
The exec functions do work for this sort of thing.
You just need to figure out what is causing this problem.

If you are sure the paths are correct, could it be that the user running PHP does not have permission to execute the file?

Try using chmod to change the file permission. Something like:
Expand|Select|Wrap|Line Numbers
  1. $ chmod 755 /path/to/file.ext
You could also look into the PHP / JAVA Integration extension, but I have no experience with that so I can't really say how well that works.
Well, as I know it Java is more secured than PHP base on the server side programming..
That makes absolutely no sense.

The only reason I can think of why a Java program may be considerd safer is that Java is compiled, while PHP is interpreted.
Meaning that the PHP source code is read every time the program is executed, while the Java code is only read once, after which the complied binary files are used.

But none of that matters on a typical web server, because the PHP code itself will never be accessible to the public. Only the output of the PHP code will be.
And in any case. If you are worried about that you could always just put sensitive scripts outside the web-root and include them into your public scripts.
Oct 15 '08 #5
Okay, thanks for that explanation bro.

I think the PHP/Java Integration is not necessary because I just need to run the Java program, so I will not need any variables or function that are in Java. Its just like I am calling an executable program like Firefox, C++ executable files, etc. and afterwards continue my php script.
Oct 15 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Martin Hampl | last post by:
Hi, I couldn't compile php with java support on Mac OS X so I thought I'd call my java program with shell_exec(). It does work for simple programs ("hello world") but if the program gets more...
3
by: gohaku | last post by:
Hi everyone, I would like to know if it's possible to use python (libraries) in a Java Program. I do not want to use: Process proc = Runtime.getRuntime.exec(command) I am basically looking for...
1
by: chandan | last post by:
Is it possible to call an external java program from a trigger in oracle 8i. I know that you can call a stored procedure in java from a trigger but i want to know is it possible to call an...
5
by: Tyler | last post by:
Hi ppl, I know it's forbidden to mention Java in this newsgroup but I've been presented with a problem which requires that my C++ program communicate with another java program. What is the...
4
by: Alan Wang | last post by:
Hi there: I am just wondering if I could call java library using C#. The reason to do that is my application wants to automate OpenOffice and create document. Thanks in advance Alan
1
by: =?Utf-8?B?S2Vubnk=?= | last post by:
I have one bat file that contains a command to startup Java Program. Then, I would like to create a cluster job to call the bat file. In case of one computer is down, another computer can also call...
11
by: BigZero | last post by:
Hello, can i call Java method.That is java code from php,here what i m looking for i have class called DB in this class all the DB related things ,like DB connection DB insert,DB read etc...
6
by: moongeegee | last post by:
I have compile my java program as myjava.class. And I can run as "java myjava" without any program. As now, I need to execute myjava.class in javascript. Please shed a light how to execut "java...
0
by: Siyodia | last post by:
This is a java program which i need to run facing compilation error Its consuming a third party web service method I have the supported files(folder) which contain necessary class files...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.