[java] Cant run programs compiled within NetBeans outside NetBeans

Started by
3 comments, last by xissburg 16 years, 4 months ago
Why?! I cant run the programs I compile inside NetBeans outside NetBeans. When I double click the .jar file or go to its directory through the prompt and type java -jar someprogram.jar I get an error message that says "Failed to load Main-Class manifest attribute from C\:Documents and Settings\...\someprogram.jar". Have you ever seen this?! How to fix this thing? Thanks in advance. . .. .. .. . .. .... . . . . . . . . . . .
.
Advertisement
I'm no java expert, but I'm pretty sure that your file structure is flubbed somewhere. You probably have netbeans automatically building the manifest file in your system file structure, as well as appending to the classpath. While this will work when your in netbeans, when you try and execute the jar its only looking at the default classpath. If it can't find it on the classpath then it can't load it.
Quote:Original post by xissburg
How to fix this thing?
.
First of all, I'm really tired, so if I missed something extremely obvious, don't blame me[smile]

I wanted to test this, so I created my own "Java Class Library" project and tried to add a main class, which turned out exactly how you described.

So, I checked out the NetBeans webstite for a couple of minutes, but the only way that it described to fix this doesn't work. So, I tried several ways on my own to fix it, and I found a strange one that solved the problem. I'm really tired now, so this may or may not make any sense. I'll share it now, and maybe work on a better answer tomorrow (unless someone else finds a better answer by then).


First, right click on the project and go into properties. Go to the run selection and add the main class. Click ok.

Right click on the project again and add an empty file with the name "manifest.mf".

Next, open the window menu and open the files window. Expand nbproject and open project.properties. Add "manifest.file=manifest.mf" to the project.properties file. Now, build your project and it should work!


Or you could just create a new Java Application project and refactor all of your files into the new project.

Greggles
Hm..thanks :) its working now =D
.

This topic is closed to new replies.

Advertisement