# 2.1.1 java code generation with interfaces

**URL:** <https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506>\
**Category:** App Development\
**Tags:** daml, features and bugs, daml-sdk\
**Created:** [May 10, 2022, 5:47pm UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506 "2022-05-10T17:47:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_Safar1](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/jean_safar1/32/2860_2.png) [@Jean\_Safar1](https://forum.canton.network/u/Jean_Safar1)\
**Post date:** [May 10, 2022, 5:47pm UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/1 "2022-05-10T17:47:54Z")

</div>

Hi,  
Using daml 2.1.1 sdk.  
I have a simple template:

module Counter where

template Counter  
with  
owner : Party  
value : Int  
incrementers : [Party]  
rules: [ContractId CounterRule]  
where  
signatory owner  
observer incrementers  
key owner : Party  
maintainer key

```
choice Increment : ContractId Counter
  with incrementer : Party
  controller incrementer
    do
      create this with value = value + 1

```

interface CounterRule where  
apply : Party → Bool

When generating the grpc java code with a daml codegen java I noticed something out of place in that the rule, is placed outside the package indicated into java command:

daml codegen java .daml/dist/counter.dar=test -o …/grpctest/src/main/java

Inside src/main/java I see 2 packages:  
counter  
test

In counter I see the counter rule. Yet, in test I see all the regular packages. But does not compile since it cannot find the CounterRule …  
counter/Counter.java:38: error: package CounterRule does not exist  
public final List\<CounterRule.ContractId\> rules;  
^  
Any clue as to what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [May 11, 2022, 9:21am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/2 "2022-05-11T09:21:11Z")

</div>

Hi @Jean_Safar1,

I’m not very familiar with the Java codegen myself, but I know it’s been a pretty active project over the past few weeks, particularly around interface integration. Before we delve into this further, can you double-check whether you still see this issue if you use `2.2.0-snapshot.20220504.9851.0.4c8e027d` instead of `2.1.1`?

---

<div class="post-metadata">

**Author:** ![Jean\_Safar1](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/jean_safar1/32/2860_2.png) [@Jean\_Safar1](https://forum.canton.network/u/Jean_Safar1)\
**Post date:** [May 11, 2022, 9:54am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/4 "2022-05-11T09:54:28Z")

</div>

I will check with the snapshot!

---

<div class="post-metadata">

**Author:** ![Jean\_Safar1](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/jean_safar1/32/2860_2.png) [@Jean\_Safar1](https://forum.canton.network/u/Jean_Safar1)\
**Post date:** [May 11, 2022, 9:57am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/5 "2022-05-11T09:57:10Z")

</div>

It does with the example I put above

---

<div class="post-metadata">

**Author:** ![victor.pr.mueller](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/victor.pr.mueller/32/2083_2.png) [@victor.pr.mueller](https://forum.canton.network/u/victor.pr.mueller)\
**Post date:** [May 11, 2022, 10:00am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/6 "2022-05-11T10:00:51Z")

</div>

So it does or does _not_ work with the snapshot?

---

<div class="post-metadata">

**Author:** ![victor.pr.mueller](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/victor.pr.mueller/32/2083_2.png) [@victor.pr.mueller](https://forum.canton.network/u/victor.pr.mueller)\
**Post date:** [May 11, 2022, 10:04am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/7 "2022-05-11T10:04:14Z")

</div>

Counter.daml

```haskell
template Counter
  with
    owner : Party
    value : Int
    incrementers : [Party]
    rules: [ContractId CounterRule]
  where
    signatory owner
    observer incrementers
    key owner : Party
    maintainer key

    choice Increment : ContractId Counter
        with incrementer : Party
        controller incrementer
            do
            create this with value = value + 1

interface CounterRule where
    apply : Party → Bool

```

So that is the full daml code?

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [May 11, 2022, 10:27am UTC](https://forum.canton.network/t/2-1-1-java-code-generation-with-interfaces/4506/8 "2022-05-11T10:27:29Z")

</div>

Hi @Jean_Safar1,

I can reproduce the issue. Here are specific repro steps:

```plaintext
daml new t
cd t
echo 'interface TestInt where' >> daml/Main.daml
echo ' f : Int -> Int' >> daml/Main.daml
echo 'build-options:' >> daml.yaml
echo ' - --target=1.dev' >> daml.yaml
daml build
daml codegen java .daml/dist/t-0.0.1.dar -o jvm1
daml codegen java .daml/dist/t-0.0.1.dar=prefix -o jvm2

```

Comparing the contents of `jvm1` and `jvm2` at that point shows that the `TestInt` file ends up in the wrong place, e.g. with

```plaintext
$ diff <(cd jvm1; find .) <(cd jvm2/prefix; find .)
8d7
< ./main/TestInt.java

```

Specifically, for `jvm2`, it ends up in `jvm2/main/TestInt.java` instead of `jvm2/prefix/main/TestInt.java` as expected.

We’ll be looking into this further. Thanks for the report!
