Sign in to follow this  
xissburg

[java] Cant run programs compiled within NetBeans outside NetBeans

Recommended Posts

xissburg    204
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. . .. .. .. . .. .... . . . . . . . . . . .

Share this post


Link to post
Share on other sites
RIZAX    127
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.

Share this post


Link to post
Share on other sites
greggles    347
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this