hi, am Gilbert i developed a desktop application in java and i craeted an autorun of the application.
and i made a webbased application using php.
how can i run the desktop application via php?

Dani AI

Generated

Short answer: you cannot make a remote PHP page magically start a program on somebody else’s desktop. PHP runs on the server; calling exec() (as suggested) launches processes on the machine that is running the PHP, not on a visitor’s PC (this is the server/client execution model). (developer.mozilla.org)

If you do want the JAR to run on the machine that hosts your PHP (server-side), use a safe, full-path command and background it. Example (Linux) — note use of escapeshellarg() and nohup so it keeps running and logs go somewhere you can check:

<?php
$jar = '/opt/myapp/myapp.jar';
$cmd = sprintf('nohup /usr/bin/java -jar %s > /var/log/myapp.log 2>&1 & echo $!', escapeshellarg($jar));
$pid = trim(shell_exec($cmd));

Common pitfalls: wrong absolute paths, webserver user (www-data/Httpd) lacking execute permission, SELinux/AppArmor blocking, or trying to start a GUI app on a headless server. If you need scheduled runs on the server, cron is a straightforward option (as hinted).

If the goal is to start the Java app on a visitor’s PC, you need a client-side mechanism and the user must install/approve it. Practical options:

  • Register a custom URI scheme (myapp://...) and have the desktop app handle it; the browser will invoke the registered handler but the protocol must be installed on the client (registry/Info.plist). (learn.microsoft.com)
    Example HTML: <a href="myapp://doAction?x=1">Open app</a>
  • Use JNLP / Java Web Start workflows on clients — note Oracle removed the Web Start deployment stack in JDK 11; OpenWebStart is a maintained replacement. (docs.oracle.com)
  • Run a small local “agent” on the client (or have the Java app poll your server for commands). Polling is the simplest if the client app can be installed and you control the clients — this is what suggested.

Browsers and vendors have tightened plugin/auto-run paths (NPAPI and in-browser Java plugins were phased out), so applet-style in-browser launching is no longer reliable. (blog.chromium.org)

Security notes: never pass untrusted input into shell commands; require HTTPS and authentication for any command channel; sign installers or use enterprise deployment if you must auto-register schemes or agents.

Recommended Answers

All 5 Replies

That only works when your PHP script runs on the same machine as your desktop application.

pixelsoul and pritaeas comments are both true. well there's one trick, PHP's exec() can execute exe files, lebian files, Jar files, and Mac OS' executubale file. those that are made of program. Not Media type files.

one trick here is to download the executable file then run the PHP script, if and only if it is a server based application. if want to make the application wider which is world wide web, then install the executable file in the web server or just save it then put all the scripts on the server. make sure that the scripts and the executable files are on the same root folder, otherwise it will fail.

Member Avatar for Member #120589

Having an remote php page access your local machine could be tricky. Do you really need to do this? Seems that that would be a major security issue. I think I'd have a flip if anybody tried to access my PC.

How about the java autorun -> poll website for data -> java

Or is that not possible or perhaps not what you need?

diafol's idea was right and that is what I was also talking about. Please have a little background doing CRON jobs this will be part of your scriptings regarding your question. One another way is doing the jApplet. and if you pursue to do it on jApplet. this forum should be transffered to Java programming, not the Javascript

as for me, I defined my self that cron's acronym to make it easy to remember is Compiled Run-on Online Network. This is not the correct acronym but that's the way I understand what CRON can do. So I defined it my self that way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.