Archived

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

package com.zeroc.Ice not found Ice 3.7 Java Ubuntu 16.04

neros
edited December 2017 in Help Center

I have a problem in java files compilation on Ubuntu (slice2java from Slice definition was successfully generated)

The error is "package com.zeroc.Ice does not exist"

The compilation command line is " javac -d pathTo/classes -classpath /pathTo/classes:/pathTo/Ice.jar Serveur.java ClientServeurI.java Morceau.java /PathTo/generated/MP3/*.java "

All code source is in attachment

Comments

  • benoit
    benoit Rennes, France

    Hi,

    Where did you copy/get the Ice.jar file from? Are you sure it's the Ice jar file for the new Java mapping and not the old mapping (see https://doc.zeroc.com/display/Ice37/New+Features+in+Ice+3.7#NewFeaturesinIce3.7-NewJavaMapping)?

    You can check the content of the Ice.jar file with:

    jar tf <path>/Ice.jar
    

    If the classes don't start with the com/zeroc prefix, the Ice.jar file contains the Ice runtime for the old Java mapping.

    Cheers,
    Benoit.

  • The classes don't start with, could you tell me how can I do ?

  • neros
    edited December 2017

    Please, I'm a student and I must solve the problem

    jar tf Ice.jar > log.txt

    log.txt 43.4K
  • bernard
    bernard Jupiter, FL

    Hi Mauris,

    You just need to install and use the correct ice.jar file (with a lowercase i).

    One option is to use Maven Central, as described on https://doc.zeroc.com/display/Ice37/Building+Ice+Applications+in+Java.

    On Ubuntu 16.04, another option is to install the libzeroc-ice3.7-java package - see https://doc.zeroc.com/display/Ice37/Using+the+Linux+Binary+Distributions.

    Best regards,
    Bernard

  • Where can I find the right ice.jar ?

    I have already installed libzeroc-ice3.7-java

  • joegeorge
    joegeorge Jupiter, Florida

    The ice jar files are installed into /usr/share/java. For example, the Ice 3.7.0 jar file is /usr/share/java/ice-3.7.0.jar.

  • neros
    edited December 2017

    Compilation command line :

    javac -d /path/classes -classpath /path/classes:/usr/share/java/ice-3.7.0.jar Serveur.java ClientServeurI.java Morceau.java /path/generated/MP3/*.java

    Compilation result into log25.txt, jar tf /usr/share/java/ice-3.7.0.jar into log2.txt

    Please help I don't have much time

  • neros
    edited December 2017

    Compilation problem solved, I have a problem in trying of execute the Server (impossible of load the main class TP3.Serveur)

    Execution command line : java TP3/Serveur

    Source code attached

  • I have a problem when I execute Serveur

    java Serveur

    Exception in thread "main" java.lang.NoClassDefFoundError: com/zeroc/Ice/Object
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544 )
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: com.zeroc.Ice.Object
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

  • Please, I would like solve the problem.
    I need to have a good mark for this work to valid my semester
  • xdm
    xdm La Coruña, Spain

    you need to add /usr/share/java/ice-3.7.0.jar to the classpath when running the application try:

    java -cp classes:/usr/share/java/ice-3.7.0.jar Serveur
    
  • Result : impossible to find or load main class Serveur

  • xdm
    xdm La Coruña, Spain

    Right you need to include the package name of Serveur

    java -cp classes:/usr/share/java/ice-3.7.0.jar TP3.Serveur
    
  • Result : impossible to find or load main class TP3.Serveur

  • If this can help, the content of the folder in which I run the command :

    ClientServeurI.class Morceau.class MP3 Serveur.class TP3

  • xdm
    xdm La Coruña, Spain

    Hi Mauris,

    The source you upload has the following structure

    source
      classes
        TP3
           Serveur.class
    

    Try running this command from source directory

  • I don't find the "source" folder

  • The server is running, no error for the moment in execution.

    Thanks you

  • I'am newbie with Ice, all my pure Java cod works, but I don't have tested the Ice code part yet.
    If I understand it correctly, thanks to Ice work with Slice definition, the server method call mechanism is invisible ? For the client point of view, its like a simply local method call ?

  • I have a problem with my Python, client.

    Client in attachment

    A simply server connection test failed with this error :

    Traceback (most recent call last):
    File "client.py", line 6, in
    printer = MP3.ClientServeurPrx.checkedCast(base)
    File "/home/hector/Téléchargements/python/ClientServeur_ice.py", line 133, in checkedCast
    return _M_MP3.ClientServeurPrx.ice_checkedCast(proxy, '::MP3::ClientServeur', facetOrContext, context)
    Ice.ObjectNotExistException: exception ::Ice::ObjectNotExistException
    {
    id =
    {
    name = clientserveurAdapter
    category =
    }
    facet =
    operation = ice_isA
    }

  • xdm
    xdm La Coruña, Spain

    Seems you attach the wrong file

  • bernard
    bernard Jupiter, FL

    Hi Mauris,

    Did you try the Ice demos? They include a build system and instructions on how to run the client and server, so it should make everything easier for you.

    For this latest ObjectNotExistException error, ObjectNoExistException means the object adapter in your server could not find an object with the specified identity. The exception shows the object identity specified by your client is "clientserverAdapter". Check if this matches the identity for the target object in your server (the identity in your call to "add" on the object adapter).

    Best regards,
    Bernard

  • Python client :

    import sys, Ice
    import MP3

    with Ice.initialize(sys.argv) as communicator:
    base = communicator.stringToProxy("clientserveurAdapter:default -p 10000")
    printer = MP3.ClientServeurPrx.checkedCast(base)
    if not printer:
    raise RuntimeError("Invalid proxy")

    Java server :

    package TP3;

    public class Serveur {

       public static void main(String[] args) throws Exception
        {
            try(com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize(args))
            {
    
                com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("clientserveurAdapter", "default -p 10000");
                com.zeroc.Ice.Object object = new ClientServeurI();
                adapter.add(object, com.zeroc.Ice.Util.stringToIdentity("clientserveur"));
                adapter.activate();
                communicator.waitForShutdown();
            }
        }
    

    }

  • I can't find the problem, cloud you help ?
  • xdm
    xdm La Coruña, Spain

    You are using the wrong object identity in the client proxy

    base = communicator.stringToProxy("clientserveurAdapter:default -p 10000")
    

    Should be

    base = communicator.stringToProxy("clientserveur:default -p 10000")
    
  • I have a problem with my Python client

    def ajouterMorceau():
    global titre;
    global id;
    global serveur;
    titre = raw_input("Veuillez entrer le nom du morceau : ");
    '''resultat = serveur.getIdMorceauByTitre(titre);'''
    interprete = raw_input("Veuillez entrer l'interprete : ");
    genre = raw_input("Veuillez entrer le genre : ");
    url = raw_input("Veuillez entrer l'URL : ");
    print "Ajout morceau..."
    id = serveur.addMorceau(titre)
    print id
    serveur.setInterpreteMorceauById(int(id),interprete)
    serveur.setGenreMorceauById(id,genre)
    serveur.setURLMorceauById(id,url)

    Result :

    Traceback (most recent call last):
    File "UIclientV2.py", line 143, in
    menuPrinci();
    File "UIclientV2.py", line 31, in menuPrinci
    ajouterMorceau();
    File "UIclientV2.py", line 85, in ajouterMorceau
    serveur.setInterpreteMorceauById(int(id),interprete)
    File "/home/hector/Téléchargements/python/ClientServeur_ice.py", line 72, in setInterpreteMorceauById
    return _M_MP3.ClientServeur._op_setInterpreteMorceauById.invoke(self, ((id, interprete), context))
    Ice.UnknownException: exception ::Ice::UnknownException
    {
    unknown = java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at TP3.ClientServeurI.setInterpreteMorceauById(ClientServeurI.java:43)
    at MP3.ClientServeur._iceD_setInterpreteMorceauById(ClientServeur.java:113)
    at MP3.ClientServeur._iceDispatch(ClientServeur.java:261)
    at com.zeroc.IceInternal.Incoming.invoke(Incoming.java:226)
    at com.zeroc.Ice.ConnectionI.invokeAll(ConnectionI.java:2695)
    at com.zeroc.Ice.ConnectionI.dispatch(ConnectionI.java:1282)
    at com.zeroc.Ice.ConnectionI.message(ConnectionI.java:1193)
    at com.zeroc.IceInternal.ThreadPool.run(ThreadPool.java:416)
    at com.zeroc.IceInternal.ThreadPool.access$500(ThreadPool.java:12)
    at com.zeroc.IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:785)
    at java.lang.Thread.run(Thread.java:748)

    }

  • Problem solved, index error in Java Interface

  • After small debug of Java server, all the project is working, thanks a lot