Bug 177194 - [68cat] Java library projects do not package main class
[68cat] Java library projects do not package main class
Product: java
Classification: Unclassified
Component: Project
PC Linux
: P3 (vote)
: 7.4
Assigned To: Tomas Zezula
Depends on:
  Show dependency treegraph
Reported: 2009-11-19 06:10 UTC by dynamite
Modified: 2013-07-10 12:19 UTC (History)
0 users

See Also:
Issue Type: DEFECT


Note You need to log in before you can comment on or make changes to this bug.
Description dynamite 2009-11-19 06:10:01 UTC
Java application projects are created with manifest.mf file containing only comments and a manifest.file property in nbproject/project.properties.  Java library projects have neither of these.  Nevertheless, it is possible for a user to specify a "main" class for a library project.  The user may then be forgiven for thinking that they now have an application project (note that manifest.mf only appears under Files and not Projects).  Alas they do not because manifest.mf and the manifest.file property are both still missing.  Thus whilst running the project will run the main method of the specified main class, the jar that ant creates will not have the Main-Class attribute set in its manifest.

There is a work-around which is for the user to manually set manifest.file=manifest.mf in nbproject/project.properties and create an ampty manifest.mf file in their projects root directory.  It may take the user some time though to find this out.

I propose that library projects should differ from application projects only in that they are not created with a main class.  manifest.mf should exist and the manifest.file property defined.  The setting of Main-Class should only depend then upon whether there is a main class defined for the project.  This leaves the fewest surprises for the unwary user.
Comment 1 Tomas Zezula 2009-11-19 06:24:59 UTC
There is no reason why the library does not have manifest.mf, at least I don't remember any.
Scheduling for Nb 6.9
Comment 2 Vince Kraemer 2010-05-17 17:11:25 UTC
There is a question on stack overflow about this...


I tried to do the following with a Java Library Project in 6.9

1. create an empty manifest.mf file at the project root.
2. add 'manifest.file=manifest.mf' in the project properties.

When I did a clean and build... The MANIFEST.MF file in the jar did not include a Main-Class entry...
Comment 3 Vince Kraemer 2010-05-17 17:14:53 UTC
it looks like bug 178796 and bug 182897 are variations on the same 'theme' as this one...

TomasZ: You may want to close the others as a dup of this...  If you do, you may want to raise the priority of this issue, too.
Comment 4 Tomas Zezula 2010-05-17 18:02:48 UTC
For apps (manifest+main.class) the J2SEProject does the copying of dependent libs and adds the Class-Path attribute into the manifest. This is unwanted for libs, see issue #180707. I didn't put it into 6.9 as I was afraid main class in library (causing Class-Path attribute to be added) as a dependent project.
Comment 5 Marian Mirilovic 2010-09-24 10:26:02 UTC
Comments from Rob Conklin:
I am afraid this bug inspires a fairly substantial 'rant'....

There may be a patch or update for this that I haven't got.  But 6.9 should never have shipped with this bug in the first place.   This is an unbelievable lapse in quality control, IMHO.

I switched to Netbeans from Eclipse simply *because* of Netbeans configuration of Ant build to package project jar files into /lib subdirectory and fix the manifest to include the program jar's main class and reference to classpath pointing at /lib! 

I am almost ready now to switch *BACK* !

To break something like this really causes head-aches -- it's a nightmare in general to deal with classpath (note: dumping 'classpath entirely would be the biggest boon to Java development since the beginning, and would be a more significant improvement than anything that has appeared in platform evolution over decades -- it would restore millions of hours of programmer productivity to the free pool, and make Java a much more popular programming tool [not that it isn't already, but there's no reason to keep stupid features like classpath just because they don't completely alienate everyone enough to keep them from programming in Java -- it's close -- I hated it when I first encountered it, and I've never gotten any warmer in my feelings about it over the last 4-5 years of doing development full-time with Java!!!!

 ... the complexities of Java projects these days, with all the .xml files that  go into it.  Jesus, can someone focus on a *vast* simplification, such as simply having any .jar files in the same directory as the main  class or jar containing the main class automatically be searched for classes that the project may depend on (like .NET).   I suggest completely eliminating classpath from Java -- does anyone really enjoy dealing with this or find it really useful?  Better to have a simple mechanism like the cwd & to support something like a global cache library that can be used to add specific libraries that are critical for mulitple projects, (again, have a look at .NET, netgen, that sort of thing).

In the meantime, if it isn't fixed already, please fix this one, it's more than a 'defect' it's a disaster, highest priority bug, IMHO -- it's just incredible that this got broken.
Comment 6 Tomas Zezula 2011-02-02 17:43:18 UTC
The libraries copying was disabled due to j2ee server problems with non existent Class-Path reference.
In the NB 7.0 I've added Project/Properties/Packaging/Copy  Dependent Libraries which allows to turn it on. When you create a new project it's enabled for apps by default. For libraries you have to turn it on in customizer.

fixed jet-main 4c0bdd9bb167
Comment 7 Quality Engineering 2011-02-03 05:52:28 UTC
Integrated into 'main-golden', will be available in build *201102030000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/4c0bdd9bb167
User: Tomas Zezula <tzezula@netbeans.org>
Log: #177194:[68cat] Java library projects do not package main class
Comment 8 Jeff_Vallis 2012-03-20 20:23:17 UTC
Product Version: NetBeans IDE 7.1 (Build 201112071828)
Java: 1.6.0_29; Java HotSpot(TM) 64-Bit Server VM 20.4-b02-402
System: Mac OS X version 10.6.8 running on x86_64; MacRoman; en_US (nb)
User directory: /Users/Jeff/.netbeans/7.1
Cache directory: /Users/Jeff/.netbeans/7.1/var/cache

Well I am still having the same problem 
MANIFEST.MF no main class

So Read this above and tried it 

I tried to do the following with a Java Library Project in 6.9

1. create an empty manifest.mf file at the project root.
2. add 'manifest.file=manifest.mf' in the project properties.
Now I presume by project properties. that we mean
Right Click main Project - Choose Properties
In the Categories choose Actions
Bottom Right Set Properties
Add Button - Disabled
so could not do this as a work round

Would be glad to send my Project so you can check
Comment 9 archenroot 2013-07-10 11:37:11 UTC
This is still alive as I see, I am using the Netbeans 7.3 version and maven project still not working for me. the manifest class doesn't incluede the main class attribute deffinition.
Comment 10 Tomas Zezula 2013-07-10 12:19:49 UTC
In reply to comment #9:
Works in NB 7.4 for Ant project, please the java/project category are issues for Ant based project or generic infrastructure. The Maven issues belong to projects/maven. I know that it's a strange but it was set in this way.

For Ant based project in NB 7.4:
1) When library has a main class set the jar's manifest contains Main-Class attribute.
2) If you want the build to create the lib folder with dependences (as the Java Application does) go to Project's Properties/Packaging and enable "Copy Dependent Libraries"

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo