Skip to content

aturri/teaching-se2

 
 

Repository files navigation

Java EE 7 examples for SE2 classes

Required tools

Starting Maven Archetype

Group ID: com.airhacks
Artifact ID: javaee7-essentials-archetype
Version: 1.2
Repo: http://repo.maven.apache.org/maven2/
Description: Java EE 7 project template. Clean, lean and minimalistic.
  • From CLI: Run

    mvn archetype:generate \
      -DarchetypeCatalog=http://repo.maven.apache.org/maven2/ \
      -Dfilter=com.airhacks:javaee7-essentials-archetype
    
  • From Netbeans: File -> New Project -> Maven Project from Archetype -> Search "essentials"

  • From Eclipse

    • The first time you need to add the Repo: Eclipse -> Preferences -> Maven -> Archetypes -> Add Remote Catalog... http://repo.maven.apache.org/maven2/
    • File -> New -> Project ... -> Maven Project -> Filter "essential"

Glassfish

How to start and stop the server

  • From Netbeans:
    • Services tab -> Right click on Servers -> add server...
    • Services tab -> Right click on Glassfish Server -> Start/Stop
  • From Eclipse:
    • Servers tab -> Right click -> New -> Server...
    • Servers tab -> Right click on Glassfish -> Start/Stop
  • From CLI:
    • glassfish/bin/asadmin start-domain
    • glassfish/bin/asadmin stop-domain

Access the Control Panel

Once started, go to http://localhost:4848. Default username and password are both "admin".

Run the examples

  • Download the repo for the first time, run (or use your favourite git client)

    git clone https://github.com/deib-polimi/teaching-se2.git
    

    for future updates of the repo, run

    git pull
    
  • Open a project in your IDE:

    • Netbeans: File -> Open Project
    • Eclipse: File -> Import Project -> Existing Maven Project
  • Create a connection to the glassfish server in your IDE:

    • Netbeans: "Services" tab -> Right-click on Servers -> add server
    • Eclipse: "Servers" tab -> New -> Server
  • Configure the project to be run on Glassfish

    • Netbeans: Right-click on the project -> Properties -> Run -> Server: GlassFish Server
    • Eclipse: Right-click on the project -> Properties -> Server: Glassfish
  • Run the project

    • Netbeans: Run
    • Eclipse: Run on server

MySQL

How to start and stop mysql server

  • on Windows: instuctions

  • on Linux / OSX:

     sudo /usr/local/mysql/support-files/mysql.server [start|stop|restart]
    

How to create a database

Here are the instructions from command line, but you can do the same from your IDE or using any mysql GUI client (e.g., MySQL Workbench).

  • login as root (default password is empty)

     shell> mysql -u root -p
    
  • create a database

     mysql> create database mydb;
    

These other two guides may be of interest:

How to connect to MySQL:

  • Download MySQL Connector/J
  • Follow these instructions to install the library and create a MySQL connection pool
  • Add the url to the additional properties of the connection pool. In the end you should have all and only the following ones:
    • DatabaseName: mydb
    • User: root (or any user granted to access mydb)
    • Password: the root password
    • URL: url to the db (e.g., jdbc:mysql://localhost:3306/mydb)
    • ServerName: localhost
  • Under JDBC Resources create a new resource (e.g., jdbc/mydb) and assign the new mysql pool

Form based authentication with JDBCRealm

See the "registration" example for project configuration (web.xml, glassfish-web.xml, persistence.xml and User entity).

Follow these steps for creating a JDBCRealm:

  • enter Glassfish control panel
  • Configurations -> server-config -> security -> Realms -> new...
  • Use the following configuration:
    • Realm Name: must be the same referenced in the web.xml
    • Class name: JDBCRealm
    • JAAS Context: jdbcRealm
    • JNDI: your data base resource name, where username, password and group name are going to be saved (e.g., jdbc/mydb)
    • User Table: the table containing username and password (e.g., user)
    • User Name Column: the name of the column containing the username (e.g., email)
    • Password Column: the name of the column containing the password (e.g., password)
    • Group Table: the table containing username and group, can be the user table (e.g., user)
    • Group Table User Name Column: the name of the column in the Group Table containing the username (e.g., email)
    • Group Name Column: the name of the column in the Group Table containing the group name (e.g., groupname). WARNING: do not use "group", since it is a reserved word and queries will fail
    • Password Encryption Algorithm: MD5
    • Digest Algorithm: SHA-256
  • Server restart may be required

Interesting Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%