Clone GitHub项目
git clone https://github.com/LeeKemp/UserAgentParser
将项目打成jar包,安装到maven仓库中
D:Github ProjectUserAgentParser>mvn clean package -DSkipTests
[INFO] Building jar: D:Github ProjectUserAgentParser argetUserAgentParser-0.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.845 s
[INFO] Finished at: 2019-04-09T14:57:39+08:00
[INFO] Final Memory: 19M/210M
[INFO] ------------------------------------------------------------------------
D:Github ProjectUserAgentParser>mvn clean install -DSkipTests
[INFO] Installing D:Github ProjectUserAgentParser argetUserAgentParser-0.0.1.jar to C:Usersghc.m2
epositorycomkumkeeUserAgentParser .0.1UserAgentParser-0.0.1.jar
[INFO] Installing D:Github ProjectUserAgentParserpom.xml to C:Usersghc.m2
epositorycomkumkeeUserAgentParser .0.1UserAgentParser-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.027 s
[INFO] Finished at: 2019-04-09T14:58:51+08:00
[INFO] Final Memory: 19M/217M
[INFO] ------------------------------------------------------------------------
在项目pom.xml中加入maven依赖
<dependency>
<groupId>com.kumkee</groupId>
<artifactId>UserAgentParser</artifactId>
<version>0.0.1</version>
</dependency>
编写junit测试类
public class UserAgentTest {
@Test
public void test(){
String source = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36";
UserAgentParser userAgentParser = new UserAgentParser();
UserAgent agent = userAgentParser.parse(source);
String browser = agent.getBrowser();
String engine = agent.getEngine();
String engineVersion = agent.getEngineVersion();
String os = agent.getOs();
String platform = agent.getPlatform();
System.out.println(browser + " , "+ engine + " , "+ engineVersion + " , "+ os + " , "+ platform);
}
}