Tomcat

From no name for this wiki
Jump to: navigation, search

Tomcat Stuff

Datasource einrichten in Tomcat

Datei context.xml im META-INF Verzeichnis einer Webapplikation anlegen.

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/WebLearingPlatform">
   <Resource name="jdbc/WebLearningPlatform"
           auth="Container"
           type="javax.sql.DataSource"
           username="dbusername"
           password="dbpassword"
           driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
           url="jdbc:derby:Databases/WebLearningPlatform;create=true"
           maxActive="8"
           maxIdle="4"/>
</Context>

in der web.xml Datei eine Referenz einfuegen:

 <resource-ref>
       <res-ref-name>jdbc/WebLearningPlatform</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>

Im Code kann wie folgt auf die JDBC Connection zugegriffen werden.

 Context initCtx = new InitialContext();
 Context envCtx = (Context) initCtx.lookup("java:comp/env");
 DataSource ds = (DataSource) envCtx.lookup("jdbc/WebLearningPlatform");
 con = ds.getConnection();

Im Tomcat geht man mit Nameskonvention, java:comp/env/jdbc/WebLearningPlatform referenziert automatisch auf jdbc/WebLearningPlatform

Port ändern von Tomcat

Im Verzeichnis TOMCAT_HOME\conf die Datei server.xml anpassen;

<Connector port="8081" protocol="HTTP/1.1" 
              connectionTimeout="20000" 
              redirectPort="8443" URIEncoding="UTF-8" />

Tomcat Admin Konsole aufrufen

Im Ordner TOMCAT/conf die Datei tomcat-users.xml wie folgt anpassen:

<tomcat-users>
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
-->
    <user password="adminadmin" roles="manager,admin" username="admin"/>
</tomcat-users>

Dann die URL http://localhost:8080/manager/html aufrufen.