------------------------------------------------------------------------------------------
步骤:(以下步均为在命令行的输入)
------------------------------------------------------------------------------------------
第一步 通过APPFUSE创建基于Struts 2 Basic的项目:
mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.1 -DgroupId=com.yourproject -DartifactId=yourproject
mvn eclipse:eclipse
<genericCore>${amp.genericCore}</genericCore>
<fullSource>${amp.fullSource}</fullSource>
修改成:
<genericCore>false</genericCore>
<fullSource>true</fullSource>
注意,这里必须吧pom.xml中的genericCore属性设为false 否则只会生成Action
第四步:生成MODEL类
先执行,这样会把默认需要的相关类先生成
mvn appfuse:full-source
mvn appfuse:gen-model
mvn appfuse:gen -Dentity=你的MODEL类
这里可能会有一个提示找不到/src/main/resources/database.properties, 可以不用理会
如果设置了很复杂的关联,这个生成过程会很痛苦,老是报targeting an unmapped的错,
我的解决方法是找到关联的类比如USER,先把关系映射方法和属性删掉,
然后在再把/src/main/resources/hibernate.cfg.xml其他的类声明删掉
生成成功后再把这些加上去.
mvn appfuse:install
打完收工
struts的配置文件会生成到:/src/main/resources/struts.xml中
------------------------------------------------------------------------------------------
常用的命令介绍:
------------------------------------------------------------------------------------------
mvn appfuse:gen-model 根据数据库的表生成java类
mvn appfuse:gen 根据 POJOs.生成并安装 Tests, DAOs, Managers, Controllers and Views
mvn appfuse:full-source 把运行所需要的org.appfuse中的依赖类转换成你的包名称
mvn eclipse:eclipse 生成eclipse的项目的配置文件,用户可以直接把项目导入到eclipse中
mvn jetty:run-war 打包并且发布你的应用程序到Jetty, 查看在 http://localhost:8080
mvn appfuse:install 把生成的源代码及配置文件写入到src中
mvn integration-test 启动TOMCAT(或别的服务器)进行测试
mvn appfuse:remove 删除appfuse:gen.生成的代码
mvn appfuse:clean 清除target下的所有内容
需要注意的问题:
------------------------------------------------------------------------------------------
1.必须吧pom.xml中的genericCore属性设为false 否则只会生成Action
3.运行后出现gzip 该问题是压缩HTML的包导致,暂时屏蔽掉相关filter
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<ehcache.version>1.4.1</ehcache.version>
后再生成代码
当添加新的数据表时间,除了执行mvn appfuse:gen -Dentity=yourmodel外,还需要执行
mvn appfuse:install 来把DAO,STRUTS配置写入到SRC下的相应文件中.
默认情况下UserInfo会生成到com.my.app.model下,把配置改成
<mapping class="com.my.app.model.user.UserInfo"/>
UserInfo会生成到com.my.app.model.user下。
这是因为%MAVEN_HOME%/conf/settings.xml 中localRepository属性默认为~/.m2/repository
~即当前用户在系统中的用户目录,比如WINDOWS在c:/Documents and Settings/username
因为路径中包含空格,所以Candy找不到,解决方法就是在命令行操作
start C:/Progra~1/Java/jdk1.6.0/bin/native2ascii -encoding UTF-8 d:/workspace/dayawa/src/ApplicationResources_zh.properties d:/workspace/dayawa/src/ApplicationResources_zh_CN.properties
echo done!
return dao.saveUser(user);
} catch (DataIntegrityViolationException e) {
throw new UserExistsException(e.getCause().getCause().toString());
} catch (EntityExistsException e) { // needed for JPA
throw new UserExistsException(e.getCause().getCause().getMessage());
}
this.addActionMessage(getText("signup.welcome"));
return INPUT;
}
user.setEnabled(true);
//user.setRegistTime(new Date());
// Set the default user role on this new user
user.addRole(roleManager.getRole(Constants.USER_ROLE));
try {
userManager.saveUser(user);
} catch (AccessDeniedException ade) {
// thrown by UserSecurityAdvice configured in aop:advisor userManagerSecurity
log.warn(ade.getMessage());
getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
ade.printStackTrace();
return null;
} catch (UserExistsException e) {
log.warn("message "+e.getMessage());
List<String> args = new ArrayList<String>();
if(e.getMessage().indexOf("'"+user.getUsername()+"'")!=-1){
args.add(user.getUsername());
addActionError(getText("errors.existing.username", args));
}else{
args.add(user.getEmail());
addActionError(getText("errors.existing.email", args));
}
// redisplay the unencrypted passwords
user.setPassword(user.getConfirmPassword());
//to fix the bug that is when username exists and changed newusername throw Incorrect result size: expected 1, actual 0 Exception
user.setVersion(null);
//e.printStackTrace();
return INPUT;
}
getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
auth.setDetails(user);
SecurityContextHolder.getContext().setAuthentication(auth);
mailMessage.setSubject(getText("signup.email.subject"));
try {
sendUserMessage(user, getText("signup.email.message"), RequestUtil.getAppURL(getRequest()));
} catch (MailException me) {
addActionError(me.getCause().getLocalizedMessage());
me.printStackTrace();
}
return SUCCESS;
1021



被折叠的 条评论
为什么被折叠?



