📜 ⬆️ ⬇️

Jelastic Cloud + Maven. Part 1

What is Jelastic Cloud ? This is a cloud-based java-hosting, and for some time a php-hosting that supports application servers such as Tomcat 6/7, Jetty 6, Glassfish 3, Java 6/7 runtime, as well as MariaDB 5.5, MySQL 5.5, PostgreSQL 8.4, MongoDB 2.0 and CouchDB 1.2 (versions are indicated at the time of posting). More information can be found on their website.

We'll talk about creating and uploading a java web application to the cloud environment using the maven plug-in from Jelastic.

In the first part, we will create an environment in the cloud and create a simple web-project, which we will install in the environment.

Step 1. Create a cloud environment.

To do this, you need to create, if you do not already have it, an account and go to the "Administration Panel" with your provider (Jelastic Cloud is located at different providers).
')
I chose tomcat 6 and java 6. The environment will be from one to three cloudsets. Also, in the picture I highlighted the environment name ( env-6560883 ) - we will later install the web application on it, as well as using it, we will open it in the browser ( env-6560883.j.rsnx.ru env-6560883.j.rsnx.ru )


Step 2. Create a simple web application using Maven.

many pictures





After Maven finishes creating the basic structure of the project, open the file /src/main/webapp/WEB-INF/web.xml and replace the content in it completely with ours, thereby indicating that we will use servlet API 2.5 instead of 2.3 .

xml source
 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 



Well, we’ve finished creating our simplest web application and now is the time to start setting up a project to install it via Maven on the Jelastic Cloud.
You may ask, why does the example from Jelastic itself not suit me? Well, at least by the fact that it is required to do 2 steps (assemble, install) instead of one (assemble and install).
Let's get started

To begin with, in accordance with the official documentation, add the following block to ~/.m2/settings.xml :
 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>jelastic</id> <> <activation> <activeByDefault>true</activeByDefault> </activation> </> <properties> <jelastic.username>[insert your Jelastic user name]</jelastic.username> <jelastic.password>[insert your Jelastic password]</jelastic.password> </properties> </profile> </profiles> </settings> 

the only difference was that I removed the inclusion of the default profile (activation section) - it is more convenient for me to explicitly include the necessary profiles for a specific project.

Now, in the same way, according to the official documentation, we will add a repository for the jelastic-plugin to the pom.xml of the project:
 <pluginRepositories> <pluginRepository> <id>sonatype-oss-public</id> <url>https://oss.sonatype.org/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> 


This is where our correspondence with the official Jelastic documentation ends and turn to “magic”.

Added a new profile to pom.xml with an id corresponding to the jelastic profile id in settings.xml:

xml source
 <profiles> <profile> <id>jelastic</id> <build> <plugins> <plugin> <groupId>com.jelastic</groupId> <artifactId>jelastic-maven-plugin</artifactId> <version>1.7-SNAPSHOT</version> <configuration> <api_hoster><span style="color: red;"><b>app.j.rsnx.ru</b></span></api_hoster> <context>ROOT</context> <email>${jelastic.username}</email> <environment><span style="color: red;"><b>env-6560883</b></span></environment> <password>${jelastic.password}</password> </configuration> <executions> <execution> <phase>install</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>none</phase> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> 



Here we did the following:
1) disabled for this profile the execution of the maven-install-plugin , which installs our artifact into the local Maven \ repository
2) Added a jelastic maven plugin with indication of the cloud environment, data for authentication and context for our web application (if you need a non-domain root, write your path instead of ROOT , for example " /myapp ")
3) for the jelastic maven-plug-in indicated that it runs automatically in the " install " step

All - now we are ready to build and install our web application on Jelastic Cloud.

we include the jelastic profile and we specify maven to make installation, having specified the install stage


We see that the installation was successful:
many pictures





This is where our first part is completed - we successfully deployed our web application to the Jelastic Cloud environment.

PS: at the moment when using the jelastic maven-plug-in there is a problem with creating duplicates of war-files in the distribution manager - you have to go to the administration panel and delete duplicates manually.

Source: https://habr.com/ru/post/164883/


All Articles