This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 246071 - Dependent jar not integrated in project manifest
Summary: Dependent jar not integrated in project manifest
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 8.0
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-28 17:35 UTC by ulfzibis
Modified: 2014-08-06 08:40 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Test projects (36.41 KB, application/octet-stream)
2014-07-29 07:32 UTC, Tomas Zezula
Details
3 test projects (41.70 KB, application/zip)
2014-07-29 23:16 UTC, ulfzibis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ulfzibis 2014-07-28 17:35:08 UTC
[ JDK VERSION : 1.7.0_45 ]

STEPS:
   * Java project without Main class set.
   * Add dependent project via Libraries->Add JAR/Folder i.e dist/Other.jar.
   * Build project.

ACTUAL:
   The dependent jar is copied to dist/lib/Other.jar. OK

EXPECTED:
   Additionally /lib/Other.jar should be added to manifest of dist/This.jar
Comment 1 Tomas Zezula 2014-07-29 07:31:39 UTC
Works for me.
1) Create TestLib project
2) Create TestApp project
3) Build TestLib
4) Add LestLib/dist/TestLib.jar as JAR/Folder.
5) Build TestApp

Here is the TestApp.jar manifest content:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0-b132 (Oracle Corporation)
Class-Path: lib/TestLib.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: testapp.TestApp


There is CP attribute with lib/TestLib.jar
I will also attach the test projects.
Comment 2 Tomas Zezula 2014-07-29 07:32:51 UTC
Created attachment 148375 [details]
Test projects
Comment 3 ulfzibis 2014-07-29 23:16:28 UTC
Created attachment 148396 [details]
3 test projects

Try this one.

STEPS:
   Run TestApp.jar

ACTUAL:
Exception in thread "main" java.lang.NoClassDefFoundError: org/me/lib/Util
	at org.me.lib.Util2.sub(Util2.java:14)
	at testapp.TestApp.main(TestApp.java:20)
Caused by: java.lang.ClassNotFoundException: org.me.lib.Util

EXPECTED:
   The dependent lib/TestLib.jar should be added to manifest of TestLib2/dist/TestLib2.jar
Comment 4 ulfzibis 2014-07-30 09:58:02 UTC
(In reply to Tomas Zezula from comment #1)
> 5) Build TestApp
> Here is the TestApp.jar manifest content

I) Your TestApp does not fulfil the condition of step 1:
   * Java project without Main class set.


II) Additionally IMO when for a project, here TestApp.jar, there is another dependence in a dependent jar, here TestLib2.jar dependent on TestLib.jar:
- Add TestLib.jar + TestLib2.jar to TestApp/dist/.
- Add lib/TestLib.jar + lib/TestLib2.jar to classpath of TestApp.jar/MF

Could this be covered by this bug or should I open a separate jar?
However, because of the missing condition at this moment it is unclear, if II) is already implemented.
Comment 5 Tomas Zezula 2014-08-04 16:40:47 UTC
I've tested the attached 3 projects.
When built, the TestApp.jar MANIFEST-MF contain is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0-b132 (Oracle Corporation)
Class-Path: lib/TestLib2.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: testapp.TestApp

It contains Class-Path: lib/TestLib2.jar which is correct.
It does not contain TestLib.jar as there no runtime dependency on it, the Ant projects unlike Maven have no transitive dependency. You need to add TestLib at least to Runtime ClassPath. If you do it and rebuilt the TestApp the TestApp.jar MANIFEST-MF contain is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0-b132 (Oracle Corporation)
Class-Path: lib/TestLib2.jar lib/TestLib.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: testapp.TestApp

Here is an enhancement for automatic adding of transitive libs to runtime classpath:
https://netbeans.org/bugzilla/show_bug.cgi?id=47507


Also when you create the project as a library project it has by default disabled copying of dependencies (as the library is a dependency itself). You can enable it in the Project Properties/Packaging/Copy Dependent Libraries.
Comment 6 ulfzibis 2014-08-05 20:45:52 UTC
(In reply to Tomas Zezula from comment #5)
> Here is an enhancement for automatic adding of transitive libs to runtime
> classpath:
> https://netbeans.org/bugzilla/show_bug.cgi?id=47507

Thanks for the pointer.

> Also when you create the project as a library project it has by default
> disabled copying of dependencies (as the library is a dependency itself).
> You can enable it in the Project Properties/Packaging/Copy Dependent
> Libraries.

Aha, the dependency classpath is only set, if copying of dependencies is enabled, and the latter is not enabled by default for libraries, but for applications.

So thanks for the explanation and sorry for the noise.
Comment 7 Tomas Zezula 2014-08-06 08:40:23 UTC
>Aha, the dependency classpath is only set, if copying of dependencies is enabled, and >the latter is not enabled by default for libraries, but for applications.
Yes.

>So thanks for the explanation and sorry for the noise.
No problem. Better noise then forgotten bug.