Glassfish

From air
Revision as of 18:24, 4 October 2016 by Donsez (talk | contribs) (→‎Complément)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Console web de Glassfish
Console web de Glassfish :: Déploiment

Serveur d'application JavaEE open-source

Installation & Démarrage

Installer les dernières versions de Java et de Maven.

Vérifiez la version de votre JRE : Java 7 est requis. JRE 8 est préférable.

javac -version

Téléchargez le zip depuis https://glassfish.java.net/download.html

Lisez https://glassfish.java.net/getstarted.html

unzip glassfish-4.l.zip

cd glassfish4

GLASSFISH_HOME=`pwd`

${GLASSFISH_HOME}/bin/asadmin

${GLASSFISH_HOME}/bin/asadmin start-domain

Ouvrez la console Web http://localhost:4848

IMPORTANT : Sécurisez votre console d'administration qui n'est pas sécurisé par défaut : https://glassfish.java.net/docs/4.0/security-guide.pdf

Installez le plugin Glassfish dans votre IDE : https://glassfish.java.net/ide.html

Créez une application web simple Hello avec Maven

cd ..
mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=webapp-javaee7 -DarchetypeVersion=1.1     -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/ -DgroupId=fr.polytech-grenoble.ricm.ecom   -DartifactId=ecomweb  -Dversion=0.1.0-SNAPSHOT -Dpackage=ecom  -Darchetype.interactive=false --batch-mode --update-snapshots archetype:generate


Remarque: il y a d'autres archetypeArtifactId disponibles

cd ecomweb
mvn clean package


Ajoutez les fichiers de projet pour simplifier l'importation dans votre IDE favori.

mvn eclipse:eclipse
mvn idea:idea


Remarque : il est possible de déployer l'artefact à l'issue du packaging en modifiant le pom.xml au préalable.

mvn clean package glassfish:deploy

Déploiement

Vous pouvez déployer votre application (ejbjar, war, ear) via la console ou bien via la ligne de commande suivante

${GLASSFISH_HOME}/bin/asadmin list-applications

${GLASSFISH_HOME}/bin/asadmin deploy --name ecomweb ../ecomweb/target/ecomweb-0.1.0-SNAPSHOT.war

${GLASSFISH_HOME}/bin/asadmin list-applications

${GLASSFISH_HOME}/bin/asadmin list-applications --type web

${GLASSFISH_HOME}/bin/asadmin list-applications --subcomponents

Ouvrez http://localhost:8080/ecomweb-0.1.0-SNAPSHOT/

Web Application WAR

Servlet, Filter et JSP

Modifiez et re-construisez votre application en ajoutant :

Rédeployez celle-ci

${GLASSFISH_HOME}/bin/asadmin redeploy --name ecomweb --contextroot "ecom" target/ecomweb-0.1.0-SNAPSHOT.war

Ouvrez avec votre navigateur

ou avec cURL

curl GET "http://localhost:8080/ecom/hello.jsp"

Regardez le contenu du journal du domaine.

tail  glassfish/domains/domain1/logs/server.log

Web Service

Modifiez et re-construisez votre application en ajoutant :

Redéployez

Ouvrez

Générez une application client pour le WebService

cd ..
mkdir hellowsclient
cd hellowsclient
wsimport -keep -p fr.polytechgrenoble.ricm.ecom.ws.client http://localhost:8080/ecom/HelloWSService?wsdl

Utilisez le plugin Maven wsimport dans le pom.xml du projet.

RESTFul Service

Modifiez et r-construisez votre application en ajoutant :

Redéployez

Utilisez curl pour interoger le service

curl -i -X GET -H Accept:application/json 'http://localhost:8080/ecom/hellorest'
curl -i -X GET -H Accept:application/json 'http://localhost:8080/ecom/hellorest/Didier'
curl -i -X POST -H "Accept: application/json" -d "firstName=james" http://localhost:8080/ecom/hellorest/Didier
curl -i -X DELETE -H "Accept: application/json" http://localhost:8080/ecom/hellorest/Didier

plus d'information sur JAX-RS ... et sur le Richardson Maturity Model

Undeploy

${GLASSFISH_HOME}/bin/asadmin undeploy ecomweb

Arrêt

IMPORTANT : pensez à arrêter votre serveur et la VM sur lequel il s'exécute quand vous utilisez une plateforme Cloud.

${GLASSFISH_HOME}/bin/asadmin stop-domain domain1

Création des autres artefactes JavaEE 7

Créez les autres artéfactes JavaEE 77 avec les archetypes JavaEE 7 disponibles sur http://mvnrepository.com/artifact/org.codehaus.mojo.archetypes

VERSION=0.1.0-SNAPSHOT

Création de l'EJB-JAR

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes     -DarchetypeArtifactId=ejb-javaee7   -DarchetypeVersion=1.1    -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/    -DgroupId=fr.polytech-grenoble.ricm.ecom   -DartifactId=ecomejb     -Dversion=0.1.0-SNAPSHOT -Dpackage=ecom.ejb   -Darchetype.interactive=false     --batch-mode  --update-snapshots     archetype:generate
cd ecomejb
mvn clean install
${GLASSFISH_HOME}/bin/asadmin deploy --name ecomejb --contextroot "ecomejb" target/ecomejb-0.1.0-SNAPSHOT.jar
${GLASSFISH_HOME}/bin/asadmin list-applications
${GLASSFISH_HOME}/bin/asadmin list-sub-components ecomejb

Ajoutez les EJB suivants:

Création de l'application cliente EJB

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes     -DarchetypeArtifactId=appclient-javaee7   -DarchetypeVersion=1.1     -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/    -DgroupId=fr.polytech-grenoble.ricm.ecom   -DartifactId=ecomapp     -Dversion=0.1.0-SNAPSHOT -Dpackage=ecom.ejb.client   -Darchetype.interactive=false     --batch-mode  --update-snapshots     archetype:generate

cd ecomapp
mvn clean install
CLASSPATH=ecom.ejb.client.Main
java -cp ${CLASSPATH} -jar target/ecomapp-0.1.0-SNAPSHOT.jar

Création de l'EAR

mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes     -DarchetypeArtifactId=ear-javaee7   -DarchetypeVersion=1.0    -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/    -DgroupId=fr.polytech-grenoble.ricm.ecom   -DartifactId=ecomear     -Dversion=0.1.0-SNAPSHOT -Dpackage=ecom.ear   -Darchetype.interactive=false     --batch-mode  --update-snapshots     archetype:generate

cd ecomear
mvn clean install

Modifiez le pom.xml pour y ajouter ecomejb.jar, ecomweb.war, ecomwebadmin.war et ecomapp.jar.

Retirez (ie undeploy) ces applications.

Déployez l'EAR

${GLASSFISH_HOME}/bin/asadmin deploy --name ecomear --contextroot "ecom" target/ecomear-0.1.0-SNAPSHOT.ear

${GLASSFISH_HOME}/bin/asadmin list-applications
${GLASSFISH_HOME}/bin/asadmin list-sub-components ecomear

Création du super POM (parent)

Créez le pom.xml du super POM (parent) qui liste les modules du projet et factorise les propriétés du projet (name, groupId, version, scm ...) et les configurations des plugins (maven-compiler-plugin, ...).

Modifiez chaque pom.xml des modules en conséquence.

Exemple pour l'application web

<project>
...
  <parent>
    <groupId>fr.polytech-grenoble.ricm.ecom</groupId>
    <artifactId>ecom</artifactId>
    <version>1</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>ecom-web</artifactId>
...
</project>

Re-construisez le projet depuis le super POM.

Redéployez (redeploy) l'EAR vers le serveur

Complément

Monitoring de Glassfish avec VisualVM

Installation du plugin Glassfish

Lancez la console VisualVM. Installez le plugin pour Glassfish (Tools > Plugins > Available Plugins). Relancez la console VisualVM Connectez vous au serveur en utilisant la console VisualVM.

jvisualvm &

OSGi Felix

Accès aux commandes du Gogo Shell de Felix

./bin/asadmin osgi lb -l

Lire http://docs.oracle.com/cd/E26576_01/doc.312/e24928/overview.htm#gjjxt

Run Java EE 7 Application as Docker Container using Maven (and WildFly)

https://github.com/javaee-samples/javaee7-docker-maven

Documentation

REMARQUE: les livres sur JavaEE se periment très vite avec l'évolution de la spécification

JavaEE

REST