tags:

views:

297

answers:

1

I try to get a PHP ScriptEngine from the ScriptEngineManager, but getEngineByName("php") returns null. The following unit test works, if I replace "php" with "javascript", but it fails for "php".

import static org.junit.Assert.*;
import org.junit.Test;
import javax.script.*;

public class ScriptEngineTest {
    @Test
    public void executeCommand() throws Exception {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("php");
        assertNotNull(engine);
    }
}

I must be missing something obvious. I know, that Rhino comes with Java 6 and is behind the javascript engine. Where do I get this for PHP?

EDIT:

I made my first step forward. On http://php-java-bridge.sourceforge.net/pjb/installation.php there is a download link for JavaBridgeTemplate5442.war. I unzipped this war file. Under WEB-INF/lib/ I found the jar files

  • JavaBridge.jar
  • php-script.jar
  • php-servlet.jar

When I put JavaBridge.jar in my class path, the unit test works. (Probably I will also need php-script.jar to actually execute PHP code.)

+1  A: 

Scripting engines available under JSR 223 are listed here (bottom of the page).

Current implementations of PHP include Quercus and PHP to Java bridge.

ChssPly76
I saw both before, but for Quercus still I do not see, how I can integrate it. I finally made it with php-java-bridge. I will edit my question.
GrGr
Look here: http://groovy-news.org/e/page/axelclk?entry=experiments_with_the_jsr_223and here: http://weblogs.java.net/blog/ludo/archive/2007/03/100_java_quercu.htmlI haven't tried Quercus myself, though.
ChssPly76
Thanks, looks similar to the solution I found for php-java-bridge. I think, that this packaging makes it a little harder to actually use these bridges.
GrGr