Bug 435209 - Bad classpath in exported build.xml for dependent plugin
Summary: Bad classpath in exported build.xml for dependent plugin
Status: RESOLVED WONTFIX
Alias: None
Product: PDE
Classification: Eclipse Project
Component: Build (show other bugs)
Version: 4.3.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: pde-build-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted, investigate
Depends on:
Blocks:
 
Reported: 2014-05-19 09:46 EDT by Hernan Gonzalez CLA
Modified: 2018-11-13 07:27 EST (History)
4 users (show)

See Also:


Attachments
Example projects demonstrating this problem (6.63 KB, application/x-zip-compressed)
2015-12-03 08:54 EST, Mikhail Kalkov CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hernan Gonzalez CLA 2014-05-19 09:46:10 EDT
Create an blank plugin "plugin1", then a second plugin "plugin2" that depends on "plugin1" (plugin dependence). 

In some class in plugin1 (say, Activator) create a method

public static void sayHi() {
	System.out.println("plugin1 says hi");
}

Create a class in plugin2 that calls that method :

public class Class1 {
	@Test
	public void mytest() {
		plugin1.Activator.sayHi();
	}

	public static void main(String[] args) {
		(new Class1()).mytest();
	}
}


Test that it runs ok, as Java app and as Junit test

Then generate a ANT build.xml for plugin2: 
plugin2 -> Export -> General -> Ant BuildFiles

Open the generated build.xml and try to run the Class1 target (either as Java app, or a Junit test). It fails java.lang.NoClassDefFoundError: plugin1/Activator

Looking inside the build.xml I see

  <path id="Plug-in Dependencies.libraryclasspath">
        <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ui_3.105.0.v20130522-1122.jar"/>
        ....
        <pathelement location="../../../../plugin1"/>
 </path>


That last entry looks wrong; it misses the "bin/" and it can't imagine what's it's being relative to... If I manually change it to 

        <pathelement location="../..plugin1/bin"/>

then it works.
Comment 1 Hernan Gonzalez CLA 2014-05-24 13:57:28 EDT
I think there is another related (but more fundamental issue). 

The classpath built in as <path id="Plug-in Dependencies.libraryclasspath">  element only gathers the dependent plugins as declared in the plugin. But this totally misses the transitive dependencies.

Say plugin2 depends on plugin1. Some plugin2.Class2 class instances a plugin1.Class1 (exported by plugin1), and  plugin1.Class1 instances/references a class exported from another plugin, from say, org.eclipse.emf.ecore*.jar . If
plugin1 has included org.eclipse.emf.ecore*.jar among its dependencies, all compiles and runs ok (as it should). Specifically, I can see in the Eclipse debugger that when I run plugin2.Class2 the passed classpath includes org.eclipse.emf.ecore*.jar (because, I guess, it was computed as a transitive dependence). 

However, if I want to run plugin2.Class2 from some Ant task, and I use the classpath exported by Eclipse in build.xml, I will fail, because, as mentioned, org.eclipse.emf.ecore*.jar will not be included.
Comment 2 Mikhail Kalkov CLA 2015-12-03 08:54:51 EST
Created attachment 258437 [details]
Example projects demonstrating this problem

I've experienced the same issue with unit tests. They would run perfectly fine in command line with Tycho, but fail as soon as you try to run them in Eclipse PDE. However, importing one of project dependencies into Eclipse workspace has fixed the tests. Debugging has shown that Eclipse launch configuration lacks transitive dependencies from jar dependencies.

To reproduce this problem
- download and unzip projects
- import them into a new workspace running Eclipse 4.5.1
- export `plugin1` as a deployable plug-in and add it to your target platform
- run `plugin2` as an Eclipse application and witness that it works
- close `plugin1` project and rerun `plugin2` to witness that it fails with unresolved dependencies

I have expected Eclipse PDE to add transitive dependencies to the classpath.
Comment 3 Lars Vogel CLA 2018-11-13 07:27:19 EST
Mass change for PDE Build bugs tagged with "helpwanted". PDE build is not actively enhanced, hence I close these bugs as wontfix. Please reopen if you want to contribute a patch.