Getting "Error: Could not find or load main class aQute.launcher.Launcher" in Eclipse IDE even though it works in command line

412 views Asked by At

I am currently on a project which uses OSGi/Bndtools. I'm still new to OSGi/Bndtools so please be patient with me.

I had been developing using Eclipse IDE (2020-03) with Bndtools (5.0.1). However, I reformatted my PC and I can't seem to get my OSGi program to work on my new Eclipse IDE/Bndtools setup. I am currently using Eclipse (2020-03) with Bndtools (5.3.0 REL). (I have not found a way to download the older Bndtools version 5.0.1).

Summary of error: When I click the 'Run OSGi' button for my BND Run Description file (stub.bndrun), I see the following error in the Eclipse console:

Error: Could not find or load main class aQute.launcher.Launcher

There is no other text given in console, and the OSGi program fails to run.

However, when I execute the following line in terminal, my OSGi/Bnd program does indeed run:

bnd stub.bndrun

where stub.bndrun is the same BND Run Description file.

EDIT: Here's the repo which you can use to reproduce my issue: https://github.com/vorajeem/bndtools_error_reproduce_public.git

Other details of stub.bndrun are given below:

-runfw: org.apache.felix.framework;version='[5.2.0,5.2.0]'
-runee: JavaSE-1.8
-runsystemcapabilities: ${native_capability}

-resolve.effective: active

-runvm: -Dosgi.console

I think my problem is similar to the one given in the following question:Could not find main class while it does exist. But I do not understand the answer given to the question in the link above.

Attempt 1: Based on the answer to question #27457710 given above, I have added the Apache Felix framework (5.2.0) to the 'Run Bundles', but I still get the same error message.

I have seen other questions with a similar error message on StackOverflow (i.e. Could not find or load main class [package-name]. However, no mention is made of Bndtools - and I think my issue may be related to the way Bndtools is setup on my PC.

Attempt 2: I've added 'biz.aQute.launcher' (3.0.0) to my 'Run Bundles', but I still get the same error message.

Requesting your help. Thanks in advance.

EDIT:

I've added -runvm -verbose:class to stub.bndrun, and clicked 'Run OSGi'/'Debug OSGi'. The output is long list of the classes which are loaded (as well as the previous error I had been seeing). I've added the first 2 lines and the last few lines of the output. It seems like it successfully loads all the JAVA packages (The loaded packages all start with java. or sun. prefix and they all come from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib).

However, it cannot find any OSGi/Bndtools packages(??). I'm wondering if my Bndtools repositories are setup correctly?... How can I make sure that is the case?

[Opened /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.lang.Object from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.io.Serializable from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
...
[Loaded java.text.AttributedCharacterIterator$Attribute from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.text.Format$Field from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.text.MessageFormat$Field from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.lang.Shutdown from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
[Loaded java.lang.Shutdown$Lock from /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
Error: Could not find or load main class aQute.launcher.Launcher
1

There are 1 answers

1
Zyrando On

I ran into the same problem. I was just trying to start an empty OSGi-Component generated with the bndtools-template.

In my case I just had to remove the generated module-info.java and the bndrun started correctly.