APPFUSE2使用說明及常見問題解決方案

來源:互聯網
上載者:User
APPFUSE2使用說明及常見問題解決方案配置好MAVEN_HOME,JAVA_HOME 這個就不廢話了:P------------------------------------------------------------------------------------------
步驟:(以下步均為在命令列的輸入)
------------------------------------------------------------------------------------------
第一步 通過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執行完畢後CD到yourproject目錄中 第二步:加入ECLIPSE工程檔案,方便匯入到ECLIPSE
mvn
eclipse:eclipse  第三步:修改yourproject/pom.xml 設定檔   1.修改產生代碼方式,找到
      <genericCore>${amp.genericCore}</genericCore>
      <fullSource>${amp.fullSource}</fullSource>
      修改成:
       <genericCore>false</genericCore>
      <fullSource>true</fullSource>
      注意,這裡必須吧pom.xml中的genericCore屬性設為false 否則只會產生Action   2.資料庫配置資訊(mysql在最底下)第四步:產生MODEL類
先執行,這樣會把預設需要的相關類先產生
mvn
appfuse:full-source然後執行
mvn
appfuse:gen-model 第五步:修改/src/main/resources/hibernate.cfg.xml添加需要產生dao,service,action,jsp的模組 第六步:產生Dao,Service,Action
mvn
appfuse:gen -Dentity=你的MODEL類
    這裡可能會有一個提示找不到/src/main/resources/database.properties,  可以不用理會
  如果設定了很複雜的關聯,這個產生過程會很痛苦,老是報targeting an unmapped的錯,
  我的解決方案是找到關聯的類比如USER,先把關係映射方法和屬性刪掉,
  然後在再把/src/main/resources/hibernate.cfg.xml其他的類聲明刪掉
  產生成功後再把這些加上去.第七步: 把產生的設定檔寫入到src目錄下的設定檔中
mvn
appfuse:install 最後執行 mvn
jetty:run-war 即可打包並運行項目打完收工 總結:DAO和service的設定檔會產生到:/src/main/webapp/applicationContext.xml中
      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 否則只會產生Action3.運行後出現gzip  該問題是壓縮HTML的包導致,暫時屏蔽掉相關filter 4.使用ehcache1.3以前的版本產生的程式碼介面字元會變成問號,這是因為maven無法下載正確的ehcache包造成,解決方案是修改/pom.xml ,在裡面加上: <dependency>
           <groupId>net.sf.ehcache</groupId>
           <artifactId>ehcache</artifactId>
           <version>${ehcache.version}</version>
       </dependency>
       <ehcache.version>1.4.1</ehcache.version>
後再產生代碼 5.當某張資料表被修改需要更新相應的model時,只需執行 mvn
appfuse:gen -Dentity=yourmodel
  當添加新的資料表時間,除了執行 mvn
appfuse:gen -Dentity=yourmodel外,還需要執行
  mvn
appfuse:install 來把DAO,STRUTS配置寫入到SRC下的相應檔案中. 6.如果希望產生的model類不在預設的model包根下,只需要在resources/hibernate.cfg.xml中修改想要產生的包路徑就行,比如:
預設情況下UserInfo會產生到com.my.app.model下,把配置改成
<mapping class="com.my.app.model.user.UserInfo"/>
UserInfo會產生到com.my.app.model.user下。 7.使用Candy for Appfuse 外掛程式時發現model都無法產生,
這是因為%MAVEN_HOME%/conf/settings.xml 中localRepository屬性預設為~/.m2/repository
~即目前使用者在系統中的使用者目錄,比如WINDOWS在c:/Documents and Settings/username
因為路徑中包含空格,所以Candy找不到,解決方案就是在命令列操作 8.關於亂碼的問題對於APPFUSE產生的工程運行時亂碼是很常見的現象,造成該現象的原因也有幾種:為了偷懶,這裡引用一篇網上的文章:http://www.blogjava.net/43880800/archive/2006/11/18/81892.html 對於國際化檔案*.properties檔案的編輯,有兩個ECLIPSE外掛程式可以推薦:Properties Editor 和 ResourceBundleEditor 再次偷懶引用一篇網文:http://blog.csdn.net/lmjq/archive/2007/06/21/1660137.aspx 不過我的IDE有點問題,這兩個都裝上卻不好使,不知道是怎麼回事。用了個笨方法:寫個批處理來做。內容如下:echo begin encoding
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! 儲存成 encodeProperties.bat 執行就行,當然,相關路徑要設定成你的實際路徑。   9. 執行“ mvn
jetty:run-war”時,會根據POJO先刪除資料庫裡的表再重建,如果不想對資料進行操作可以修改pom.xml,將<
configuration
>下的

drop熟悉修改為 false。不過執行“ mvn
jetty:run-war”仍然會執行建表操作,出現大量的錯誤記錄檔,不過沒有影響。   10. 執行“ mvn
jetty:run-war”時,會清空資料表的資料並插入預設的資料,預設的資料在%PROJECT_HOME%/src/main/ resources/default-data.xml配置,這個很討厭。修改pom.xml中的<
dbunit
.operation.type
>的配置為
NONE

可以屏蔽這部分操作。
   11.在註冊新使用者時,如果使用者名稱或郵件已經被註冊,返回表單改後提交報DataIntegrityViolationException, 這是appfuse的一個BUG,解決方案:          修改UserSecurityAdvice.before()        在最後的else裡加上:user.setVersion(null);     修改UserManagerImpl.saveUser():把最後的try改成:     try {
            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());
        }     然後在SignupAction.save()改成:
     if(user==null){
      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;
        }
        saveMessage(getText("user.registered"));
        getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);
        // log user in automatically
        UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
        auth.setDetails(user);
        SecurityContextHolder.getContext().setAuthentication(auth);
        // Send an account information e-mail
        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;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.