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.
In a java project, which comes without the file MANIFEST.MF in the project directory, I set the value of "main.class" and build my file. Then I tried to run the compiled project from the jar file and got the error "Cannot find main class" I add an empty MANIFEST.MF into the project directory, set the "manifest.file" in build.xml, and the compiled jar file now have Main Class specified in its embeded MANIFEST.MF! The problem comes from the fact that in build-impl.xml: <target name="-do-init" depends="-pre-init,-init-private,-init-user,-init- project,-init-macrodef-property"> <available file="${manifest.file}" property="manifest.available"/> <condition property="manifest.available+main.class"> <and> <isset property="manifest.available"/> <isset property="main.class"/> <not> <equals arg1="${main.class}" arg2="" trim="true"/> </not> </and> </condition> and I'm not quite sure why this is set to behave in such a way.
So, what is the expected (not so funny?) behavior?
shouldn't the main class be set in MANIFEST.MF regardless of whether an empty version of the file exists in the project directory?
Why? If you're creating a project from existing sources that don't include MANIFEST.MF, there is probably some reason why it's missing. Would you expect the IDE to create it for you and set the Main-Class attribute? Sorry, this is not a P1 defect. In fact, I am not conviced it's a defect at all.
So why am I setting a Main Class in my project if that is not my Main Class in the packaged JAR? Well if creating an empty MANIFEST.MF file for any new projects is a suggested fix, I would accept that personally - since this behaviour feels counter- intuitive and I didn't get any help from the Help in the IDE!
Re "if creating an empty MANIFEST.MF file for any new projects is a suggested fix" If you're creating a project from scratch, then the IDE creates a new MANIFEST.MF for you, of course. If you're creating a project from existing sources, how can it decide the missing MANIFEST.MF is not an intention? Re "why am I setting a Main Class in my project if that is not my Main Class in the packaged JAR?" I assume you're well aware that the Main Class setting is also used when running/debugging the project in the IDE, so it's a useful property to set, even if MANIFEST.MF is missing.
ah, now I see the point: 1) The project was created as a Class Library. 2) Later on, (after having a few classes) I have decided that it should just be an Application instead; so I created a "Java Main Class" to the project, and set it as the project main class. obviously in this case MANIFEST.MF would be missing. I'm wondering though, so what is the proper way to get round this problem in the first place?
Hmm, we could possibly generate a warning when building the project jar (for the first time). E.g.: "You're building an application JAR without the manifest.mf file. Do you want the IDE to create it for you? Yes/No". Or (simpler), the warning could be printed in the build process output "Building application JAR without the manifest.mf file." This would need to be specified. Not for 5.0.