Here are the steps to set it up:
Once you singup and you will get “New Hosting Account Created” email from javaproject.net.
javaproject.net preload Tomcat, Java and MySQL already.
Your email from javaproject would like this:
SolusVM control panel https://cp.whitelabelbox.com:5656/
Username: yourgivenusername
Password: yourpasswd
RootPassword: yourpasswd
Main IP: 123.456.789.012
------ Set up ------
1. Login to the Server:You can login to MainIP using root/yourpasswd with SSH. For window, use putty.exe or cygwin
2. Quick Test Tomcat:
Then you can do quick test by starting tomcat:
Start tomcat:
cd to /home/tomcat/tomcat/bin
./startup.sh
Test: with web browser such as Firefox.
http://MainIP à http:// 123.456.789.012 you will see the tomcat home page.Stop tomcat:
./shutdown.sh3. Setup MySQL server.
In any directory of the server type in: mysql
3.1 create user and set privileges
mysql>grant all privileges on *.* to 'yourUser'@'localhost' identified by 'yourPassword' with grant option;
mysql>grant all privileges on *.* to 'yourUser'@'%' identified by 'yourPassword' with grant option;
mysql>quit
3.2 login with new user
mysql –h localhost –u yourUser –p
Enter Password: yourPassword
3.3 create new database
mysql>CREATE DATABASE yourdb;
mysql>use yourdb;
mysql> create table testdata (
id int not null auto_increment primary key,
foo varchar(25),
bar int);
mysql> insert into testdata values(null, 'hello', 12345);
mysql> select * from testdata;+----+-------+-------+
| 1 | hello | 12345 |
+----+-------+-------+
1 row in set (0.00 sec)
4. Set up Tomcat data source for database connection pool
Database source would be used by hibernate to deal with database connection.
Setting related to your war file or explored directory name, for our example yourapp.war
4.1 Create context.xml under your META-INF
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/yourDS" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"username="yourUser" password="yourPassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/yourdb"/>
where yourUser is the user you create at step 3.1
<resource-ref>
<description>MySQL Datasource example</description>
<res-ref-name>jdbc/yourDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.3 Create app specific xml file yourapp.xml under /home/tomcat/tomcat/conf/Catalina/localhost
<Context path="/tracking/">
type="javax.sql.DataSource" username="yourUser" password="yourPassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/yourdb " maxActive="8" maxIdle="4"/>
</Context>
Note:
1 The name of yourapp from yourapp.xml must be same as your war file name yourapp.war
2. Not sure why we need this, but it is required step in order to use data source. For me, it is required by Linux but not Win 7.
5. Set up hibernate.cfg.xml file
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/yourDS</property>
With those settings, you can upload your app with scp in cygwin or winscp to copy your war file or directory under /home/tomcat/tomcat/webapps
Start Tomcat, you are ready to see your app in the web browser. Congratulation you got it.
If you are experience slow SSH access or operation, see next post.
No comments:
Post a Comment