Importing a jar file into a workflow

There are a lot of examples out there of importing groovy files into Nextflow workflows Groovy Imports - training.nextflow.io

There are also some examples of importing java functions

import java.nio.file.Files

How would you import a jar file? The docs claim you can Pipeline sharing — Nextflow v24.08.0-edge documentation

Hi Edmund!

From what I understand this this is the purpose of the magic lib directory. Try creating the lib dir in your pipeline root and dropping the jar in there and seeing if it works. :test_tube:

Hey Ken!

Thanks, I got that from the docs. I’m looking for what’s the exact syntax to import the jar though, I’ve done that, just struggling to use the library then.

I have an old (DSL1, but perhaps that doesn’t matter) example here,

I don’t think you need to import the jar explicitly, just import classes/methods you want to use.

E.g.

import com.myclass.MyClass

or

import static com.myclass.MyClass.method
4 Likes

Awesome, thanks for posting that!

I figured it out eventually Fix import · edmundmiller/cid-nf@dfdd730 · GitHub

The part that I also really struggled with was figuring out what the namespace was in the jar.

$ jar tf java-cid-v1.3.8.jar

META-INF/MANIFEST.MF
META-INF/
io/
io/ipfs/
io/ipfs/cid/
META-INF/maven/
META-INF/maven/com.github.ipld/
META-INF/maven/com.github.ipld/java-cid/
io/ipfs/cid/Cid$Codec.class
io/ipfs/cid/Cid.class
io/ipfs/cid/Cid$CidEncodingException.class
META-INF/maven/com.github.ipld/java-cid/pom.xml
META-INF/maven/com.github.ipld/java-cid/pom.properties

Which led to

import io.ipfs.cid.Cid
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.