首页 > 代码库 > centos 安装glassfish4.0 配置jdbc连接mysql
centos 安装glassfish4.0 配置jdbc连接mysql
版本glassfish-4.0.zip
1、解压,拷贝到指定安装路径
unzip glassfish-4.0.zip cp cp glassfish4 /usr/local/ -rf
2、设置glassfish环境变量
vim /etc/profile export GLASSFISH_HOME=/usr/local/glassfish4 export PATH=.:$PATH:$JAVAHOME/bin:$MYSQLHOME/bin:$GLASSFISH_HOME/bin source /etc/profle
进入/usr/local/glassfish4/glassfish/config,编辑该目录下的asevn.conf文件,在文件末尾加入AS_JAVA="/usr/local/jdk"(值为本机jdk安装路径)
AS_JAVA="/usr/jdk1.7.0_60"
3、如果不想使用默认domain可在此步骤创建自己的domain,并指定domaindir和admin port
执行如下命令,创建端口为4848,名称为虹盘的domain
asadmin create-domain --adminport 4848 hongpan
Enter admin user name [Enter to accept default "admin" / no password]>
Bad Network Configuration. DNS can not resolve the hostname:
java.net.UnknownHostException: dev: dev: Name or service not known
Using port 4848 for Admin.
Using default port 8080 for HTTP Instance.
Using default port 7676 for JMS.
Using default port 3700 for IIOP.
Using default port 8181 for HTTP_SSL.
Using default port 3820 for IIOP_SSL.
Using default port 3920 for IIOP_MUTUALAUTH.
Using default port 8686 for JMX_ADMIN.
Using default port 6666 for OSGI_SHELL.
Using default port 9009 for JAVA_DEBUGGER.
Distinguished Name of the self-signed X.509 Server Certificate is:
[CN=localhost,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US]
Distinguished Name of the self-signed X.509 Server Certificate is:
[CN=localhost-instance,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US]
Domain hongpan created.
Domain hongpan admin port is 4848.
Domain hongpan allows admin login as user "admin" with no password.
Command create-domain executed successfully.
4、启动刚才建立的domain虹盘
asadmin start-domain hongpan
Waiting for hongpan to start .........................
Successfully started the domain : hongpan
domain Location: /usr/local/glassfish4/glassfish/domains/hongpan
Log File: /usr/local/glassfish4/glassfish/domains/hongpan/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
5、修改刚刚创建的domain的admin密码,并使之能够通过web登录到控制台
asadmin change-admin-password
Enter admin user name [default: admin]>
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.
每次操作的时候控制台都提示输入用户名密码,比较麻烦
可以建立密码配置文件
AS_ADMIN_PASSWORD=xxxx
6、开启远程登录权限
asadmin enable-secure-admin
Enter admin user name>
Enter admin password>
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.
7、重启domain
asadmin restart-domain hongpan
现在就可通过控制台进行管理了
下面开始配置jdbc连接mysql
1、拷贝连接mysql的jar包到glassfish库目录里
cp mysql-connector-java-5.1.16-bin.jar /usr/local/glassfish4/glassfish/lib/
2、重启domain
3、登陆mysql控制台,到JDBC连接池界面
点击new新建JDBC连接池
配置连接属性
测试连通性
Succeeded
4、创建JDBC资源,程序到时候只需要连接JNDI名称即可
下图JNDI Name填写名称,Pools Name选择刚才创建的JDBC连接池。
配置完成,大功告成!
本文出自 “央了个样” 博客,请务必保留此出处http://yayang.blog.51cto.com/826316/1439841