Edit Creating JAR


There are two way to create JAR file with your php code:

  1. Use a simple way via Launcher class (read here).
  2. Use gradle plugin + StandaloneLauncher class.

We will consider the second way. Create a simple jphp project via build.gradle like shown in the first way.

Change your build.gradle

ext {
    jphpVersion = "0.7.+"
}

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath "org.develnext:jphp-gradle-plugin:0.6.+"
    }
}

apply plugin: 'php'
apply plugin: 'application'

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile "org.develnext:jphp-runtime:$project.jphpVersion"

    compile "org.develnext:jphp-zend-ext:$project.jphpVersion" // legacy zend classes and functions
    compile "org.develnext:jphp-json-ext:$project.jphpVersion" // json support
    compile "org.develnext:jphp-xml-ext:$project.jphpVersion" // xml library
    compile "org.develnext:jphp-gdx-ext:$project.jphpVersion" // libgdx wrapper
    compile "org.develnext:jphp-jsoup-ext:$project.jphpVersion" // library for site parsing in jQuery style
}

mainClassName = 'php.runtime.launcher.StandaloneLauncher'

Run your app via gradle run.

To build JAR, use the gradle dist command and see the result in build/ directories.


What about class loading?

In this case, you don’t need to use a class loader for using your classes. JPHP Gradle plugin create a class map and load your classes, functions and constants automatically.