java.lang.NoClassDefFoundError: javax/microedition/io/Connector

mstocummstocum Junior MemberPosts: 119
Okay, I'm sure I'm doing something silly here. I'm trying to do some simple HTTP GET requests using docs from http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/io/HttpConnection.html as an example. Everything compiles cleanly, but when I actually go to try to grab a URL, I'm getting java.lang.NoClassDefFoundError: javax/microedition/io/Connector on the console. I'm guessing I need do something special to make the javax.microedition classes visible to the module, but I have zero clue what that is. Anyone out there able to provide any insights?

Thanks.

Comments

  • GregGGregG Just some guy... Posts: 249
    The subset of framework supported by duet doesn't include the useful javax classes, so I used the java.io.... stuff with file/io streams to implement html gets and puts.
  • mstocummstocum Junior Member Posts: 119
    GregG wrote: »
    The subset of framework supported by duet doesn't include the useful javax classes, so I used the java.io.... stuff with file/io streams to implement html gets and puts.

    Is AMX really selling a development platform in 2014 which doesn't have native support for HTTP?
  • GregGGregG Just some guy... Posts: 249
    I actually thought it was a serious oversight back when duet was initially released.

    Check this post ( http://www.amxforums.com/showthread.php?7060-AMXTools&p=53652#post53652 ) for some AMX code that does most of the easy stuff already.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    Its in there...


    But in my experience that doesn't mean you can actually get it to work..
  • GregGGregG Just some guy... Posts: 249
    Is that new with the 4.x firmware? I never noticed it on 3.x.

    (Which tells you how long ago I gave up on duet)
  • mstocummstocum Junior Member Posts: 119
    Oh, it's in there alright, which is why the code is compiling, but it's not on the freaking controller. It's bad enough that AMX doesn't have any HTTP calls in NetLinx, but to not have any on the Java side either?

    I guess what I really want to know is if there is any way to do actual HTTP calls in AMX.

    ETA I am using 4.x firmware.
  • GregGGregG Just some guy... Posts: 249
    I rolled my own module (originally in netlinx, and then later in java) which handles http for me. The netlinx one is more reliable from firmware to firmware, but the java one is faster.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    Nope, that is 3.x. In 4.x, java is packaged in CEEJ2.jar, if you go through the hassle of manually setting up a project to use the new jars, it is not pretty. The 4.x jars are also based on SE, not ME! I have had many issues trying to use classes from this package. AMX buys this JVM from another company, I have found many issues with base java classes not working as they should. I was trying to use a Threadpool and the ExecutorService Class implementation throws all kinds of Exceptions when you try to use it. The code runs perfect in Java 1.7.
  • mstocummstocum Junior Member Posts: 119
    JasonS wrote: »
    Nope, that is 3.x. In 4.x, java is packaged in CEEJ2.jar, if you go through the hassle of manually setting up a project to use the new jars, it is not pretty. The 4.x jars are also based on SE, not ME! I have had many issues trying to use classes from this package. AMX buys this JVM from another company, I have found many issues with base java classes not working as they should. I was trying to use a Threadpool and the ExecutorService Class implementation throws all kinds of Exceptions when you try to use it. The code runs perfect in Java 1.7.

    I don't suppose you could point to any directions to walk a newb through setting up the project to use the new jars? I've also been poking at apache commons httpclient (the old 3.x branch, since the 4.x branch seems to require some stuff that Eclipse can't find), but no matter what I do, when I add the JAR, Eclipse won't include it in the bundle. I'm sure I'm doing something wrong there too.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    mstocum wrote: »
    Oh, it's in there alright, which is why the code is compiling, but it's not on the freaking controller. It's bad enough that AMX doesn't have any HTTP calls in NetLinx, but to not have any on the Java side either?

    I guess what I really want to know is if there is any way to do actual HTTP calls in AMX.

    ETA I am using 4.x firmware.

    To actually use the 4.x.x Java classes is a pain in the butt. You have to get the "Master-v4_x_x_jar_files.zip" from Hotfix firmware on ActiveEcho. Then you have to manually replace all the jar files in your Java build path and manually rebuild your Duet Manifest file (probably the hardest part of the process).

    You might want to try taking your Master back to 3.x firmware and see if it runs, because I don't think that package is available on the Master running 4.x because 4.x Java is based on Standard Edition, not Micro Edition.
  • GregGGregG Just some guy... Posts: 249
    The 2 key things I use are these imports (not all apply to the code farther down):
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.UnsupportedEncodingException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Properties;
    import java.util.StringTokenizer;
    

    and then inside my service routine I do something like this:
    try
      {
        FileToGet = new URL("http://example.com/file.txt");
        URLConnection urlC = FileToGet.openConnection();
        InputStream webInputStream = urlC.getInputStream();
        FileOutputStream fileOutputStream = new FileOutputStream("/user/file.txt");
        copy(webInputStream, fileOutputStream);
        webInputStream.close();
        fileOutputStream.close();
    }
    catch (MalformedURLException eURLProblem)
    {
        // TODO Malformed URL catch block
    }
    

    The copy() routine is my own, and basically just does a thread safe copy.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    Here is the contents of the Readme inside the Master 4.x.x zip file:
    Master v4.x.x Java JAR layout

    The new master 4.x.x Java firmware is a substantial departure from the previous master
    3.x.x architecture.

    New Java Virtual Machine
    ________________________

    The Java Virtual Machine (JVM) was migrated from a virtual machine based on the
    Sun/Oracle J2ME VM to a third-party VM provided by Skelmir. In addition to the
    Skelmir VM being a newer more efficient design, it provides a broader set of
    foundation Java classes. Where the the Sun VM was based around Java Micro
    Edition (J2ME) the Skelmir JVM is based around Java Standard Ediction (J2SE)
    which is a broader set of classes.

    On the master controller, the Skelmir VM contains the full JavaSE set of classes
    minus any user interface classes. (Ex. AWT) This is because the master has no direct
    user display so the UI classes were pared from the Skelmir implimentation to save
    space.

    The following is the list of standard packages provided under the Master v4.x.x VM.

    java.beans
    java.beans.beancontext
    java.io
    java.lang
    java.lang.annotation
    java.lang.ref
    java.lang.reflect
    java.math
    java.net
    java.nio
    java.nio.channels
    java.nio.channels.spi
    java.nio.charset
    java.nio.charset.spi
    java.security
    java.security.acl
    java.security.cert
    java.security.interfaces
    java.security.spec
    java.sql
    java.text
    java.text.resources
    java.util
    java.util.jar
    java.util.logging
    java.util.prefs
    java.util.regex
    java.util.zip
    javax.accessibility
    javax.net
    javax.security.auth
    javax.security.auth.callback
    javax.security.auth.login
    javax.security.auth.spi
    javax.security.auth.x500
    javax.security.cert
    javax.sql
    javax.transaction
    javax.transaction.xa
    javax.xml.parsers
    javax.xml.transform
    javax.xml.transform.dom
    javax.xml.transform.sax
    javax.xml.transform.stream



    OSGi framework moved from Oscar to Knopflerfish 2.4.0
    _____________________________________________________

    The OSGi framework was transitioned from Oscar to Knopflerfish 2.4.0.
    With the transition to the new framework various packages have moved between
    .jar files. While all of the 3.x.x packages exist, they may now reside
    in a different .jar based on Knopflerfish's layout. The following is
    a basic mapping of old .jars to new:

    3.x.x .jar 4.x.x .jar(s)
    __________ _____________

    j2me1_1.jar CEEJ2.jar Core Java classes

    oscar.jar framework.jar OSGi framework classes
    cm/cm_api-2.0.1.jar
    device/device_api-2.0.0.jar
    javaxServlet/javaxServlet.jar
    kxml/kxml-1.0.jar
    log/log_api-2.0.2.jar
    ftpClient/ftpClient.jar

    http.jar httpServer/http_all-2.1.1.jar HTTP server (switched from Jetty to Knopflerfish)

    core.jar core.jar Master foundation firmware classes
    amx_util.jar

    morpheus.jar master/morpheus.jar Master Duet firmware classes
    log/amx_log.jar



    Building Duet Java project against the new 4.x.x .jar files
    ___________________________________________________________

    A Duet module build against the old 3.x.x .jar files will continue to execute on a 4.x.x master.
    A developer only needs to switch to the new 4.x.x .jar files if they need to take advantage of
    new functionality. For example, a Java class that was not available in J2ME but is available in
    J2SE.

    Building a Java Eclipse project to utilize these new .jar files should be as simple as modifying the
    project's "Reference Libraries" to point to the newly supplied .jar files rather than the old versions.

    The Duet module framework does not utilize any new implimentations from the highter firmware layers.
    Meaning Duet modules can continue to be compiled against the existing oscar, http, core and morpheus
    .jar files.

    This only leaves changing from j2me1_1.jar to CEEJ2.jar to gain access to the newly available
    Java Standard Edition classes.

    Be aware, a Duet module written to utilize new classes available in 4.x.x will NOT run successfully
    on older 3.x.x master firmware due to failed class resolution.

    After you create a new project, right click on the project in the Package Explorer, select Properties from the menu, then Java Build Path in the dialog, and then the Libraries Tab. Remove the jars in the 3.x.x column and add the ones in the 4.x.x column. Then you have to manually edit your "manifest.duetmf" file with at least the following sections. More import packages and file dependencies maybe required depending on the packages you are using.

    Import-Package:
    Import-Package: 
     com.amx.duet.driver; specification-version=1.0.1,
     com.amx.duet.da; specification-version=1.0.1,
     com.amx.duet.core.osgi; specification-version=1.0.1,
     com.amx.duet.devicesdk; specification-version=1.8.0,
     com.amx.duet.devicesdk.base; specification-version=1.8.0,
     com.amx.duet.devicesdk.component; specification-version=1.8.0,
     com.amx.duet.devicesdk.type; specification-version=1.8.0,
     com.amx.duet.util.metadata; specification-version=1.0.1,
     com.amx.duet.util; specification-version=1.0.1,
     org.osgi.framework; specification-version=1.3,
     org.knopflerfish.service.log,
     org.osgi.service.packageadmin; specification-version=1.2,
     org.osgi.service.condpermadmin; specification-version=1.0,
     org.osgi.util.tracker; specification-version=1.3.1,
     org.osgi.service.permissionadmin; specification-version=1.2,
     org.osgi.service.startlevel; specification-version=1.0,
     org.osgi.service.cm; specification-version=1.2.0,
     org.osgi.service.device; specification-version=1.1.0,
     org.jvftp.util,
     org.osgi.service.http; specification-version=1.2.0,
     org.xmlpull.v1,
     org.kxml2.wap.syncml,
     org.kxml2.wap,
     org.kxml2.io,
     org.kxml2.kdom,
     com.amx.log
    

    File-Dependencies:
    File-Dependencies: 
     devicesdkrt.jar; specification-version=1.15.0,
     snapirouter.jar; specification-version=1.15.0
    
  • mstocummstocum Junior Member Posts: 119
    JasonS,

    I need to request that zip file from AMX Tech Support though, correct?

    Thanks everyone for all of your help.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 226
    mstocum wrote: »
    I don't suppose you could point to any directions to walk a newb through setting up the project to use the new jars? I've also been poking at apache commons httpclient (the old 3.x branch, since the 4.x branch seems to require some stuff that Eclipse can't find), but no matter what I do, when I add the JAR, Eclipse won't include it in the bundle. I'm sure I'm doing something wrong there too.

    I have had a lot of trouble getting jars into Duet module jars, I always have to play with it to get it to work. I have never found a good way to do it. You might try adding it as a File Dependency in the duet Manifest File, but that won't make it part of the Duet Jar, when you go to load the System from Netlinx Studio it will ask you for the location of that Jar file.
  • mstocummstocum Junior Member Posts: 119
    GregG,

    Thanks, I was able to get something working based off of your code. I should at least be able to do what I need to do with that.

    Now to figure out how to include a 3rd party JAR in my project and have it actually work...
  • PhreaKPhreaK Senior Member Posts: 966
    [thread=8076]Here you go[/thread].

    Also, if you're wanting a simple way to do HTTP with current firmware have a look inside the RMS SDK, you'll find a nicely packed up Apache commons HTTP library and its associated dependancies.
  • mstocummstocum Junior Member Posts: 119
    PhreaK wrote: »
    [thread=8076]Here you go[/thread].

    Also, if you're wanting a simple way to do HTTP with current firmware have a look inside the RMS SDK, you'll find a nicely packed up Apache commons HTTP library and its associated dependancies.

    Well that's a clever idea...
  • mstocummstocum Junior Member Posts: 119
    Okay, what am I doing wrong here...
    Line    219 (21:20:37.109)::  Loading 1 Duet Modules.
    Line    220 (21:20:40.026)::  Device Access: DA.processNewDevice: {Device-Revision=1.0.0, Device-Category=other, Device-Make=LeBow, Physical-Device=0:0:0, objectClass=[Ljava.lang.String;@27620b, Device-SDKClass=com.amx.duet.devicesdk.Utility, Bundle-Version=1.0.0, Device-Model=HTTPTest
    Line    221 (21:20:40.026)::  , Duet-Device=41000:1:0, service.id=10, Duet-Module=HTTPTest_dr1_0_0}
    Line    222 (21:20:40.073)::  Device Access: loadDrivers: searching for 1 drivers
    Line    223 (21:20:40.073)::  Device Access: isDriverActive: checking for active driver - /bundle/HTTPTest_dr1_0_0
    Line    224 (21:20:40.073)::  Device Access: isDriverActive: driver not active - /bundle/HTTPTest_dr1_0_0
    Line    225 (21:20:40.307)::  DA: installing dependency: file:doc:/bundle/commons-logging-1.1.1-AMX-01.jar
    Line    226 (21:20:43.006)::  doc:/bundle/commons-logging-1.1.1-AMX-01.jar: dependency bundle matches flash file manifest
    Line    227 (21:20:43.006)::  DA: installing dependency: file:doc:/bundle/commons-lang-2.5-AMX-01.jar
    Line    228 (21:20:46.485)::  doc:/bundle/commons-lang-2.5-AMX-01.jar: dependency bundle matches flash file manifest
    Line    229 (21:20:46.485)::  DA: installing dependency: file:doc:/bundle/commons-codec-1.4-AMX-01.jar
    Line    230 (21:20:49.309)::  doc:/bundle/commons-codec-1.4-AMX-01.jar: dependency bundle matches flash file manifest
    Line    231 (21:20:49.309)::  DA: installing dependency: file:doc:/bundle/commons-httpclient-3.1-AMX-01.jar
    Line    232 (21:20:50.557)::  Memory Available = 10037384 <12336>
    Line    233 (21:20:52.803)::  doc:/bundle/commons-httpclient-3.1-AMX-01.jar: dependency bundle matches flash file manifest
    Line    234 (21:20:55.346)::  Device Access: DeviceAccess.loadDrivers - installing bundle for /bundle/HTTPTest_dr1_0_0
    Line    235 (21:20:58.466)::  /bundle/HTTPTest_dr1_0_0: bundle matches flash file manifest
    Line    236 (21:20:58.466)::  Device Access: DeviceAccess.loadDrivers - starting bundle for /bundle/HTTPTest_dr1_0_0
    Line    237 (21:21:01.025)::  Device Access: DA.processNewDevice: {Device-Revision=1.0.0, Device-Category=other, Device-Make=LeBow, Duet-Model=HTTPTest, Physical-Device=0:0:0, Device-Service=com.amx.duet.routers.snapi.ISNAPIRouter, Device-SDKClass=com.amx.duet.devicesdk.Utility, object
    Line    238 (21:21:01.025)::  Class=[Ljava.lang.String;@2925c0, Duet-Make=LeBow, Device-Channels=255, Bundle-Version=1.0.0, Device-Model=HTTPTest, Device-Levels=8, Duet-Revision=1.0.0, Duet-Device=41000:1:0, service.id=12}
    Line    239 (21:21:01.025)::  Device Access: loadDrivers: searching for 1 drivers
    Line    240 (21:21:01.025)::  Device Access: isDriverActive: checking for active driver - /lib/jars/duet/snapirouter
    Line    241 (21:21:01.040)::  Device Access: isDriverActive: driver not active - /lib/jars/duet/snapirouter
    Line    242 (21:21:01.134)::  Device Access: DeviceAccess.loadDrivers - installing bundle for /lib/jars/duet/snapirouter
    Line    243 (21:21:01.274)::  /lib/jars/duet/snapirouter: bundle matches flash file manifest
    Line    244 (21:21:01.274)::  Device Access: DeviceAccess.loadDrivers - starting bundle for /lib/jars/duet/snapirouter
    Line    245 (21:21:02.007)::  SNAPIRouter: UtilityComponent loaded
    Line    246 (21:21:02.117)::  SNAPIRouter: ModuleComponent loaded
    Line    247 (21:21:02.366)::  CIpEvent::OnLine 41000:1:1
    Line    248 (21:21:46.890)::  ICSPTCPRx0: Duplicate messageID received Sys=1 Dev=32001 MsgID=286E
    Line    249 (21:21:54.237)::  REINIT Called
    Line    250 (21:21:54.237)::  java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpClient
    Line    251 (21:21:54.237)::  $09at com.lebow.httptest.dr1_0_0.LebowHttptest.getViaCommons (LebowHttptest.java:95)
    Line    252 (21:21:54.237)::  $09at com.lebow.httptest.dr1_0_0.LebowHttptest.reinitialize (LebowHttptest.java:70)
    Line    253 (21:21:54.237)::  $09at com.amx.duet.routers.snapi.component.ModuleComponent.OnHandleDataEvent (Unknown Source, bco=568)
    Line    254 (21:21:54.237)::  $09at com.amx.duet.routers.snapi.SNAPIRouter.OnHandleDataEvent (Unknown Source, bco=22)
    Line    255 (21:21:54.237)::  $09at com.amx.duet.routers.snapi.SNAPIRouter.handleDataEvent (Unknown Source, bco=7)
    Line    256 (21:21:54.237)::  $09at com.amx.duet.core.master.IcspNetLinxDevice.handleDataEvent (Unknown Source, bco=40)
    Line    257 (21:21:54.237)::  $09at com.amx.duet.core.master.EventRouter.processEvent (Unknown Source, bco=772)
    Line    258 (21:21:54.237)::  $09at com.amx.duet.core.master.EventRouter.run (Unknown Source, bco=1406)
    Line    259 (21:21:54.237)::  $09at java.lang.Thread.run (Unknown Source, bco=16)
    

    I can get it to work by adding all of the org.apache.commons packages to the Import Packages section of the manifest.duetmf, but looking in the RmsNetLinx adapter JAR, it's not doing that. It mentions several org.apache.commons.lang packages, but nothing about httpclient. Is there an easier way to do this other than the boil the ocean approach I'm taking?
  • PhreaKPhreaK Senior Member Posts: 966
    If you have a look at the manifest for rmsclient.jar you will see them mentioned there. RmsNetLinxAdapter references rmsclient which in turn references these. You could use require-bundle, however generally considered 'nicer' to import specific packages.

    Boil away.
  • AMXJeffAMXJeff Senior Member Posts: 450
    mstocum wrote: »
    Is AMX really selling a development platform in 2014 which doesn't have native support for HTTP?

    You can use HTTPUrlConnection for this, this comes with duet.

    However I have moved to using apache http core library... More stable!

    http://hc.apache.org/httpcomponents-core-ga/
  • mstocummstocum Junior Member Posts: 119
    AMXJeff wrote: »
    You can use HTTPUrlConnection for this, this comes with duet.

    However I have moved to using apache http core library... More stable!

    http://hc.apache.org/httpcomponents-core-ga/

    Does version 4.x work on Duet? I've been able to get the 3.1 version packaged with RMS to work.
  • AMXJeffAMXJeff Senior Member Posts: 450
    mstocum wrote: »
    Does version 4.x work on Duet? I've been able to get the 3.1 version packaged with RMS to work.

    Yes, I am currently using 4.3. Only the "core" library works though on jdk1.4.
  • mstocummstocum Junior Member Posts: 119
    PhreaK wrote: »
    [thread=8076]Here you go[/thread].

    Also, if you're wanting a simple way to do HTTP with current firmware have a look inside the RMS SDK, you'll find a nicely packed up Apache commons HTTP library and its associated dependancies.

    Question the 999th. What is the proper way to create a JAR of your own code? I tried following your advice in the linked thread, but it's not generating the Export-Package: line, and I don't quite want to try generating it by hand. I think the lack of that line is keeping the Duet Manifest editor from seeing the contents of the JAR in the import packages section.
  • AMXJeffAMXJeff Senior Member Posts: 450
    I import the jar into my duet project, and make sure to choose the package directory when packing... Done!
Sign In or Register to comment.