我正在尝试让51Degrees.mobi与我的Maven,JSF和Java项目一起工作,但是到目前为止我还没有运气。我已经从http://51degrees.mobi/Support/Documentation/Java.aspx下载了2个jar,并按照说明进行了操作。我现在有一个看起来像这样的过滤器

    import fiftyone.mobile.detection.BaseDeviceInfo;
    import fiftyone.mobile.detection.Provider;
    import fiftyone.mobile.detection.binary.BinaryException;
    import fiftyone.mobile.detection.binary.Reader;

     public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String s = httpRequest.getHeader("user-agent");

    //Create a Provider object
      Provider p;
    try {
        p = Reader.create();


    } catch (BinaryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    //Provider p = Reader.create(PATH_TO_PREMIUM_DATA);


      //Read in a HttpServletRequest or User Agent String
      BaseDeviceInfo b = p.getDeviceInfo(s);

      //Get the value of a property
      String result = b.getFirstPropertyValue("IsMobile");

      //Check the property value
      if(result.equals("True")){
        System.out.println("This is mobile");
      }

      if(result.equals("False")){
        System.out.println("This is not mobile");
      }

      //Before exiting your application, ensure you dispose of the Provide to
      //release it's resources such as it's thread pool
       p.destroy();
   }


多数民众赞成在没有任何错误。通过在线查找,我发现必须添加到pom文件中的依存关系就这样了

     <dependency><!-- Start 51Degrees.mobi dependencies -->
        <groupId>mobi.51degrees</groupId>
        <artifactId>detection</artifactId>
        <version>2.1.15.1</version>
    </dependency><!-- End 51Degrees.mobi dependencies -->


同样,文件本身没有引发任何错误,但是当我在目录中使用mvn clean install时,出现以下错误

     [ERROR] COMPILATION ERROR :
     [INFO] -------------------------------------------------------------
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[18,32]          error: package fiftyone.mobile.detection does not exist

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[19,32] error: package fiftyone.mobile.detection does not exist

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[20,39] error: package fiftyone.mobile.detection.binary does not exist

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[21,39] error: package fiftyone.mobile.detection.binary does not exist

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[45,4] error: cannot find symbol

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[47,7] error: cannot find symbol

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[50,11] error: cannot find symbol

     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[60,4] error: cannot find symbol

     [INFO] 8 errors
     [INFO] -------------------------------------------------------------
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD FAILURE
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 3.730s
     [INFO] Finished at: Wed Nov 14 12:45:35 GMT 2012
     [INFO] Final Memory: 16M/39M
     [INFO] ------------------------------------------------------------------------
     [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.1:compile (default-         compile) on project redirectionportal: Compilation failure: Compilation failure:
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[18,32]          error: package fiftyone.mobile.detection does not exist
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[19,32] error: package fiftyone.mobile.detection does not exist
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[20,39] error: package fiftyone.mobile.detection.binary does not exist
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[21,39] error: package fiftyone.mobile.detection.binary does not exist
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[45,4] error: cannot find symbol
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[47,7] error: cannot find symbol
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[50,11] error: cannot find symbol
     [ERROR]
     [ERROR] \ea\portals\redirectionportal\src\main\java\com\filters\MyFilter.java:[60,4] error: cannot find symbol
     [ERROR] -> [Help 1]
     [ERROR]
     [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
     [ERROR] Re-run Maven using the -X switch to enable full debug logging.
     [ERROR]
     [ERROR] For more information about the errors and possible solutions, please read the following articles:
     [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException


谁有想法?

最佳答案

按照rules,我声明我以Java开发人员的身份为51Degrees.mobi工作。我目前无法通过查看页面来解决问题吗?所以我想我会补充一些信息。

首先,如果您有两个Jar文件,则您使用的是2.1.16.1而不是2.1.15.1,尽管这不会直接影响您的问题,我想我想说的很清楚:)。

同样,在发布了当前答案之后,最近通过Maven中央存储库提供了51Degrees.mobi的2.1.16.1版解决方案。因此,现在您要做的就是将此依赖项添加到pom中:

 <dependency><!-- Start 51Degrees.mobi dependencies -->
    <groupId>net.sourceforge.fiftyone-java</groupId>
    <artifactId>51Degrees.mobi.detection.core</artifactId>
    <version>2.1.16.1</version>
</dependency><!-- End 51Degrees.mobi dependencies -->


如果您想使用我们的第二个jar,只需将“ core”替换为“ webapp”。

09-30 11:40