我正在努力让51Degrees.mobi与我的Maven,JSF和Java项目合作,但到目前为止我没有运气。我已从http://51degrees.mobi/Support/Documentation/Java.aspx下载了2个罐子并按照说明操作。我现在有一个看起来像这样的过滤器
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
有人有什么想法吗?
答案 0 :(得分:2)
根据rules,我声明我作为Java开发人员为51Degrees.mobi工作。如果您解决了问题,我不确定此时此页面是否正常?所以我想我会添加更多信息。
首先,如果您有两个Jar文件,那么您使用的是2.1.16.1而不是2.1.15.1,虽然这不应该直接影响您的问题,我想我会说清楚:)。
此外,51Degrees.mobi的2.1.16.1版解决方案最近在发布当前答案后通过maven中央存储库提供。所以现在你应该做的就是将这个依赖项添加到你的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”即可。
答案 1 :(得分:1)
确保您的存储库(本地或远程)中有51Degrees.mobi
。我在maven公共存储库中进行了快速搜索,但我找不到它。
如果jar在你的本地文件夹中某处。你可以使用
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]
答案 2 :(得分:1)
尝试在存储库中找到jar: jar应该驻留在这里:
~/.m2/repository/mobi/51degrees/detection/2.1.15.1/
如果你在那里找到它,检查它是否包含包
下的类 fiftyone.mobile.detection
- 更新 -
如果您没有找到此jar,可以使用以下选项之一:
使用''系统''范围依赖 - 它使您的构建平台/环境依赖,所以我不推荐它,尽管它是最简单的方法。
使用mvn install:install-file
以便将jar放入本地maven存储库。它比第一种方法好得多,但是在每个本地环境中运行maven之前你仍然需要使用这个命令/你的本地存储库被清除......
在服务器上的某处维护您自己的maven存储库,映射maven以使用此存储库。这是迄今为止我所知道的最佳方法。最好的方法是使用“Nexus”或“Artifactory”等存储库代理。在最坏的情况下,您可以将存储库创建为纯文件系统,并通过Web服务器(如apache)访问它。 在此存储库中,您将能够存储公共maven存储库中不存在的第三方jar,您自己的工件,或者可能不是免费/开源的工件,因此无法在公共maven存储库中维护(如此您可以使用的商业软件。
希望这有帮助