Hi,

> I've tried building both imagej2 and fiji that I cloned from github. I'm
> building it in netbeans using maven and get the same error message:
>
> java.lang.IllegalArgumentException: Invalid service:
> net.imagej.legacy.LegacyService

That's a runtime error, not a compile-time error. Presumably, you are
receiving this error when you try to run the Main class's main method?

My guess is that your IDE is configured to use Java 17 or later. As of Java
17, the Java platform is stricter regarding when reflection is allowed.
Here are three options to work around this issue:

1) Configure your IDE to build and run with Java 11 instead.

2) Configure your IDE to pass needed --add-opens flags when launching the
program:

--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.net=ALL-UNNAMED
--add-opens=java.base/java.nio=ALL-UNNAMED
--add-opens=java.base/java.time=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/sun.util.calendar=ALL-UNNAMED
--add-opens=java.desktop/java.awt=ALL-UNNAMED
--add-opens=java.desktop/javax.swing=ALL-UNNAMED
--add-opens=java.desktop/sun.awt=ALL-UNNAMED

On Linux, also:
--add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED

On macOS, also:
--add-opens=java.desktop/com.apple.eawt=ALL-UNNAMED

3) Remove the imagej-legacy dependency from the project pom.xml. This will
avoid the LegacyService initialization error, but you will lose backwards
compatibility with the original ImageJ in the process.

Regards,
Curtis

On Thu, Apr 11, 2024 at 3:16 AM William Rust <[email protected]> wrote:

> Hi,
>
> I've tried building both imagej2 and fiji that I cloned from github. I'm
> building it in netbeans using maven and get the same error message:
>
> java.lang.IllegalArgumentException: Invalid service:
> net.imagej.legacy.LegacyService
>
> Is there some way to build it without using the legacy service? Or, what do
> I need to do to install the service?
>
> wjr
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
  • build error William Rust
    • Re: build error Curtis Rueden

Reply via email to