0

I am trying to get 51Degrees.mobi to work with my Maven, JSF and Java project however I am having no luck so far. I have downloaded the 2 jars from http://51degrees.mobi/Support/Documentation/Java.aspx and followed the instructions. I now have a filter which looks like this

    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();
   }   

Thats throws no errors. From looking online I have found the dependancy I must add to the pom file and I have it as such

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

Again no errors are thrown in the file itself, however when I use mvn clean install in the directory I get the following error

     [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

Anyone have any ideas?

Chaney
  • 455
  • 1
  • 7
  • 20

3 Answers3

2

As per the rules, I state that I work for 51Degrees.mobi as a Java developer. I am not sure from looking at the page at this time if you solved your problem? So I thought I would add some more information.

Firstly, If you have two Jar files then you are using 2.1.16.1 not 2.1.15.1, although this should not directly effect your problem I thought I would say for clarity :).

Also, 51Degrees.mobi's version 2.1.16.1 solution was recently made available via the maven central repository, after the current answers were posted. So now all you should have to do is add this dependency to your 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 -->

If you wished to use our second jar just replace "core" with "webapp".

Community
  • 1
  • 1
Chris B
  • 925
  • 4
  • 14
  • Hi Chris, thanks for the reply, unfortunately I have been pulled from that project and put into a different project, currently the project that this question was made for is being put on hold until the bureaucracy can sort it all out :). Thanks for the reply however and I shall try it as soon as the project is renewed! – Chaney Nov 30 '12 at 16:36
1

Make sure you have 51Degrees.mobi in your repository (local or remote). I did a quick search in maven public repository and i cannot find it.

If the jar is in your local folder some where. You can use

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]

check the link maven install plugin

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
  • I checked and it is not there, also as you said it is not in the repository, do you know of another way to get this working with Maven? – Chaney Nov 14 '12 at 13:21
  • Thanks for the Updated Anser Sajan, I done as you said and got the following success message Installing c:\51Degrees\dist\51Degrees.mobi.detection.core to C:\Users\Paul\.m2\repository\com\mblas\redirectionportal\1.1.0\redirectionportal-1.1.0.jar however I still get the same error as detailed in original question. – Chaney Nov 14 '12 at 14:23
  • 1
    why your groupId, artifactId, and version are different than mentioned in your pom file.? Update your pom accordingly – Sajan Chandran Nov 14 '12 at 14:34
  • Hi, Sorry to seem like an idiot but I thought the groupId,artifactID and version where supposed to be off the pom file I am installing to and not the dependancy? So I have a jar file in a folder do I not run the following mvn install:install-file -Dfile=c:\51Degrees\dist\51Degrees.mobi.detection.core -DgroupId=com.openet.mblas -DartifactId=redirectionportal -Dversion=1.1.0 -Dpackaging=war -DcreateChecksum=true – Chaney Nov 14 '12 at 14:46
  • The details were taken from the top of the pom file, 4.0.0 com.openet.mblas redirectionportal Redirection Portal 1.1.0 war Sorry if this is obvious, I am new to this kind of thing. – Chaney Nov 14 '12 at 14:47
  • 1
    Do like mvn install:install-file -Dfile=c:\51Degrees\dist\51Degrees.mobi.detection.core -DgroupId=mobi.51degrees -DartifactId=detection -Dversion=2.1.15.1 – Sajan Chandran Nov 14 '12 at 14:58
  • Thanks Sajan, I have done that and gotten the following success message Installing c:\51Degrees\dist\51Degrees.mobi.detection.core to C:\Users\Paul\.m2\repository\mobi\51degrees\detection\2.1.15.1\detection-2.1.15.1.jar yet I still have the same problem. – Chaney Nov 14 '12 at 15:04
  • @Chaney If you successfully installed the jar file I doubt that you'll get the same error as before. – maba Nov 15 '12 at 08:51
1

Try to find the jar in your repository: The jar should reside here:

~/.m2/repository/mobi/51degrees/detection/2.1.15.1/

If you find it there, check whether it contains the classes under package

fiftyone.mobile.detection

-- Update --

In case you don't find this jar, you can use one of the following options:

  1. Use ''system'' scope dependency - it makes your build platform/environment dependent so I don't recommend it, although its the easiest way.

  2. Use mvn install:install-file so that it will place your jar into your local maven repository. Its much better than the first method, but you still will need to use this command before running maven in each local environment / your local repository gets purged...

  3. Maintain your own maven repository somewhere on server, map the maven to use this repository. This is by far the best approach I'm aware of. The best will be to work with repository proxies like 'Nexus' or 'Artifactory'. In the worst case you can create a repository as a plain file system and make it accessible through web server (like apache). In this repository you'll be able to store thirdparty jars that don't exist in the public maven repository, your own artifacts, or maybe artifacts which are not free/opensource and therefor can't be maintained in the public maven repo (like commercial software that you can use).

Hope this helps

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • I checked and it is not there, it is also not in the Maven public repository, is there a way to get it working in Maven regardless of the fact? – Chaney Nov 14 '12 at 13:22
  • 1
    yes, There are a couple of ways to do so. I'll update my answer – Mark Bramnik Nov 14 '12 at 13:39
  • Hi Mark, thanks for the updated answer, I went with number 2 and successfully installed it to as follows. Installing c:\51Degrees\dist\51Degrees.mobi.detection.core to C:\Users\Paul\.m2\repository\com\openet\mblas\redirectionportal\1.1.0\redirectionportal-1.1.0.jar however I am still getting the same error as I was in the original post. – Chaney Nov 14 '12 at 14:31