使用Maven构建Web项目

参考 http://blog.csdn.net/yuguiyang1990/article/details/8796410

1.新建Maven项目

1.1 File -> New -> Other

1365863541_5385

1.2 选择Maven Project ,单击Next

1365863553_1351

1.3 保持默认即可,单击Next

1365863566_6467

1.4 选择Archetype为 web app,单击Next

1365863577_7171

1.5 输入一些必要信息,单击Finish

1365863587_8509

1.6 项目结构如下图:

1365863599_9491

或者如下图

在Mac下面的Eclipse Kepler中目录的位置有所变化

screenshot

2.配置项目(某些修改实际工作中用不到,以下仅供参考

现在开始修改一些配置

2.1 在项目上右键单击,添加Source Folder

Maven的项目有一些约定:src/main/java , src/main/resources , src/test/java , src/test/resources .那么,添加这些文件夹:(注意,创建文件夹有可能失败,比如Kepler 上面,此时,到目录下面直接创建文件夹然后刷新Eclipse项目就可以了

1365863613_2412

输入Source Folder 的名字

1365863628_6400

创建完之后的目录结构:

1365863640_6524

2.2 修改Build Path 配置

在项目上,右键单击,选择 Build Path ->Configure Build Path

1365863656_2376

选择 Source标签,会显示4个Source Folder ,修改他们的 OutPut folder :

1365863670_3566

双击每个文件夹的Output folder,选择路径

src/main/java,src/main/resources,选择target /classes;
src/test/java ,src/test/resources, 选择target/test-classes;

1365863682_6273

修改完成后如下图所示:

1365863693_6468

修改JDK版本:选择 libraries 标签,选中JRE library,单击Edit按钮

1365863704_4952

选择系统默认的就可以了,单击 Finish 按钮:

1365863729_2512

最后,单击OK即可:

1365863769_4461

完成后,项目结构如下图:

1365863781_4158

2.3 将项目转换为Dynamic Web Project

在项目上右键单击,选择 Properties:

1365863806_5537

在左侧选择 Project Facets,单击右侧的 ”Convert faceted from “链接:

1365863817_6166

修改Java为你当前项目的JDK,并添加Dynamic Web Module ,最后单击”Further Configuration available“ 链接:

1365863830_6294

修改Content directory 为 src/main/webapp ,单击OK:

1365863840_2584

在一次单击OK,完成操作:

1365863853_7859

2.4 设置部署程序集(Web Deployment Assembly)

在项目上右键单击,选择Properties,在左侧选择Deployment Assembly

1365863864_8268

此处列表是,部署项目时,文件发布的路径。
1,我们删除test的两项,因为test是测试使用,并不需要部署。
2,设置将Maven的jar包发布到lib下。
Add -> Java Build Path Entries -> Maven Dependencies -> Finish
设置完成效果图
1365863878_5803

单击OK

完成后,项目结构如下图所示:

1365863887_1279

就这样,使用Maven构建的一个Web项目就完成了。

Eclipse debugger always blocks on ThreadPoolExecutor without any obvious exception

I'm working on my usual projects on Eclipse, it'a a J2EE app, made with Spring, Hibernate and so on. I'm using tomcat7 for this (no particular reason, I don't exploit any new feature, I just wanted to try that). Every time I debug my application, it happens that eclipse debugger pops out like it has reached a breakpoint, but it is not the case, in fact it stops on a Java Source File that is ThreadPoolExecutor. There is no stack trace on the console, it just stops. Then if I click on resume it goes on and the app works perfectly. This is what shows in the debugger window:

Daemon Thread ["http-bio-8080"-exec-2] (Suspended (exception RuntimeException))
ThreadPoolExecutor$Worker.run() line: 912
TaskThread(Thread).run() line: 619

I really can't explain this, because I'm not using ThreadPoolExecutor at all. Must be something from Tomcat, Hibernate or spring. It's very annoying because I always have to resume during debugging.

Any clues?

The posted stack trace indicates that a RuntimeException was encountered in a Daemon thread. This is typically uncaught at runtime, unless the original developer caught and handled the exception.

Typically, the debugger in Eclipse is configured to suspend execution at the location where the exception was thrown, on all uncaught exceptions. Note that the exception might be handled later, lower down in the stack frame and might not lead to the thread being terminated. This would be cause of the behavior observed.

Configuring the behavior of Eclipse is straightforward - in the Preferences Dialog, the Debug pane under Java in the tree hierarchy, has the option titled "Suspend execution on uncaught exceptions", which can be unchecked.

junit4入门例子

第一步:eclipse中新建一个项目,java build path中导入junit jar包(本文例子junit-4.9b1.jar)

第二步:新建一个package,导入如下四个文件

第三步:右键AllCalculatorTests(或者CalculatorTest、SquareTest),run as junit test,查看执行结果。

代码中的注释能够帮你理解Junit4。

 

 

 

一个简单的Jsp+Servlet实例

开发环境Eclipse+Tomcat7

1、先创建web project,项目名为Hello,

2、在WebRoot 目录下创建login.jsp文件,只需修改body中的内容,如下所示:

3、在scr目录下的com.ht.servlet编写AcountBean.java文件,代码如下:

4、在scr目录下的com.ht.servlet编写servlet类CheckAccount.java文件,代码如下:

5、在WebRoot目录下编写success.jsp文件 成功后跳转

6、在WebRoot目录下编写fail.jsp文件 失败后跳转

7、修改web.xml配置文件

Eclipse add Tomcat 7 blank server name

I was trying to add Tomcat 7 in my Eclipse in Ubuntu. When I click "Add new server" in Eclipse and select "Tomcat v7.0 Server", the field "Server Name" is blank and I cannot type in anything in that textbox as shown below:

0pHnn

It is a bug in Eclipse. I had exactly the same problem, also on Ubuntu with Eclipse Java EE Juno.

Here is the workaround that worked for me:

1.Close Eclipse
2.In {workspace-directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings delete the following two files:
org.eclipse.wst.server.core.prefs
org.eclipse.jst.server.tomcat.core.prefs
3.Restart Eclipse

Tomcat在Mac平台安裝

到http://tomcat.apache.org下載tomcat版,例如apache-tomcat-7.0.42.tar.gz
将apache-tomcat-7.0.42.tar.gz 解压缩到目标目录
执行

设置管理用户密码:
编辑 apache-tomcat-7.0.42/conf/tomcat-users.xml , 加入


設定好後執行 apache-tomcat-7.0.42/bin/startup.sh , 再使用browser連到http://localhost:8080, 如果可以看到以下画面, Tomcat Server的安裝算是初步完成

Apache Tomcat_7.0.42_Default_Page

設定Launchd主要讓Mac OS X server啟動時, 也順便啟動Tomcat Server, Launchd有點類似Windows的NT Service使用Launchd來啟動Tomcat Server

1.到 apache-tomcat-7.0.42/bin/目錄下新增一個檔案 launchd_wrapper.sh, 內容如下

请注意 ,launchd_wrapper.sh要使用

使其具有执行权限

2. 加入tomcat for Launchd 文件, 到/Library/LaunchDaemons目录使用

新增tomcat.plist

3. 使用

, 编辑tomcat.plist, 文件內容如下, 要注意的是/Users/admin为安装目录, 请改成你的目录

4.手动测试Launchd


停止指令

测试OK后, 下次重新开机Tomcat Server就会自己执行了.

处理在64位Ubuntu使用jd-gui报错error while loading shared libraries: libgtk-x11-2.0.so.0

在64位Ubuntu中使用jd-gui反编译时出现错误:
error while loading shared libraries: libgtk-x11-2.0.so.0

此时,需要安装如下依赖包,即可:

(Ubuntu 13.04 x64)

(Ubuntu 13.10 x64)