0

So I am stuck with a problem when debugging with the most recent version of Eclipse 2020-03, which I installed for a new project I'm working on. It first struck me that things were not working correctly when I couldn't read a resource with Class.getResource( String name ), as the debugger at the breakpoint in getResource(..) kept telling me that the name was null, while I definitely had provided a path name.

Clearing, cleaning, reloading the target (Running Platform), refreshing and rebuilding did not change anything, so I decided to create a simple OSGI plugin project with just an Activator, and a debug configuration with only the bare minimum bundles.

The Activator looks like this:

public class Activator implements BundleActivator {

        public static final String BUNDLE_ID = "test.myapp.core";

        private static BundleContext context;

        private Logger logger = Logger.getLogger(this.getClass().getName());

        static BundleContext getContext() {
            return context;
        }


        public Activator() {
            super();
            logger.info("STARTED: " + BUNDLE_ID);
        }


        @Override
        public void start(BundleContext bundleContext) throws Exception {
            logger.info("ACTIVATED: " + BUNDLE_ID);
            Activator.context = bundleContext;
            InputStream in = getClass().getResourceAsStream( "/test.cfg" );
        }


        @Override
        public void stop(BundleContext bundleContext) throws Exception {
            Activator.context = null;
        }

    }

EDIT: Changed the original link to build.properties to test.cfg in order to avoid confusion.

But when I start the debugger, it will activate the bundle, but will not show any of the log messages. Also the debugger will not respond to the breakpoints I put in. Strangely enough, selecting 'ss' shows me far more bundles than the ones provided in the debug configuration.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.15.200.v20200214-1600
1 ACTIVE test.myapp.core_1.0.0.qualifier
2 ACTIVE org.apache.lucene.core.source_8.4.1.v20200122-1459
3 ACTIVE javax.annotation.source_1.2.0.v201602091430
....

It seems as if a different debug configuration is launched, and is using an previously built version of my bundle, where the log messages were not yet included. clearing the bin folder, and eventually all the metadata also had no effect.

I'm totally stumped as of what I'm experiencing here. Hopefully someone can help!

keesp
  • 301
  • 2
  • 13
  • It's not clear to me what you did and what you claim to be weird here. There are situations where you need to delete/clean the configuration area (see run configuration tab _Configuration_). Make also sure to include all resources via source folder or via `build.properties` (to access this file on runtime does not make sense to me). – howlger Apr 19 '20 at 14:41
  • Hi, I did all that; that's what i meant with cleaning, clearing, etc, etc. all the straightforward actions that sometimes cause the IDE to do strange things. But to be complete: - clearing debug configuration, check! synchronizing target: check; refreshing and cleaning projects: check; deleting binary build: check; deleting metadata: check – keesp Apr 19 '20 at 14:52
  • and the build.properties, was just to see if it could detect a file (inputStream != null). I also tried all the variants with '/' just to be sure. – keesp Apr 19 '20 at 14:59
  • `build.properties` is not included by default and there are different ways to include it (it is a common mistake not to include it). Please give an exact step-by-step instruction how to reproduce this issue. Describe what you get vs. what you expect. In your example, what is the purpose of the logger? You have the variable `in` that is never used. So the compiler will not include it in the bytecode and what does not exist cannot be debugged. What you mean by _"when I start the debugger"_? Please edit your question (shorter is better and please ask only one question) instead of adding comments. – howlger Apr 19 '20 at 15:31

1 Answers1

0

Well..as it seems, I found out what was wrong. There were two problems that were occuring all at once:

1: Regarding the problems with getResource( String name). The Bundle-ClassPath setting in Manifest.MF MUST include . (see https://www.eclipse.org/forums/index.php/t/287184/), so in my case:

Bundle-ClassPath: .,
 test.myapp.core

Bundle-ClassPath is not added automatically by the plugin wizards, so that can cause some problems.

2: The Debug configuration screen in the new IDE seems to be very slow, and does not change the selected bundles if you switch from "only show selected" and back. As a result, the previous list of bundles remained active, while they were unchecked in the Debug Configuration Editor.

I'll file a report for these issues

ADDITIONAL

So I have made some further investigations on the Bundle-ClassPath issue, and what probably has happened that this entry in the Manifest.MF occured when adding some libraries. After they were removed again, the Bundle-ClassPath entry remained, and caused all sorts of problems. If you ever:

1: Notice that certain classes from bundle A cause a NoClassDefFound exception when used in bundle B
2: The build.properties file from bundle A give a warning that sources are missing
3: Other bundles don't seem to give that problem

Check to see if there is a Bundle-ClassPath entry in your Manifest.MF file. Most probably that entry is causing the problems. Either remove the entry in the manifest, or add ,. at the end.

see:
1: What is the intended use case for Bundle-Classpath in OSGI bundles
2: https://bugs.eclipse.org/bugs/show_bug.cgi?id=139271

keesp
  • 301
  • 2
  • 13