使用“.jar”文件导入JSF 2.2项目

时间:2015-05-26 19:53:10

标签: java eclipse jsf

我是JSF的新手,我一直在研究一些教程和帖子(很难找到好的/新材料),但我仍然不知道如何将“.jar”文件导入我的JSF 2.2项目

我有这个“.jar”文件,它使用一些“.so”(共享对象)文件。所以我将它们复制并粘贴到WEB-INF / lib文件夹中(正如一些教程所建议的那样)。然后我右键单击我的项目并选择:属性> Java构建路径>添加外部罐子并指向我上面提到的“.jar”。

之后我按照描述创建了我的Bean和我的视图:

豆:

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”(右键单击项目并选择粘贴)。

1 个答案:

答案 0 :(得分:0)

我认为您可能缺少部署程序集部分。您需要检查项目属性 - &gt;部署程序集将jar放在服务器的WEB-INF / lib文件夹中。

相关问题