Archived

This forum has been archived. Please start a new discussion on GitHub.

Add methods to a Java sample ????

Hello,

sorry but I'm a absolut Java ICE beginner.
E.g. demoj\book\printer
The printer example:
How is it possible to add a method getDate()
like the existing printString("Hello World!") method to all files.

I'v added but I've got an error by compiling it with the existing ant script:
compile:
    [mkdir] Created dir: C:\Ice-2.1.2\demoj\book\printer\classes
    [javac] Compiling 11 source files to C:\Ice-2.1.2\demoj\book\printer\classes

    [javac] Compiling 14 source files to C:\Ice-2.1.2\demoj\book\printer\classes

    [javac] C:\Ice-2.1.2\demoj\book\printer\Client.java:28: cannot find symbol
    [javac] symbol  : method getDate(java.lang.String)
    [javac] location: interface Demo.PrinterPrx
    [javac]         printer.getDate("Test");
    [javac]                ^
    [javac] 1 error

BUILD FAILED
C:\Ice-2.1.2\demoj\book\printer\build.xml:47: Compile failed; see the compiler error output for details.

Please could somebody explain in short words what are the main things to look at.

Thank you very much !!!!
surfer

Comments

  • dwayne
    dwayne St. John's, Newfoundland
    Hi,

    You should only need to add the new method to the Printer interface slice definition in Printer.ice and the java implementation of the method in PrinterI.java.

    Regards,
    Dwayne
  • How can the client invoke the method?

    Hi and thanks but how invokes the client the method?

    That's my Client changes:
    printer.printString("Hello World!");
    printer.getDate("Test");
    


    that's my Printerl changes:
    public class PrinterI extends Demo._PrinterDisp {
        public void
        printString(String s, Ice.Current current)
        {
            System.out.println(s);
        }
        
        public void
        getDate(String st,Ice.Current current)
        {
    	System.out.println(st);
        }
        
    }
    


    that's my Printer.ice changes:
    interface Printer
        {
    	void printString(string s);
                 void getDate(string st);
        };
    

    What could be the mistake ??
    Thanks a lot.
    surfer
  • matthew
    matthew NL, Canada
    Was the slice file retranslated by slice2java? Try removing all the generated code and the .class files and re-run ant to see what is going on.

    Regards, Matthew
  • Hello,
    I remove the folders "generated" and "classes" all the time
    so that I've only the sample files without these folders.
    But I've had an folder called old_files, where my old class and java files are.
    That was the problem.

    Thank you very much
    surfer
  • In regards to Matthew's reply:

    Try removing all the generated code and the .class files and re-run ant to see what is going on.

    ___

    I am running into the same problem and have since removed all the generated .class files. After that, I recompiled my java code and tried to run the server/client, but I am still getting an error. What does it mean to "re-run ant"? Is that different than rebuilding the java code with "javac"? Thanks for your help.

    e
  • mes
    mes California
    Hi,

    Please update your signature as described by our revised forum support policy.

    Thanks,
    - Mark
  • mes
    mes California
    epallazz wrote:
    I am running into the same problem and have since removed all the generated .class files. After that, I recompiled my java code and tried to run the server/client, but I am still getting an error. What does it mean to "re-run ant"? Is that different than rebuilding the java code with "javac"?
    Matthew suggested that the user re-run ant because the user was modifying one of the demos included with the Ice for Java distribution, and we use ant as our build tool. It's essentially the same as running javac manually on the regenerated code.

    The most likely reason for a compile error after changing a Slice file is a CLASSPATH problem, specifically the compiler finds an obsolete definition of a class. If you've removed all of the generated files and compiled class files, recompiled your Slice files and double-checked your CLASSPATH, the next step would be to create a self-contained archive of your project and attach it so that we can take a look at it.

    Take care,
    - Mark
  • mes
    mes California
    In the Ice for Java demo directories, we place the generated files (i.e., the files created by slice2java) in the "generated" subdirectory. After you modify the Slice definitions, you must re-run slice2java and recompile the source files in the generated subdirectory.

    Hope that helps,
    - Mark