I have designed a simple gui in netbeans on windows but when i try to run it,nothing is showing.My main class is called ModelApp.java and the gui part i designed in netbeans is called app.java. When i try running the jar on command prompt,i get the error
Error: Could not find or load main class ModelApp
Your ModelApp class is probably not in the folder written in the manifest file or something like that.
See JAR Basics
If you want to run your application by clicking on the jar you need to specify the main class in META-INF/MANIFEST.MF file in the jar as it is described http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html . Make sure you have it properly defined.
You should be able to do this in Netbeans during creation of your jar file.
Did you forget to create the main method in ModelApp.java?
public static void main(String[] argv) {
app gui = new app();
}
Normally this should work
Related
My java class files run in Eclipse but not in command line. I have tried all possible solutions. My code has the following structure:
Client_1/src/filedownload/Client.java
RMI_interface/src/filedownload/Hello.java
The Client.java file is dependent on Hello.java. filedownload is the name of package.
When I compile using the following command, it works.
javac RMI_interface/src/filedownload/Hello.java Client_1/src/filedownload/Client.java
But when I execute the class file in the Client_1/src folder using following command, it does not work.
java filedownload.Client
The error displayed is
Could not find or load main class
I have tried many posts on stackoverflow but I am unable to solve it. I am using ubuntu.
The code structure is
package filedownload;
import ....
public class Client implements Hello, Runnable{
...other functions.....
public static void main(String args[])throws Exception{
}
}
Does your Client class have the main() method ? Where are the .class files after compilation (that is, what's the current directory you're executing the compile from) ? What's the current directory when you try to execute ? What's the classpath when you try to execute ?
Without all that info, there's little chance of anyone being able to get you going (but for the obvious advice of just setting up eclipse and doing everything from within eclipse - letting eclipse take care of all the nitty gritty detail).
(And the questions themselves suggest various possible points of failure in your scenario so look at it.)
All your steps seems to be correct. You didn't share the Client.java code which has main method.
Make sure you follow this main method syntax:
public static void main(String[] args){
...
}
E.g. if you write main without args, it can't be found.
You need to put your classes in a separate folder, separated from your sources.
javac -d bin RMI_interface/src/filedownload/Hello.java Client_1/src/filedownload/Client.java
(folder 'bin' must exist already)
And inside folder 'bin' execute command:
java filedownload.Client
just started learning java, i'm looking to save a .java file (TextIO.java) into my working directory. (which file makes up my working directory exactly?)
and then run it through cmd so that Eclipse can use the class.
I tried doing that by saving (and running thru cmd) the file in the folder containing the programs (yah right) i have written already. But Eclipse still cant find the class.
Can i get some help with this?
thanks
You have to create an Eclipse Java project first. The you can copy the file from file system explorer window and paste it on the Eclipse Package Explorer tree. Eclipse projects compile all files in their source folders automatically by default.
The TextIO.java clas you mentioned has a javadoc saying: ... TextIO provides a set of static methods for reading and writing text... This means you use it as a toolkit rather than executing as an application. Given TextIO.java and you class TextIOUtilizer are both in the root of your classpath (source folder in Eclipse), here is how you call a TextIO method:
public class TextIOUtilizer {
/**
* #param args
*/
public static void main(String[] args) {
// code
TextIO.skipBlanks();
//code
}
}
Now you run TextIOUtilizer as a Java application - it has a main method. Hope this helps.
I have my first application written in Netbeans, with supporting libraries. After building the project, the file NetbeansProjects/PDF/dist/PDF.jar runs fine.
I'm ultimately trying to build a OSX app, but think(?) that the first step is to bundle the PDF.jar and the /lib/*.jar files together.
To this end, I'm using JarSplice, but can't work out how set the Main Class. I think it should be found in the manifest.mf file, but it doesn't seem to contain anything. JarSplice requests:
Enter your applications main class file below, complete with any packages that it maybe in.
E.g: my package.someotherpackage.MainClass
Adding System.out.println(main.getClassName()); to my main method gives me "PDF" in the output window of Netbeans.
Can someone tell me how I go about finding the main class, and ideally, because I'm an idiot, exactly what to input into as the main class into JarSplice?
It depends were you put your main class when developing.
Try the class name that contains your main method, if you put your main method in Test.java then put;Test
If your main class is nested in a package then put something like org.package.Test
Once you export your .jar open up the Manifest file and next to Main-Class: should have the main class, just copy and paste
I explore other threads on stackoverflow, I explore the web but couldn't find the solution...
so I am posting it here with full "hello world" example.
I am using Eclipse 3.6/jdk 1.6 I write a one class using swt and want to export it as runnable file.
Here is how I am trying to do it:
File->Export->Java->Jar ...in the following dialogs I select to create new manifest and select my mainc class for entry point, export it and run it but get this error:
Could not find the main class co.My. Program will Exit
Here is my Manifest.mf file, with two empty lines at the end:
Manifest-Version: 1.0
Main-Class: co.My
In class I have method:
public static void main(String args[])
And here is download link for whole "hello world" project.
http://www.mediafire.com/?wl6mixmpatpglwh
If I remember good, there is in Eclipse also an option to create a Runnable Jar File.
This will help to solve the problem
I have a java project. I can run it through command prompt but can not able to run through Eclipse or NetBeans. When I run it, the error come main class is not found.
What can i do ?
How are you trying to run it in Eclipse and Netbeans? Basically you need to tell them which class to execute - which class has the main method in.
In Eclipse you can just go to the relevant class and hit Alt-Shift-X, J to launch it.
A few steps for eclipse
create a new project: Menu File/New/Project...
place your java source in the src folder of your project
through the context menu (right click the project name in navigator) you define the build path, and add required libraries.
now your code should be ready to run using the green (>) button
Is your project using libraries? I had the opposite problem where I could run my program in Netbeans and not from the jar (or command line) because the libraries were in my Netbeans folder and not my "distribution" folder.
EDIT: By libraries I mean third party libraries.
When you create a project in NetBeans, it will create a default Main class for you, complete with a main(String[] args) method. To access your code, just rename your class main method, copy it (and any dependnt classes into the project and change the package names to reflect the project name) and instantiate the class containing it in the default NetBeans main method and call the renamed main method e.g. if your class is called HelloWorld and the main method was renamed "hello" the call would look like:
HelloWorld hw = new HelloWorld();
hw.hello();
Simples :)