J2EE-Application Server

Werbung
J2EE-Application
Server
Installation- and
Setup-Guide
F:\_Daten\Hochschule Zurich\Web-Technology\ApplicationServerSetUp.docx
Last Update: 8.10.2015, Walter Rothlin
Seite 1
Table of Contents
Java Setup .............................................................................................................................................. 4
Download JDK (Java Development Kit) ............................................................................................... 4
Install JDK ........................................................................................................................................... 5
Glassfish Server Setup ............................................................................................................................ 6
Download Glassfish ............................................................................................................................ 6
Install Glassfish ................................................................................................................................... 6
Eclipse for JEE Developers Setup ............................................................................................................ 7
Download Eclipse ............................................................................................................................... 7
Setup Eclipse ...................................................................................................................................... 8
Install JDK in Eclipse ........................................................................................................................... 8
Add Glassfish Tools for Eclipse ......................................................................................................... 11
Setup Glassfish with Eclipse ............................................................................................................. 12
Start Glassfish Admin Console .......................................................................................................... 14
J2EE development ................................................................................................................................ 16
Create first Servlet and JSP, deploy and run it.................................................................................. 16
First Servlet Code ............................................................................................................................. 18
Create Bean to get called from Servlet / JSP in the same dynamic Web-Project ............................. 18
Call Bean-methode from Servlet (same web-App): .......................................................................... 20
Call Bean-methode from JSP (same web-App): ................................................................................ 20
Create an EJB (Enterprise Java Bean) ............................................................................................... 21
First EJB Code ................................................................................................................................... 23
Deploy EJB ........................................................................................................................................ 24
Call EJB Methode from Servlet ......................................................................................................... 25
Java-client calls EJB-Methode........................................................................................................... 27
Create a Java Client which calls a public Web-Service ...................................................................... 31
Create first own WEB-Service ........................................................................................................... 35
Create Java-Client calling own WEB-Service ..................................................................................... 40
Create TCP/IP Server-Client .............................................................................................................. 41
Create TCP/IP Server-Client advanced.............................................................................................. 43
Create RMI Client-Server .................................................................................................................. 45
Visual C++ 2013 Runtime...................................................................................................................... 48
MySql ................................................................................................................................................... 49
Download and Install MySql ............................................................................................................. 50
Create local User in MySQL Workbench ........................................................................................... 59
Seite 2
Give a Remote Computer access to MySQL...................................................................................... 62
Download mySql JDBC driver ........................................................................................................... 64
Download and Install MySql Eclipse Plugin ...................................................................................... 65
Toad extension ............................................................................................................................. 65
DBeaver ........................................................................................................................................ 67
Basic MySql commands .................................................................................................................... 73
DB Connection über JNDI auf dem Application Server einrichten .................................................... 74
Insalling XAMPP instead of MySql .................................................................................................... 77
CS IDesktop Setup ................................................................................................................................ 82
AppDevs Rechte anfordern .............................................................................................................. 82
Kepler Rechte Anfordern .................................................................................................................. 83
Eclipse Kepler aufsetzen ................................................................................................................... 85
Windows-8 ........................................................................................................................................... 87
Installation of Windows-8 ................................................................................................................ 87
Classic Start-up Menu for Windows-8 .............................................................................................. 87
Office installation ............................................................................................................................. 87
Other installations ............................................................................................................................ 87
JUnit ..................................................................................................................................................... 88
Create a JUnit test ............................................................................................................................ 88
Test-Abdeckung (Coverage) ............................................................................................................. 89
Install EclEmma Plugin.................................................................................................................. 89
Run Test with coverage report ..................................................................................................... 90
Common Help ...................................................................................................................................... 91
Finden der aktuelle IP eines Computers ........................................................................................... 91
Helpfull Links for EJB / Web-Service ................................................................................................. 92
Tricks and Tipps for Eclipse............................................................................................................... 93
New jar to eclipse project............................................................................................................. 93
Shortcuts in Eclipse....................................................................................................................... 94
Automated publishing when source has been saved ................................................................... 95
Seite 3
Java Setup
Download JDK (Java Development Kit)
Download the latest 32-bit JDK from http://www.oracle.com/technetwork/java/javase/downloads/.
(January 2015: version 8u31)
Accept their License Agreement after carefully reading it by selecting the left radio-button. Choose
the Windows x86 version from the List and download it.
JDK has to be 32-bit (x86) even on a 64-bit operating system.
Seite 4
Install JDK
Run the previously downloaded file and follow the instructions. The JDK includes the JRE so you have
to specify both installation paths. Both of them shouldn’t be changed so they’re installed to
“C:\Program Files (x86)\Java”.
Seite 5
Glassfish Server Setup
Download Glassfish
Download the latest Full Platform Server from https://glassfish.java.net/download.html.
(January 2015: version 4.1)
Install Glassfish
Extract the compressed zip-file to C:\glassfish.
Further Steps to Setup the Glassfish Server will be taken after eclipse is installed (next chapter).
Seite 6
Eclipse for JEE Developers Setup
Download Eclipse
Download the latest 32-bit version of Eclipse for JEE from https://www.eclipse.org/downloads/.
(January 2015: version 4.4.1 Luna)
Seite 7
Setup Eclipse
Extract the previously downloaded zip-file to C:\eclipse. When it’s done extracting, run
eclipse.exe from the new folder and select your workspace which should be somewhere in your
documents folder. Optionally you can create a shortcut on your desktop for faster access.
Install JDK in Eclipse
Windows > Preferences and go to the menu Java > Installed JREs.
On the right, click on Add... and navigate to the JDK installation directory.
Delete jre entry:
Seite 8
Seite 9
Seite 10
Add Glassfish Tools for Eclipse
Help > Eclipse Marketplace. Search for “glassfish” and install the corresponding package.
After that, restart Eclipse.
Seite 11
Setup Glassfish with Eclipse
After restart Eclipse, change your view in the top right corner to Java EE. Then click on the Serverstab which should be at the bottom area. Afterwards click on the blue underlined text to setup a new
one.
Select Glassfish 4.0 and click on Next >.
Seite 12
The JDK should be set to Eclipse Default and the Glassfish Server Directory should point to the
installation. Then click on next.
The Domain Directory should point to C:\glassfish\glassfish\domains\domain1
Administrator Id should be set to admin and the Password should be left blank. Click on
Finish.
Seite 13
Start Glassfish Admin Console
Seite 14
Right click the server and start it. Then you have to allow the access of the Server when you
are prompted. After that right click on Glassfish Select Glassfish à View Admin Console and
then (after a while) you will see picture above.
Seite 15
J2EE development
Create first Servlet and JSP, deploy and run it
Right click in Project section of eclipse right click new à Dynamic Web Project
index.jsp has been created in WebContent of the project. Double-Click on index.jsp to open
it in editor and run it.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Seite 16
Create Servlet:
Right click on the project and new à Servlet or if Servlet not listed go to new à Other ….
Tipp: If you just like to press CTRL-S (to save the changes in the source code) and exclipse
automatically deploys it to the application-server, check hier!
Seite 17
First Servlet Code
Replace in the generated Servlet-Class all methods with the code from below:
public FirstServlet() {
super();
System.out.println("FirstServlet ctr is called! Object created!!!");
}
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println("FirstServlet init() is called!");
}
public void destroy() {
System.out.println("FirstServlet destroy() is called!");
}
private void serveRequest(HttpServletRequest request, HttpServletResponse response, String methode)
throws ServletException, IOException {
response.setContentType("text/html");
StringBuffer sb = new StringBuffer("<html>\n<head>\n</head>\n<body>\n");
sb.append("<H1>Hallo HWZ!!</H1> Methode:<B>" + methode + "</B><br/>\n");
sb.append("</body>\n</html>\n");
response.getWriter().print(sb);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
serveRequest(request, response, "doGet");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
serveRequest(request, response, "doPost");
}
Create Bean to get called from Servlet / JSP in the same dynamic Web-Project
Create New -> Other…
Seite 18
Code for bean:
package com.rothlin.hwz;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless
@LocalBean
public class A_Bean implements A_BeanRemote, A_BeanLocal {
private int counter;
public A_Bean() {
System.out.println("Konstruktor von A_Bean aufgerufen!");
counter = 10;
}
Code for
}
public String sayHello(String name) {
counter++;
return "HALLO
" + name + ": Der Counter ist: " + counter;
}
Local
and Remote Interface:
package com.rothlin.hwz;
import javax.ejb.Remote;
@Remote
public interface A_BeanRemote {
public String sayHello(String name);
}
package com.rothlin.hwz;
import javax.ejb.Local;
@Local
public interface A_BeanLocal {
public String sayHello(String name);
}
Seite 19
Call Bean-methode from Servlet (same web-App):
Add the following code to FirstServlet.java:
@EJB
A_Bean myBean;
public FirstServlet() {
super();
System.out.println("FirstServlet ctr is called! Object created!!!")
}
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println("FirstServlet init() is called!");
}
public void destroy() {
System.out.println("FirstServlet destroy() is called!");
}
private void serveRequest(HttpServletRequest request, HttpServletResponse response, String methode)
throws ServletException, IOException {
response.setContentType("text/html");
StringBuffer sb = new StringBuffer("<html>\n<head>\n</head>\n<body>\n");
sb.append("<H1>Hallo HWZ!!</H1> Methode:<B>" + methode + "</B><br/>\n");
sb.append("<H2>" + myBean.sayHello("Walti")
sb.append("</body>\n</html>\n");
response.getWriter().print(sb);
+ "</H2>\n");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
serveRequest(request, response, "doGet");
}
Call Bean-methode from JSP (same web-App):
Add the following code to index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page
<jsp:useBean
import ="com.rothlin.hwz.A_Bean" %>
id
="userBean" class="com.rothlin.hwz.A_Bean" scope="session"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%= userBean.sayHello("HWZ") %><HR/>
</body>
</html>
Seite 20
Create an EJB (Enterprise Java Bean)
New EJB project in Eclipse
Seite 21
New “Session Bean (EJB3.x)”
Seite 22
First EJB Code
package hwz.rothlin.com;
import
import
import
import
javax.annotation.PostConstruct;
javax.annotation.PreDestroy;
javax.ejb.LocalBean;
javax.ejb.Stateless;
@Stateless
@LocalBean
public class TestBean implements TestBeanRemote, TestBeanLocal {
@PostConstruct
private void startup() {
System.out.println("TestBean: PostConstruct");
}
@PreDestroy
public void cleanup() {
System.out.println("TestBean: cleanup!");
}
public String ping() {
return "TestBean V1.0";
}
public TestBean() {
System.out.println("TestBean: ctr called!");
}
}
package hwz.rothlin.com;
import javax.ejb.Remote;
@Remote
public interface TestBeanRemote {
public String ping();
}
package hwz.rothlin.com;
import javax.ejb.Local;
@Local
public interface TestBeanLocal {
public String ping();
}
Seite 23
Deploy EJB
EJB project anklicken und Run as… Run on Server (only once)
A Portable JNDI name will be created (check serverlog):
INFO: EJB5181:Portable JNDI names for EJB TestBean: [java:global/testEJB/TestBean!hwz.rothlin.com.TestBeanRemote,
java:global/testEJB/TestBean!hwz.rothlin.com.TestBean, java:global/testEJB/TestBean!hwz.rothlin.com.TestBeanLocal]
Seite 24
Call EJB Methode from Servlet
Modify the servlet-code as following:
package com.rothlin.hwz;
import
import
import
import
import
import
import
import
import
java.io.IOException;
javax.naming.InitialContext;
javax.servlet.ServletConfig;
javax.servlet.ServletException;
javax.servlet.annotation.WebServlet;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;
testEJB.hwz.rothlin.com.TestBeanRemote;
@WebServlet("/FirstServlet")
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
TestBeanRemote aTestBean = null;
public FirstServlet() {
super();
System.out.println("FirstServlet ctr is called! Object created!!!");
}
public void init(ServletConfig servletConfig) throws ServletException {
System.out.println("SimpleServlet init() is called!");
System.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
try {
InitialContext ctx = new InitialContext();
ctx.addToEnvironment("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
ctx.addToEnvironment("org.omg.CORBA.ORBInitialPort", "3700");
aTestBean = (TestBeanRemote) ctx.lookup
("java:global/testEJB/TestBean!hwz.rothlin.com.TestBeanRemote");
}
catch (Exception ex) {
System.out.println("Couldn’t create converter bean!" + ex);
}
}
public void destroy() {
System.out.println("FirstServlet destroy() is called!");
}
private void serveRequest(HttpServletRequest request, HttpServletResponse response, String methode)
throws ServletException, IOException {
response.setContentType("text/html");
StringBuffer sb = new StringBuffer("<html>\n<head>\n</head>\n<body>\n");
sb.append("<H1>Hallo HWZ!!</H1> Methode:<B>" + methode + "</B><br/>\n");
sb.append("<H2>" + aTestBean.ping() + "</H2>\n");
sb.append("</body>\n</html>\n");
response.getWriter().print(sb);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
serveRequest(request, response, "doGet");
}
}
Seite 25
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
serveRequest(request, response, "doPost");
}
Wichtig: wird nun der Code des EJB geändert und deployed, muss auch das Servlet neu geladen
werden (die init() function muss aufgerufen werden und eine neue Remote-Referenz via JNDI geholt
werden). Am einfachsten macht man das, indem der Servlet Code geändert wird und wieder
abgespeichert, so wird das Servlet ebenfalls neu deployed und init() aufgerufen.
Seite 26
Java-client calls EJB-Methode
Create new Java project
Seite 27
C:\glassfish3\glassfish\lib\gf-client.jar
Seite 28
Create new Java class
package com.rothlin.hwz;
import javax.naming.InitialContext;
public class TestClient_EJB {
public void runTest() throws Exception {
System.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
InitialContext ctx = new InitialContext();
/* calling stateless session bean */
System.out.println("Calling TestBean (Session stateless)");
ctx.addToEnvironment("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
ctx.addToEnvironment("org.omg.CORBA.ORBInitialPort", "3700");
TestBeanRemote bean = (TestBeanRemote) ctx.lookup
("java:global/testEJB/TestBean!hwz.rothlin.com.TestBeanRemote");
System.out.println(bean.ping());
}
public static void main(String[] args) {
TestClient_EJB cli = new TestClient_EJB();
try {
cli.runTest();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Seite 29
Create interface file in same project (new à interface):
package hwz.rothlin.com;
public interface TestBeanRemote {
public String ping();
}
Projekt-Verzeichnisse nach dem fertigstellen:
Seite 30
Create a Java Client which calls a public Web-Service
Used Web-Service: http://www.webservicex.net/geoipservice.asmx?WSDL (Converts an IP-address to a country name)
Create new “Dynamic Web Project”:
Seite 31
Creating Client Stub from WSDL:
In dos-promt:
mkdir sei
cd sei
mkdir src
wsimport –keep –s src http://www.webservicex.net/geoipservice.asmx?WSDL
Import the generated stub into your project:
Create the package (net.webservicex) in your eclipse project where the generated files belong to and
drag them from the file-browser to the eclipse package.
Seite 32
Funktioniert so nicht über eclipse!!!!!!
Creating Client Stub from WSDL: Create new à Other “Web Service Client”:
http://www.webservicex.net/geoipservice.asmx?WSDL
Seite 33
Creating Client calling the Stub: Create new à Other “Web Service Client”:
package com.rothlin.ws_client;
import net.webservicex.GeoIP;
import net.webservicex.GeoIPService;
import net.webservicex.GeoIPServiceSoap;
public class WebServiceClient {
static public String getCountryNameForIP(String ipAddress) {
// from WSDL: <wsdl:service name="GeoIPService">
GeoIPService ipService = new GeoIPService();
// from WSDL: <wsdl:port name="GeoIPServiceSoap">
GeoIPServiceSoap geoIPServiceSoap = ipService.getGeoIPServiceSoap();
GeoIP geoIp = geoIPServiceSoap.getGeoIP(ipAddress);
return geoIp.getCountryName();
}
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("You need to pass one IP address!");
System.out.println("\nSome test cases:");
String ipAddress = "193.134.255.237";
System.out.println(ipAddress + " --> " + getCountryNameForIP(ipAddress));
ipAddress = "212.58.246.103";
System.out.println(ipAddress + " --> " + getCountryNameForIP(ipAddress));
} else {
String ipAddress = args[0];
System.out.println(ipAddress + " --> " + getCountryNameForIP(ipAddress));
}
}
}
Seite 34
Create first own WEB-Service
Create new project (Dynamic Web Project)
Seite 35
Create new Java Class
Add the following code:
package com.rothlin.webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class FirstWebService {
// Methodes in a web-Service are called Operations
// Operation names can not be overloaded (
@WebMethod
public String sayHello() {
return "Hello HWZ";
}
@WebMethod() // ctrl-space shows you the options
public String sayHelloName(String name) {
return "Hello " + name;
}
}
Seite 36
@WebMethod(exclude=false)
public String sayAnredeName(String anrede, String name) {
return anrede + " " + name;
}
Run java class on Server and check Admin Console
To test the Operation
Seite 37
To get the generated WSDL
To test the Web-Service without writing a client, click on the Tester-Link on the above screen of the
console screen.
Seite 38
Seite 39
Create Java-Client calling own WEB-Service
Create new project (Dynamic Web Project) WS_ClientForOwnWS
Create package: com.rothlin.webservice and import all files produced via wsimport from WSDL
Create package: com.rothlin.ws_client and create WebServiceClient
package com.rothlin.ws_client;
import com.rothlin.webservice.FirstWebService;
import com.rothlin.webservice.FirstWebServiceService;
public class WebServiceClient {
static public String sayHello() {
FirstWebServiceService ws = new FirstWebServiceService();
FirstWebService wsPort = ws.getFirstWebServicePort();
return wsPort.sayHello();
}
static public String sayHello(String name) {
FirstWebServiceService ws = new FirstWebServiceService();
FirstWebService wsPort = ws.getFirstWebServicePort();
return wsPort.sayHelloName(name);
}
public static void main(String[] args) {
String aName = "Walti";
System.out.println(sayHello());
System.out.println(sayHello(aName));
}
}
Seite 40
Create TCP/IP Server-Client
import java.io.*;
import java.net.*;
class TCP_Server {
public static void main(String argv[]) throws Exception {
String clientSentence;
String upperSentence ;
ServerSocket welcomeSocket = new ServerSocket(6789);
System.out.println("TCP/IP Server started!");
while(true) {
System.out.println("TCP/IP Server waiting to be called....");
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(
new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Received from Client: " + clientSentence);
upperSentence
}
}
Seite 41
}
= clientSentence.toUpperCase() + '\n';
System.out.println("Sent back to Client : " + upperSentence );
outToClient.writeBytes(upperSentence);
import java.io.*;
import java.net.*;
class TCP_Client {
public static void main(String argv[]) throws Exception {
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(
new InputStreamReader(System.in));
Socket clientSocket = new Socket("localhost", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
System.out.print("Enter a String
sentence = inFromUser.readLine();
System.out.println("Sent to SERVER
: ");
: " + sentence);
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("Received from SERVER: " + modifiedSentence);
clientSocket.close();
System.out.println("Client terminated!!!!!");
}
Seite 42
}
Create TCP/IP Server-Client advanced
import java.io.*;
import java.net.*;
public class TCP_Server_1 {
private static String businessFct_A(String msg) {
return msg.toUpperCase() + '\n';
}
private static String businessFct_B(String msg) {
return msg.toLowerCase() + '\n';
}
public static void main(String argv[]) throws Exception {
String clientMsg;
String replyMsg;
ServerSocket welcomeSocket = new ServerSocket(6789);
System.out.println("TCP/IP Server started!");
while(true) {
System.out.println("TCP/IP Server waiting to be called....");
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(
new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientMsg = inFromClient.readLine();
System.out.println("Received from Client: " + clientMsg);
String[] msgParts = clientMsg.split(":");
String fctName
= msgParts[0];
String stringMsg = msgParts[1];
System.out.println("
Function : " + fctName);
System.out.println("
Parameter: " + stringMsg);
if (fctName.equals("toUpper")) {
replyMsg = businessFct_A(stringMsg);
} else if (fctName.equals("toLower")) {
replyMsg = businessFct_B(stringMsg);
} else {
replyMsg = "ERROR: Unknown Function " + fctName + '\n';
}
System.out.println("Sent back to Client : " + replyMsg );
outToClient.writeBytes(replyMsg);
}
}
}
Seite 43
import java.io.*;
import java.net.*;
public class TCP_Client_1 {
public static void main(String argv[]) throws Exception {
String sentence;
String fctName;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader(
new InputStreamReader(System.in));
Socket clientSocket = new Socket("localhost", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
System.out.print("Enter function name : ");
fctName = inFromUser.readLine();
System.out.print("Enter a String
: ");
sentence = inFromUser.readLine();
System.out.println("Sent to SERVER
: " + fctName + ":" + sentence);
outToServer.writeBytes(fctName + ":" + sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("Received from SERVER: " + modifiedSentence);
clientSocket.close();
System.out.println("Client terminated!!!!!");
}
}
Seite 44
Create RMI Client-Server
Create new Java-Project with name RMI_ExampleInterface
Create package com.interf.test
Create class TestRemote
package com.interf.test;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface TestRemote extends Remote{
public boolean isLoginValid(String username) throws RemoteException;
}
Create class with Const definitions Constant
package com.interf.test;
public class Constant {
public static final String RMI_ID = "TestRMI";
public static final int RMI_PORT = 222;
}
Seite 45
Create new Java-Project for the RMI-Server and name it RMI_ExampleServer
Create package com.test
Create class RemoteImpl
package com.test;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import com.interf.test.TestRemote;
public class RemoteImpl extends UnicastRemoteObject implements TestRemote {
private static final long serialVersionUID = 1L;
protected RemoteImpl() throws RemoteException {
super();
}
@Override
public boolean isLoginValid(String username) throws RemoteException {
if (username.equals("test")) {
return true;
}
return false;
}
}
Create class RMIServer
package com.test;
import
import
import
import
java.rmi.AlreadyBoundException;
java.rmi.RemoteException;
java.rmi.registry.LocateRegistry;
java.rmi.registry.Registry;
import com.interf.test.Constant;
public class RMIServer {
public static void main(String[] args)
throws RemoteException, AlreadyBoundException {
RemoteImpl impl = new RemoteImpl();
Registry registry = LocateRegistry.createRegistry(Constant.RMI_PORT);
registry.bind(Constant.RMI_ID,impl);
System.out.println("Server is started!");
}
}
Seite 46
Create new Java-Project for the RMI-Client and name it RMI_ExampleClient
Create package com.client
Create class TestClient
package com.client;
import
import
import
import
java.rmi.NotBoundException;
java.rmi.RemoteException;
java.rmi.registry.LocateRegistry;
java.rmi.registry.Registry;
import com.interf.test.Constant;
import com.interf.test.TestRemote;
public class TestClient {
public static void main(String[] args)
throws RemoteException, NotBoundException {
Registry registry = LocateRegistry.getRegistry("localhost", Constant.RMI_PORT);
TestRemote remote = (TestRemote) registry.lookup(Constant.RMI_ID);
System.out.println(remote.isLoginValid("test"));
System.out.println(remote.isLoginValid("TEST"));
}
}
Seite 47
Visual C++ 2013 Runtime
http://www.microsoft.com/de-ch/download/details.aspx?id=40784
In order to use the MySQL Workbench which will be installed in the next step, the Microsoft
Visual C++ 2013 Runtime is required.
Select the English 32 bit (x86) file and download it by clicking next. After the download
execute it.
Double-click on the downloaded package and get it installed.
Seite 48
MySql
http://www.youtube.com/watch?v=Rnq8DS05PwQ
http://www.youtube.com/watch?v=4oChG9--iMM
Seite 49
Download and Install MySql
http://dev.mysql.com/downloads/mysql/
Oracle: [email protected] (8ZUqdn007)
Seite 50
mysql-installer-community-5.6.22.0.msi
Start installation
Seite 51
Fix if “Developer Default” doesn’t work:
Choose “Custom” and select the components manually. The specific components are in the second
picture below.
Seite 52
Seite 53
Seite 54
admin
admin
Seite 55
Seite 56
Seite 57
Seite 58
Create local User in MySQL Workbench
Start MySQL Workbench
Goto User and Privileges
Seite 59
Add Entry -> % (any Schema) -> OK -> Select all
Seite 60
Test MySQL
Start-Menu à MySQL à MySQL Server 5.5 àMySql Command Line Client
Password: admin
List all defined DBs (show databases;)
Seite 61
Give a Remote Computer access to MySQL
Um einem anderen Computer die Berechtigung zu geben auf eine MySql DB zuzugreifen, starten Sie
My SQL Workbench:
1. Add Account
2. Add IP Adresse des Remote-Host, welcher auf die DB zugreifen möchte.
Gebe diesem Account die nötigen Rechte:
Seite 62
Seite 63
Download mySql JDBC driver
https://downloads.mariadb.com/files/mysql-connector-java-5.1
download zip file and extract it.
Then move the connector (mysql-connector-java-*.*.*-bin.jar) to: C:\glassfish4\glassfish\lib
Otherwise it won’t work.
Seite 64
Download and Install MySql Eclipse Plugin
Eclipse -> Help -> Marketplace and search for Toad
Toad extension
Seite 65
admin
Seite 66
DBeaver
Restart Eclipse (you will be asked for)
Switch to Database Developer Perspective
Seite 67
Right Mouse-Click on Database Connections
Seite 68
Seite 69
Select the MySQL JDBC Driver with the matching System Version (January 2015: 5.1) and select the
«Jar List»-Tab.
Seite 70
Remove the current Jar in the list and click on «Add JAR/Zip…». Then navigate to the installation
directory of the glassfish-server and select the driver in the directory «…/glassfish/lib».
Click on «Open» and «OK».
Seite 71
admin
Seite 72
Basic MySql commands
Start MySql Command Line Client to find out which DB are already defined
show databases;
use test;
show tables;
create table Classmates (
id int PRIMARY KEY NOT NULL,
fname varchar(25),
lname varchar(25)
);
CREATE UNIQUE INDEX PRIMARY ON classmates(id);
INSERT INTO classmates (id, lname, fname)
VALUES (1,'David','Etter');
Seite 73
DB Connection über JNDI auf dem Application Server einrichten
Glassfish Admin-Console starten und unter Resourcen à JDBC à JDBC ConnectionPools einen
neuen Pool anlegen. Hier wird unter einem Namen eine DB Connection String abgespeichert! Nicht
als ein einziger String, sondern als einzelne Felder!)
Seite 74
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
Bis zum Ende der Seite scrollen und die folgenden Properties setzen:
User à admin
Password à admin
Database à onlineshop
Url à jdbc:mysql://localhost:3306/onlineshop
URL à jdbc:mysql://localhost:3306/onlineshop
Danach zwingend mit FINISH am Ende oder Anfang der Seite abschliessen und mit Ping austesten
Seite 75
(Die Werte der Properties können in der DB Perspective gefunden werden)
Neue JNDI Resource definieren, welche auf diese DB-Connection verweist:
JDBC Resources à New….
Seite 76
Insalling XAMPP instead of MySql
https://www.apachefriends.org/
1. Installer starten
a. UAC Warnmeldung ist normal wenn UAC aktiviert ist und stellt mit mysql kein
Problem dar
Seite 77
b. Hier nur die benötigten Packete auswählen
i. MySQL
Seite 78
c. Standard Installationspfad belassen
Seite 79
Seite 80
2. Kontrollpanel nutzen um MYSQL starten
Up&Running
Seite 81
CS IDesktop Setup
AppDevs Rechte anfordern
Als erstes braucht man Rechte um die “eclipse.ini” Datei, welche erst später durch die Installation
von Kepler erzeugt wird, umzuschreiben. Dazu geht man auf diese Seite. :
http://uaa3.csintra.net/request_membership.aspx
Klicken Sie auf Add Groups.
Suchen Sie nach „DSO-CS-CH-AppDevs“.
Selecktieren Sie die Gruppe. Und klicken Sie auf Done.
Seite 82
Kepler Rechte Anfordern
Gehen Sie auf MyAccess (http://myaccess.app.csfb.net/myaccess/)
Klicken Sie auf „Create Request“. Dann wählen Sie „Applications“ und „Myself“. Dann auf „Next“.
Suchen Sie nach “Eclipse”
Klicken Sie auf “Eclipse” in der Spalte “Application Name”
Seite 83
Danach wählen Sie Eclipse Kepler aus und klicken auf ok.
Sobald Sie ein Bestätigungsmail von MyAccess bekommen haben, gehen Sie in iDApps und
installieren Eclipse Kepler.
Seite 84
Eclipse Kepler aufsetzen
Wenn Sie Kepler installiert haben, probieren Sie es zu starten. Falls dies erfolgreich war, können Sie
zum nächsten Kapitel. Das folgende erklährt wie man vorgehen muss, wenn man eine solche oder
ähnliche Fehlermeldung erhällt. :
Falls dies der Fall ist, gehen Sie in das Verzeichnis „C:\Apps\Eclipse_4.3_SR1“ und Editieren Sie das
File „eclipse.ini“. Dies folgenden Informationen stammen von hier:
MyAccess+Process+
to+Request+AppDevs+Rights.docxversion=1&modificationDate=1338475307000.URL
Wichtig!
Verändern Sie das eclipse.ini File nur wie vorgegeben! Es kann zu schweren Fehlern führen, wenn Sie
etwas falsch verändern!
Die Markierte Linie müssen Sie verändern.
Seite 85
Sie müssen nun den Pfad der Datei „jawaw.exe“ angeben.
Die JDK finden Sie hier (:P/ Laufwerk) Laden Sie die JDK herunter und geben Sie deren Pfad im
eclipse.ini File an. Speichern Sie das File.
Wichtig!
Diese JDK muss angegeben werden, um Glassfish nutzen zu können!
Mit anderen JDK’s geht es nicht!
Nun öffnen Sie Kepler.
Sie können nun an dieser Stelle fortfahren: Fehler! Verweisquelle konnte nicht gefunden werden.
Seite 86
Windows-8
Installation of Windows-8
•
•
•
•
•
•
•
•
•
•
Put DVD in and press during start-up F12
Select full installation (advanced)
Delete all disk partitions
Start set-up (takes a while)
Enter Hostname
Get online (skip this step)
Settings (Use Express settings)
Your account (admin no password)
Restart
Activate windows (Settings –> Change PC settings)
Classic Start-up Menu for Windows-8
•
•
Download Classic Power Shell and install (English)
Restart computer
Office installation
•
•
•
•
Insert DVD and install it
Start up word; Open a new document
Go to Datei à Konto and add the key:
Install language pack for office
Other installations
•
•
•
Lego Mindstorm (2.0 & EV3)
Notepad++ English
Mozilla FireFox
Seite 87
JUnit
Create a JUnit test
New – JUnit Test Case
Implementing Tests and run it as JUnit Test
Seite 88
Test-Abdeckung (Coverage)
Install EclEmma Plugin
Eclipse: Help à Eclipse Marketplace…
Search for EclEmma and install it.
Seite 89
Run Test with coverage report
Seite 90
Common Help
Finden der aktuelle IP eines Computers
cmd à ipconfig
(Beispiel unten: Computer ist über Ethernet und WiFi connected, desshalb 2 IP-Adressen)
Seite 91
Helpfull Links for EJB / Web-Service
http://www.youtube.com/watch?v=9Kf5m7bMu74
Part 1 (Installation)
http://www.youtube.com/watch?v=ppGqtOeHm-g
Part 2 (Servlet calling EJB, JSP, timer-EJB)
http://www.youtube.com/watch?v=CuLYhkqt0V0
Part 3 (JPA)
http://www.http://www.youtube.com/watch?v=1epUpQlKwME
Part 4 (Facelets / JSF 2)
http://www.youtube.com/watch?v=on557289GzA
Part 5
http://www.youtube.com/watch?v=aBjlR9HoR50
Langes vollständiges Beispiel von JSP, Servlet,
DB-Connection, JPA, EJB, Web-Services
SOAP (JAX-WS):
https://www.youtube.com/watch?v=mKjvKPlb1rA
https://www.youtube.com/watch?v=C53G6R5EVys
https://www.youtube.com/watch?v=6hqDMS-oJ9k (Creating stub for a public WSDL)
https://www.youtube.com/watch?v=KFlDdb65w3U (Call the stub)
https://www.youtube.com/watch?v=Zx6NuO6niFI (Set up J2EE)
https://www.youtube.com/watch?v=S0zdMGNrxr0 (Theorie Service first vs contract first)
REST (JAX-RS):
https://www.youtube.com/watch?v=gKBiIWY7FYw&list=PLu47tUtKqNlwfR-nqjiWUaIWOYEi9FyW0
https://www.youtube.com/watch?annotation_id=annotation_401609&feature=iv&src_vid=gKBiIWY7FYw&v=4DY46f-LZ0M
https://www.youtube.com/watch?v=xkKcdK1u95s
REST Web Services 01 – Introduction:
Web-Service:
6) https://www.youtube.com/watch?v=9kb0iLpqKY4
7) https://www.youtube.com/watch?v=u5cQkVgq6jE
8) https://www.youtube.com/watch?v=HLzM92ZnisY
Web-Service Vorlesung: https://www.youtube.com/watch?v=dbxASThtC_g
Download Netbeans-All-Included Package
https://netbeans.org/downloads/
Seite 92
Tricks and Tipps for Eclipse
New jar to eclipse project
Project anclicken --> Rechte Mouse Taste --> Build Path --> Configure Build Path....
For junit
Seite 93
Shortcuts in Eclipse
Linke Mousetaste
ctrl - F11
ctrl - SPACE
sysout ctrl - SPACE
open declaration
run application
auto complete
system.out.println();
select string F2
shift - F2
Tooltip in box mit scrollbar anzeigen
Java Doc in Browser öffnen
Seite 94
Automated publishing when source has been saved
Application-Server starten
2. Select
1. Double click
Seite 95
Seite 96
Herunterladen