You can create a Java application that starts its own runtime. This allows the usage of frameworks and Java runtimes, such as Spring Boot, Jetty, Undertow, or Netty.
- You are not using the Resource Configuration feature of the buildpack.
The resource configurations needed for the database connection are not applicable for Java Main applications. For more information about database connections, see: Configuring a Database Connection
In this section, applications like this are referred as Java Main applications. The application container provided by SAP Java/Jakarta Buildpack for running Java Main applications is referred as Java Main container.
-
Make sure your built JAR archive is configured properly.
Regardless of the tool you use to build your Java application, you have to make sure that the following tasks are performed:
-
You have built a JAR archive.
-
You have specified a main class in the
META-INF/MANIFEST.MF
file of the JAR archive.Manifest.MF
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Built-By: p1234567 Created-By: Apache Maven 3.3.3 Build-Jdk: 1.8.0_45 Main-Class: com.company.xs.java.main.Controller
-
You have packaged all your dependent libraries in the JAR file, also known as creating an uber JAR or a flat JAR.
If you are using Maven as your build tool, you can use the
maven-shade-plugin
to perform the above tasks.Sample configuration for the
maven-shade-plugin
<build> <finalName>java-main-sample</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>com.sap.xs.java.main.Controller</Main-Class> </manifestEntries> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
-
-
Configure the
manifest.yml
.To be able to push the Java Main application, you need to specify the path to the
.jar
archive in themanifest.yml
file.manifest.yml
--- applications: - name: java-main memory: 128M path: ./target/java-main-sample.jar instances: 1
-
(Optional) If you use SAP HANA JDBC, we recommend that you include the dependent JAR files in the uber JAR. Then refer these files, as a space separated list, in the
Class-Path
header field of the MANIFEST.MF file. For example:Class-Path: jar1-name jar2-name directory-name/jar3-name
-
Deploy the application on Cloud Foundry. Execute:
cf push
To create a Java Main application that is using its own runtime, proceed as follows:
-
Create an application, named sample_main. Use Spring Boot for that purpose.
-
Navigate to the
sample_main
directory of the application, using the command line tool, and build it. To do that, execute:mvn clean install
-
After the successful build, check that the
sample_main
directory of the application contains a sample_main.jar file. -
Open the sample_main.jar file and check that the
META-INF/MANIFEST.MF
file contains theMain-Class
header, whose value is the name of the main class. -
Add the path to the JAR file in the manifest.yml file.
You need to do this to make sure that the application can be pushed to the Cloud Foundry environment. For that purpose, add the following line in the manifest.yml file:
path: ./target/sample_main.jar
-
Finally, deploy the Java Main application. Execute:
cf push sample_main