Home Help Center

packageless class generated by Slice2java

sylvainsylvain Member Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systems ✭✭

I am beggining with Java and I am using the Sun NetBeans 3.5 IDE (java sdk 1.4.2).

I am encountering problems because the files that are generated by Slice2Java do not begin with the (afaik) usual "package" declaration.

This prevent the compilation of a generated file that use a class defined in another generated file, and so the whole project cannot be build.

I tryed a lot of trick (playing with the location of the files, and so one...) but the only thing that work is to add a package declaration at the beginning of every generated file.

Of course this can be scripted, but I don't like the idea of modifying a generated file... I can also maybe make a single big file with every genertaed and add a single package declaration at the beginning, so I can use that package name.

I can also compile with the kind of command line that are in the Ice doc, but I really would like to use NetBeans for compiling.

Why is Slice2Java not adding a package declaration when generating files (I even found some pages on the internet that say that a packageless class is not standard) ?

By the way, even if this is not really the place to ask, are there some experienced users that were successful in using NetBeans and Ice without modifying the generated files ?

Thanks a lot in advance


  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    If your Slice definitions do not reside in a module, then the generated class files by default will have no package. There are two ways to address this: you can put your Slice definitions in a module, or you can use the --package option with slice2java. For example, the command

    % slice2java --package MyPackage Foo.ice

    will generate all Java classes in the package MyPackage.

    However, we generally recommend using a module instead.

    Take care,
    - Mark
  • patrahpatrah Member

    Sorry to disturb you with such a question, but what is the parameter
    to add to the slice2java ant task to get the --package in the slice2java program.

    Maybe it is in the doc somewhere, but i haven't read about this yet.

    Thank you very much

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    You would use a task definition such as

    <slice2java package="MyPackage" ...>

    There are some comments in the file ant/Slice2JavaTask.java which might be of use to you.

    Take care,
    - Mark
  • bashkirsbashkirs Member stanislav bashkirtsevOrganization: Barclays CapitalProject: Equities & Derivitives

    Continuing question about packages:
    1. I need derived packages: com.mycompany.myproject.mymodule. How can I accomplish this? Only with:
    module com { 
      module mycompany {
        module myproject {
          module mymodule {
    ? This doesn't seem beautiful :)
    2. It seems that I cannot have more than 8 derived modules, because errors are thrown in this case. This seems very strict restriction, but in enterprise applications nesting of packages may be deeper.
    3. Packages' names can't have "ice" at start! How so? I want module "iceutils", but I can't use such..
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Do something like:
    module mymodule

    If you use this technique then it isn't necessary to deeply nest modules. Also, as far as I'm aware there is no limit. I tested 12 nested modules and didn't get an error. Can you provide a test case which demonstrates your issue?

    As for the restriction regarding Ice, yes this is the case as documented in the Ice manual. See "Reserved Identifiers" in Lexical Rules for details.
Sign In or Register to comment.