Help with executing a Jar file in PHP

Discussion in 'PHP' started by HNH992, Jun 26, 2010.

  1. #1
    Hi
    I have Jar file which does some modifications to ZIP files.
    I want to execute the jar file by using PHP.
    I wrote like this code:
    <?php
    shell_exec('java -classpath testsign.jar testsign test.zip test2.zip');
    ?>
    PHP:
    The jar file: testsign.jar
    After executing the jar file, It will modify test.zip and create the modified file test2.zip.

    I tried this code in AppServ and it worked.
    so I uploaded it to my website and I tried it but it didn't work.
    It doesn't create test2.zip
    I turned off the Safe Mode and made the chmod is 777. But didn't work.

    What the problem??

    P.S: My hosting from Servage : http://www.servage.net

    Thanks
     
    HNH992, Jun 26, 2010 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Try putting an echo before the shell_exec and see if it's telling you something useful (like an error).
     
    digitalpoint, Jun 26, 2010 IP
  3. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    There is no problem with the code.
    Because it worked on AppServ
     
    HNH992, Jun 27, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    could try the system() cmd

    php could also be wrapping the command differently to appserv, the echo of the output would be helpful on debugging
     
    themullet, Jun 27, 2010 IP
  5. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    I tried system() and it's worked in appserv but didn't worked in my hosting.

    how can I put the echo of the output?

    Sorry I'm still beginner in PHP.

    And I have another question.
    If the hosting doesn't support JSP. Will the code work?

    Thanks
     
    HNH992, Jun 27, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Onsome shared hosting shell_exec() is disabled using the php.ini disabled_functions, check your php.ini and edit it if you have access (or contact your host).

    To check if its its disabled or not use the following code:

    <?php
    if (function_exists('shell_exec')){
    
    echo "Enabled";
    
    } else {
    
    echo "Disabled";
    
    }
    ?>
    PHP:
     
    danx10, Jun 27, 2010 IP
  7. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    It's Enabled
     
    HNH992, Jun 27, 2010 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    There doesn't need to be a problem with the code to produce an error. There could be a problem with the environment.

    Considering how low servages prices are, I'm thinking they've got their servers stripped down pretty thin.
    I'm guessing that either the server doesn't have Java installed, or it's not configured in a way that individual accounts can use it like that.

    Have you tried executing a different jar file, for instance a simple "hello world" type jar ?
     
    joebert, Jun 27, 2010 IP
  9. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #9
    I tried "hello world". But it doesn't work too.
    I think Servage doesn't support java.
    Do you know and hosting company support java?
     
    HNH992, Jun 28, 2010 IP
  10. Mibunal

    Mibunal Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You'll need a VPS - shared accounts usually don't have Java enabled.
     
    Mibunal, Jun 28, 2010 IP
  11. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #11
    The VPS is too expensive for me.
    The java file's work is to encrypt some files with a private key.
    Can I do that with php directly?
     
    HNH992, Jun 28, 2010 IP
  12. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Are you actually passing it a full path on everything?
     
    krsix, Jun 28, 2010 IP
  13. SportsBettingScholars

    SportsBettingScholars Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    You first need to find out for sure if the server you are running on has Java installed so you can run Java programs, check the informaion from the hosting company.

    Assuming not, as it's usually mentioned specifically when you subscribe, you'd need to switch your account.
    There are good hosting solutions avalable that allow you to do everything common to PHP hosting and Java on top for less than 10$ a month.
    And if you just want to run Java programs on your server account you don't need a VPS, a shared server account is plenty.
    The providor i use has a basic VPS with Java for 9.90$ , just google "cheap java hosting" and you'll find some for 4$.
     
    SportsBettingScholars, Jul 1, 2010 IP
  14. HNH992

    HNH992 Greenhorn

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #14
    Thanks.
    I will search for a good vps.
     
    HNH992, Jul 2, 2010 IP