XiaoKL

Java.web-application-development-environments-for-macosx

 

Java Web Application开发

1 下载需要的软件

使用的软件并没有采用最新的版本,只是采用了次新版本。

1.1 下载Eclipse的jee版本

eclipse-jee-luna-SR2-macosx-cocoa-x86_64.tar.gz

http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-jee-luna-SR2-macosx-cocoa-x86_64.tar.gz

1.2 下载JDK 7.0

jdk-7u79-macosx-x64.dmg

http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk7-downloads-1880260.html

1.3 下载Tomcat 7.0

apache-tomcat-7.0.63.zip

http://tomcat.apache.org/download-70.cgi

1.4 下载tomcatPluginV331.zip

http://www.eclipsetotale.com/tomcatPlugin.html

 

2 安装开发环境

2.1 安装JDK

双击 jdk-7u79-macosx-x64.dmg,然后step by step。

 

2.2 安装Tomcat 

Ref[3.1]

A: 解压apache-tomcat-7.0.63.zip 到目录 ~/Downloads/apache-tomcat-7.0.63

B: 运行以下命令

sudo mkdir -p /usr/local
sudo mv ~/Downloads/apache-tomcat-7.0.63 /usr/local

C: 运行以下命令

sudo rm -f /Library/Tomcat
sudo ln -s /usr/local/apache-tomcat-7.0.63  /Library/Tomcat

D: 运行以下命令

sudo chown -R <your_username> /Library/Tomcat

sudo chmod u+x /Library/Tomcat/bin/*.sh

E: 运行以下命令,启动和关闭Tomcat Server

/Library/Tomcat/bin/startup.sh

/Library/Tomcat/bin/shutdown.sh

 

2.3 安装Eclipse

将eclipse-jee-luna-SR2-macosx-cocoa-x86_64.tar.gz解压到 ~/your-dev-tools-path/eclipse-jee-luan

 

2.4 安装tomcatPluginV331.zip  (Sysdeo Eclipse Tomcat Launcher plugin)

解压tomcatPluginV331.zip得到com.sysdeo.eclipse.tomcat_3.3.1.jar,将该jar包复制到 ~/your-dev-tools-path/eclipse-jee-luan/dropins/ 目录下。

 

2.5 启动Eclipse,此时在其工具栏上会出现。 Figure-1: Tomcat Icon in Tool Bar 

 

2.6 配置Eclipse,首先检查JRE是否设置好,如Figure-2:JRE for Eclipse 

 

2.7 Web应用服务器的配置

Figure-3: Server Runtime Environments

 

 

2.8 为Tomcat进行配置

Figure-4: Tomcat Configuration

 

 

Q: Context declaration mode: Server.xml 和 Context files的区别是什么呢?

 

2.9 到此整个配置过程结束

点击工具条(Figure-1)中Tomcat Logo启动Tomcat Server。

在Eclpise中的Console中,会有下输出, Figure-5 Output in Console

在浏览器中输出:http://localhost:8080/, 来验证Tomcat Server是否已被正确启动。

 

3 创建Web Application Project

3.1 Tomcat Project

Ref[5] 

Eclipse中,File->New->Project...->Java->Tomcat Project, 然后点击Next, Figure-6: New Tomcat Project

 

 Demo: 

 

3.2 Dynamic Web Project

 

4 导入Web Application Project 

File->Import...->General->Existing Project into Workspace

Figure-7: Import Existing Project into Workspace

 

5. 如何调试 Web Application Project

Ref[7]

 

6. 打包部署Web Application Project

6.1 在Eclipse中打包Web Application Project 为war文件

Ref[10]

关于war文件的说明:

"In Java enterprise development, WAR (Web ARchive) is the standard container file format for

packaging Java EE applications as a single, deployable unit which can be deployed on Java EE-compliant

application servers like Tomcat, JBoss, Glassfish..." Ref[10]

6.2 部署war文件到tomcat server 

Ref[12]

A): 将war文件拷贝到$CATALINA_HOME\webapps目录下。

B): 如果tomcat server在运行中, 将tomcat停下来。删除由原来war解压得到的目录。

C): 启动tomcat server。

 

7. 用配置项来替代Web Application中hardcode的路径等

Ref[11]

用配置文件中配置项来替代Web Application中JSP/Servlet中hardcode的路径等信息。

 

 

 


 

Reference

1. Java Web开发环境的搭建(JDK+Eclipse+Tomcat)(Windows版本)

http://blog.csdn.net/zhugexubin/article/details/41726587

2. Eclipse导出war包

3. 安装Tomcat for Mac OS X

3.1 https://wolfpaulus.com/jounal/mac/tomcat7/

3.2 https://wolfpaulus.com/jounal/mac/tomcat8/

4. Sysdeo Eclipse Tomcat Launcher plugin

http://www.eclipsetotale.com/tomcatPlugin.html

5. 整合Eclipse与Tomcat开发第一个WEB程序  

http://lixiyu.blog.51cto.com/4136883/1346681 

参考创建Web App部分。

6. myeclipse 和 eclipse ide for javaee 下的java web项目目录结构对比

创建Web Project的步骤:

File->New->Project...->Web->

Dynamic Web Project

Static Web Project

Web Fragment Project 

7. 详解Eclipse Dynamic Web Project

http://blog.csdn.net/jbjwpzyl3611421/article/details/13297483 

参考 "4. 如何建一个Server" 和 "5.如何建立一个Dynamic Web Project,以及如何调试"。

8. Creating a Dynamic Web Project in Eclipse

http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.stardust.docs.wst%2Fhtml%2Fwst-integration%2Fdynamic-web-proj.html

9. JNDI Datasource HOW-TO

https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html 

关于"java:comp/env/jdbc/mysql"

Q: tomcat是如何通过"java:comp/env/jdbc/mysql"来链接上具体的MySQL Server Instance呢?

1 import javax.naming.InitialContext;
2 import javax.naming.NamingException;
3 import javax.sql.DataSource;
4 
5 .....
6 
7 DataSource dataSource = null;
8 InitialContext ctx;
9 dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");

 

10. Eclipse: Create deployable WAR file for Java web application

http://www.codejava.net/ides/eclipse/eclipse-create-deployable-war-file-for-java-web-application

11. 解压war文件,修改其中的文件,然后再压缩为war文件

11.1 Where to place and how to read properties files in a JSP/Servlet web application?

http://stackoverflow.com/questions/2161054/where-to-place-and-how-to-read-properties-files-in-a-jsp-servlet-web-application

11.2 How to unpackage and repackage a WAR file

http://stackoverflow.com/questions/19269961/how-to-unpackage-and-repackage-a-war-file

11.3 "解压war文件,修改其中的文件,然后再压缩为war文件" 是否可行?

http://www.coderanch.com/t/565599/tools/Manually-adding-java-class-files  

12. How to deploy a Java web application on Tomcat

http://www.codejava.net/servers/tomcat/how-to-deploy-a-java-web-application-on-tomcat 

13. Dynamic Web projects and applications (AAAA+)

http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html

讲解了 Dynamic Web Project的工程目录结构,以及目录各自的作用。

14. Java Util Logging Behaviour in Tomcat

http://app-inf.blogspot.tw/2012/10/java-util-logging-behaviour-in-tomcat.html

 


 

Todo

Q: Web Project vs. Tomcat Project的区别是什么呢?

 

posted on 2015-07-21 17:44  XiaoKL  阅读(638)  评论(0编辑  收藏  举报

导航