2015-05-26 48 views
0

我是JSF的新手,我一直在尋找一些教程和文章(很難找到好的/新的材料),但我仍然沒有得到如何將一個「.jar」文件導入到我的JSF 2.2項目中。使用導入到JSF 2.2的「.jar」文件項目

我有這個使用「.so」(共享對象)文件的「.jar」文件。所以我將它們複製並粘貼到WEB-INF/lib文件夾中(如某些教程所示)。然後我右鍵單擊我的項目並選擇:屬性> Java構建路徑>添加外部罐並指向上面提到的「.jar」。

後,我建立了我的豆和描述了我的觀點:

豆:

package somepackage; 
import javax.faces.bean.*; 
import uk.ac.ox.cs.fdr.*; // This is the jar file I want to use 

@ManagedBean 
public class SomeBean { 

    private String text = ""; 

    public String getText(){ 
     return(text); 
    } 

    public void setText(String ntext){ 
     this.text = ntext; 
    } 

    public void foo(){ 
     String aux = ""; 

     try { 
      Session session = new Session(); //this class is defined inside the .jar file 
      session.loadFile("intro.csp"); 
      // 
      for (Assertion assertion : session.assertions()) { 
       assertion.execute(null);//Assertion is also a class from this jar 
       aux.concat(assertion.toString()+" "+ 
        (assertion.passed() ? "Passed" : "Failed")); // here I concatenate the string to my auxiliary string 
      } 
     } 
     catch (InputFileError error) { 
      setText(error.toString()); 
     } 
     catch (FileLoadError error) { 
      setText(error.toString()); 
     } 
     this.setText(aux); 
     fdr.libraryExit(); 
    } 

}

而我的觀點:

<h:form> 
    <textarea>#{someBean.text}</textarea> 
    <h:commandButton value="Press Me" action="#{someBean.foo}"/> 
</h:form> 

當我跑我的服務器(我用ecplise使用Tomcat 8),一切正常開始(我得到2個警告,但我在其他帖子中看到了在我可以無視當時)他們是:

Classpath entry /home/rrs/workspace/myProjct/WebContent/WEB-INF/lib/fdr.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.  myProjct  P/myProjct Classpath Dependency Validator Message 

Description Resource Path Location Type Method must have signature "String method(), String method()... 

所以我去http://localhost:8080/myProjct/index.jsf,並嘗試使用我的按鈕(這個想法是,當我按下它,FOO()函數將被調用,textarea將顯示一些文本)。但它看起來像從「try {}」到「fdr.libraryExit」代碼沒有執行(控制檯不顯示任何錯誤,但textarea沒有更新)。我不知道爲什麼會發生這種情況。 PS:我在項目中粘貼了「intro.csp」(右鍵單擊項目並選擇粘貼)。

+0

撤消您在* Build Path *中所做的所有操作。只要在'/ WEB-INF/lib'中放入JAR就足夠了。 – BalusC

+0

嘿,BalusC,我做了你提到的,我實際上工作正常,但我發現我的程序不工作,因爲它無法找到文件「intro.csp」上線「session.loadFile(」intro.csp 「)」;我應該放一個特別的地方嗎?我直接複製粘貼它的項目,也試過粘貼它在WEB-INF/lib裏面,但每次得到: <未知位置>:無法打開文件'intro.csp' – Rafael

回答

0

我想你可能會缺少部署組件部分。您需要檢查項目屬性 - >部署程序集以將該jar放入服務器的WEB-INF/lib文件夾中。

+0

嘿,費爾南多,怎麼辦我做這個部署彙編部分? – Rafael

+0

嗨拉斐爾,你必須做到以下幾點1.-右鍵點擊你的項目。 - >屬性 - >部署彙編2.-將你的Web-inf/lib文件夾添加到源列,並且你必須把它放到WEB-INF/lib/deploy路徑列中。 構建和重新啓動服務器 –

+0

我認爲這個鏈接可能會幫助你[部署程序集](http://www.mastertheboss.com/eclipse/jboss-eclipse/eclipse-web-lib-configuration) –

相關問題