New Developer Question

Discussion in 'Developers Corner' started by RobTucker11, May 27, 2006.

  1. RobTucker11

    RobTucker11 New Member

    4
    0
    May 27, 2006

    Advertisements

    How do you compile applications from the command line and run them from the command line? I haven't done java development in years, but this looks like a great opportunity to get back into it. I am using an intel based macbook pro. All of the information I have found is for using the Eclipse IDE. It will unfortunatly not run on my Mac. Can someone tell me how to do it from the command line? Thanks!
     
  2. F8ster

    F8ster The Very Last One

    232
    0
    May 26, 2002
    Hi Rob,

    Here are the commands to get the "HelloWorld" sample from the SDK samples working from the command line in Windows; adjusting for the Mac differences should be straightforward:

    Code:
    c:
    cd \tivo\hme_sdk_1.4
    javac -cp hme.jar -d . samples\src\com\tivo\hme\samples\hello\HelloWorld.java
    java -cp hme.jar;hme-host-sample.jar;. com.tivo.hme.host.sample.Main com.tivo.hme.samples.hello.HelloWorld
    Run these commands, then you can either run the simulator (I just double-click on simulator.jar) or go over to your TiVo. You should find the 'HelloWorld' application listed under 'Music, Photos, Products, & More'.

    I'm not much of a Mac guy, but Eclipse is supported on the Mac (perhaps there are extenuating circumstances on your machine):

    http://developer.apple.com/tools/usingeclipse.html

    You can also consider NetBeans:

    http://www.netbeans.org/kb/articles/mac.html

    They're both excellent, and well worth the investment of time to get them going. Anyway, hope the command-line stuff helps get you going. -- Dave
     
  3. RobTucker11

    RobTucker11 New Member

    4
    0
    May 27, 2006
    I've gotten that far.
    Lets say that I want to create a new source file. I will call it HMETest.java. How do i compile it and then get it to run? Do I have to add it to a jar file? If so which one? Or can I just run the .class file and then include the hme.jar file when running it? Also thats so much for your reply. I have tried Eclipse for the Mac but it doesn't run right on the new intel based ones. And I really don't care for netbeans. Miserably slow.
     
  4. F8ster

    F8ster The Very Last One

    232
    0
    May 26, 2002
    Previous versions of NetBeans were awful performance-wise, but 5.0 seems to be a lot better. I used it for the entire Stock Viewer app, just to get better acquainted with it.

    Anyway, back to your question. Your HMETest.java will need to, at a minimum, have the following contents. For now, just create the file in the root of wherever you unpacked the HME SDK. (hme.jar and hme-host-sample.jar should be in that directory.)

    Code:
    package rob;
    public class HMETest extends Application
    {
        public void init(IContext context) throws Exception
        {
            super.init(context);
            [COLOR=Purple]getRoot().setResource(createText("default-36-bold.font",
                                        Color.white, "Hello, world!"));[/COLOR]
        }
    }
    (You can replace the line in purple with your own code later.)

    I assume if you got through the first example, you already have the JDK installed, and your PATH is set up correctly. If that's the case, then you should be able to compile it:

    Code:
    javac -cp hme.jar  HMETest.java
    That should generate rob/HMETest.class. To run it, just run the following command. You don't have to add it to a JAR or anything first. The stuff in green specifies the classpath, so Java will search all of the listed JARS and directories for the classes it needs.

    Code:
    java [COLOR=DarkGreen]-cp hme.jar;hme-host-sample.jar;. [/COLOR] com.tivo.hme.host.sample.Main rob.HMETest
    If you're successful, you should see text like this on the console:


    HME SDK 1.4 (TiVo, Inc.)
    LOG: added factory
    MDNS: http://192.168.1.110:1240/hello/


    That means the app is running. You can then go over to your TiVo and find it listed under 'Music, Photos, Products, & More.'
     
  5. lenat

    lenat New Member

    1
    0
    May 29, 2006

    Advertisements

    Rob,

    In Dave's example, notice "-d ." option for javac. -d option is name of the directory to output compiled classes (dot for current directory) . After you run javac, you should find com\tivo\hme\samples\hello\HelloWorld.class in your current directory.

    Including current directory (dot) in the classpath (see java -cp... line in Dave's example) makes java find your class. You don't have to add it to the jar...


    -elena
     
  6. RobTucker11

    RobTucker11 New Member

    4
    0
    May 27, 2006
    Thanks for all the help. I got it working, but without creating a package. For whatever reason when I would compile, and have it try to create a package called "rob" and add the HMETest class to it, it would not work. However if i omit the package declaration, it works just fine. Is there any advantage to creating a package? Here is what I am looking to develop.
    I created a custom monitoring and ticketing system (mainly in php) on a FreeBSD server. I want to develop a Tivo based application that will allow me to see the status of our network, and any trouble tickets that are open without needing to open my laptop. Yes it is the ultimate in laziness. So for creating something like this, is there any advantage in creating the package, or will my stand alone class be fine?
     
  7. RobTucker11

    RobTucker11 New Member

    4
    0
    May 27, 2006
    Do I need to do anything different work working with the bananas jar? Other than include the bananas.jar file in my classpath? I'm following the same instructions that worked before, however I'm getting: ListsScreen.java:11: package com.tivo.hme.bananas does not exist when i try to compile one of the samples. Any thoughts?
     
  8. F8ster

    F8ster The Very Last One

    232
    0
    May 26, 2002
    You'll want your application to extend BApplication, not Application. Yes, add bananas.jar to the classpath. For an extensive tutorial building a Bananas app, see http://bitrazor.com/content/tivo/hme/traffic_cam_tutorial/index.php . It uses Eclipse, but there are lots of code samples in there. I just updated it to HME 1.4 and Bananas 1.3 recently.
     

Share This Page

spam firewall

Advertisements