gpt4 book ai didi

java - 如何将 51Degrees.Mobi 与 Maven 一起使用

转载 作者:行者123 更新时间:2023-12-01 18:57:39 27 4
gpt4 key购买 nike

我正在尝试让 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 ,我声明我是 51Degrees.mobi 的一名 Java 开发人员。不知道此时查看页面是否解决了您的问题?所以我想我应该添加更多信息。

首先,如果您有两个 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”即可。

关于java - 如何将 51Degrees.Mobi 与 Maven 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379179/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com