# Use channels in .groovy file or include classes defined in another .nf module

**URL:** <https://community.seqera.io/t/use-channels-in-groovy-file-or-include-classes-defined-in-another-nf-module/587>\
**Category:** Ask for help\
**Tags:** groovy\
**Created:** [March 25, 2024, 6:57am UTC](https://community.seqera.io/t/use-channels-in-groovy-file-or-include-classes-defined-in-another-nf-module/587 "2024-03-25T06:57:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [March 25, 2024, 6:57am UTC](https://community.seqera.io/t/use-channels-in-groovy-file-or-include-classes-defined-in-another-nf-module/587/1 "2024-03-25T06:57:38Z")

</div>

I’m trying to create a groovy class that manipulates channels.

I can do this if I define the class within the .nf file that uses it. But if I try to move the class to a separate .nf file, or put it in a .groovy file which I then compile and include with a regular groovy include statement, I get errors. Trying to use `include {MyClass} from classes.nf` results in an error `ERROR ~ MyClass.<init>()`, while trying to use `include MyClass` where MyClass is compiled in a .jar file results in an error that the `channel` object is unknown.

Either a way of including classes defined in other .nf files, or a way of including the Nextflow dependencies like the channel object that would make it possible to include .jar classes that act on channel objects would solve my problem.

Thank you!

---

<div class="post-metadata">

**Author:** ![Adam\_Talbot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/adam_talbot/32/62_2.png) [@Adam\_Talbot](https://community.seqera.io/u/Adam_Talbot)\
**Post date:** [March 26, 2024, 11:51am UTC](https://community.seqera.io/t/use-channels-in-groovy-file-or-include-classes-defined-in-another-nf-module/587/2 "2024-03-26T11:51:14Z")

</div>

Two options here.

Firstly, you can include a Java class in the `lib/` directory and it will be imported automatically. You can see that in action in the nf-core template: [rnaseq/lib at master · nf-core/rnaseq · GitHub](https://github.com/nf-core/rnaseq/tree/master/lib)

However, for manipulating a channel you might find it easier to define a simple function which can be imported like any module or workflow: [Scripts — Nextflow 23.10.1 documentation](https://www.nextflow.io/docs/latest/script.html#functions).
