I am new to JAVA. I am using Eclipse 3.7 with WindowBuilder Pro installed. I have made a JFrame SearchFrame.java using the GUI in the package SearchPackage.
But when I try to run this file it gives me the error:
Error: Could not find or load main class SearchPackage.SearchFrame
I looked into my output folder DatabaseSearch/bin and there is no .class file in it. Please suggest me what should I do to rectify this. Thanks in advance.
This worked for me
Try to:
Right click on the Project in PackageExplorer -> Properties -> Java Build Path
Select Order and Export tab, and move the source package that contains the main class to the top, by selecting the correct package and pressing the Up button.
Click right at project at Package Explorer the compile and run/
Automatic builds may be disabled preventing the class file from being generated. Right click on
DatabaseSearch > Build Project
to use the manual build feature
Please clear all the build errors if any in your project. May be the project has some missing jars as a result its not able to form .class file out of your java.
Related
I just developed an application in java and I need to handover the code partially.
So, what is I want to achieve is
I've a class manageTask.Java at com.project.users.manageTask and As I need to handover the source code, excluding one class file, I want to create a jar file for that class and use with same project instead of that manageTask.Java
Somebody Please guide
Edit:
IDE: Eclipse
And there are a couple of external dependent jar for manageTask.Java
Firstly your class name should be ManageTask.Java and not manageTask.Java.
To export jar, right click your project in eclipse, select Export int he popup menu and then choose jar int he wizard that opens. After that you should be able to find what you need.
What is this ant build error in eclipse?
When I click the Ant Build I have the error message shown below.
Build failed
Reason: Unable to find an Ant file to run.
Could you please help me solve it?
Quoting from here
Create a new project in Eclipse
After the project is created, look in the package explorer window pane on the left and right click on the src folder.
There are two methods for the next step, you could either add a New > Class, and then copy and paste everything from your old java file to the new class (make sure the class name is the same), or the better route would be to Import.
After clicking Import, select File System under the general folder. Click Next.
Browse for the java folder where your source files are located. Once you click ok, it will add all of the source files to the right pane.
Select which files you want to add and click Finish.
Now if you look at your Package Explorer window you should see the source files. Now just compile them, and the error shouldn't appear and you can run them just like before.
This question already has answers here:
Eclipse "Error: Could not find or load main class"
(61 answers)
Closed 9 years ago.
Have Googled extensively on this error, but I can't seem to fix the problem. I've written a basic java program in Eclipse Juno, as follows:
public class HelloWorld {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("Hello Eclipse!");
}
}
After clicking Run, I get: "Error: Could not find or load main class HelloWorld". This error message applies to all my other projects in the same workspace. I've tried switching workspaces but the error still appears.
I'm on Windows 7 64-bit. Any help would be appreciated!
This just happened to me today after updating my JRE. I cleaned the project and it started working again.
Project -> Clean will remove any existing class files and completely rebuild the project. There's more information on Eclipse's clean function here.
I just ran into that problem. The cause... not sure. It only happened to me after I added a new JVM.
My solution:
went to run configurations: - run->run configurations
In the Classpath tab:
Select Advanced
Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
I deleted a jar file from the bin directory. Right click on your project - Properties then Libraries tab. There was a red flag in there. I removed the jar file from the Libraries and it worked.
It seems that the class is not compiled by Eclipse.
Few pointers could be-
Check if the .class file exists in your output folder.To know your output folder Right Click on Project->Properties->Java Build Path(Check at bottom).
Check if Project->build Automatically is checked in the menu.
Check if the HelloWorld class is in src folder or not.Right Click on Project->Properties->Java Build Path(Check source tab).
Same Problem occur with me.I went to Project > Properties > Java BuildPath.
There In order of export , I moved up my java/main to the top priority.
that's because you guys created the class one time with the main method & after that may be you have been deleted that form or workplace & still some of the files exist ,i will suggest you to create that form or workspace again & then delete it by clicking on it completely,then after that if you created the some class like Runner class try to run it again.
This happened to me. I noticed that someone said I have to create an entire new WORKSHOP! Why? Because I installed a newer JRE version and that won't allow other previous versions to run on it. So all those old files I have become useless in a way. Not really, Just copy and paste it to new class and change it to an unused class name.
if your package name is same with your class name this problem will occur.
I've got a project in which I'm using Java+Scala+Slick2D.
The project itself runs well when launched from within eclipse. But when I try to make a jar file, it just refuses to work. Here's the error I keep getting when trying to export it as a Runnable jar:
And if I try to export into just a Jar file, it's unable to find the Main Class:
There is, of course, a main class in game.TicTacGame. But it refuses to acknowledge it. I tried creating an executable with a simple Hello World project and it worked fine. It even detects the main class. Why is Eclipse not detecting the main class in this case?
PS: I've also tried extracting the .jar file created, editing the manifest.mf file to add the Main-Class: game.TicTacGame, enter two new lines and recreate the jar. Then it gives me a corrupted jar file error.
I'm at my wits end and would appreciate any help in this regard. I'm using Windows 7 x64 with Eclipse Juno, Java 1.7 and Scala 2.10
Edit: The Main class is in Java
Okay, I got it to work. Apparently, all I needed to do was restart eclipse. And then magically, it started detecting the Main class:
But the jar started giving me noClassDefFound errors for the Slick2d, LWJGL and other libraries. That's where JarSplice came to my rescue. I exported the project as before, with all the libraries and resources.
Then, I fired up JarSplice and added everything as follows:
Go to "Add Jars" and add the project.jar just created through eclipse, add lwjgl.jar, slick.jar and scala-library.jar. lwjgl and slick should be in your project lib folder where you would have imported them. scala-library should be available wherever it says it is. Make sure you add that as well
Next, when I tried to "Add Natives" it kept giving me "Duplicate library" error. So I removed them all and kept it empty.
Next in "Main Class", I entered the path to the main class i.e. game.TicTacGame
Finally, "Create Fat Jar". And it works perfectly :)
I just encountered the same problem, and here is how I solved it:
Open "Run As" --> "Run Configuration" on the project you want to export
Click "Search" for Eclipse to refresh the list of main class
Then export Runnable JAR file again, and everything goes smoothly.
The most easiest method is run the java file once and automatically the file appears in the list.Even i was facing the error but it was solved by using this simple method.
I recently figured a better way to do this using 'Runnable jar export' which might help you. In order for your main method to be listed in that list, you need to add the main method to the Run Configuration list.
This way it's simpler to create a runnable jar especially if you want to do it repeatedly.
Well, got the same Problem and solved it by selecting my GUI to export and not the whole Project.
I had this problem with Eclipse version 2019-03 (4.11.0) and compiler JaveSE-11. Choosing the right launch configuration and exporting runnable jar failed over and over again with an error
Could not find main method from given launch configuration
I've tried to restart Eclipse and do a clean build, but it didn't help.
In the end, I found a workaround to go into the generated jar file (I've used 7zip) and change META-INF/MANIFEST.MF file. The file should have something like this inside:
Manifest-Version: 1.0
Class-Path: .
Main-Class: <package name>.<class name>
Hope it helps someone.
I faced the same issue and in my case I found that "launch configuration" was incorrect in Runnable Jar file specification dialog. Somehow, eclipse was automatically taking it. The "Launch configuration" should be java file which has main method. Basically, it is filename-package.
The moment I changed my "launch configuration", I was able to create Jar file without any error.
I had the same issue. To overcome this issue, you need to close all opened files and open a single java class file that has the main() method. Then export it from eclipse and works fine.
I've got a copy of a java package, with example implementation. The package is in a structure called com.java.project (folders, containing myriads of .java files) and there's also a few example files (example1.java, example2.java)
The example files have 'import com.java.project' calls in them, that's all well and good. However, I can't seem to work out how to get Eclipse finding the package contents (currently returns "Type not found" for any calls to the project objects.
I've tried placing the com structure in the same level as my example1.java, but that doesn't work. I have read that I need to compile the package into a .jar to get it to work w/Eclipse, but that doesn't seem to want to behave, none of the files compile.
In Eclipse you can right click on the Project Explorer and select "New -> Java Project"
Then you can import your java files by right clicking your project, selecting import from file system. If the class file shows an error, open the class file, the class name should have red curly braces, click on the error tick mark and Eclipse will give you an option to move the file to the correct package which in turn creates the folder structure for you.
1.Can you do a check on the build path of your Java project? (Right-click the project -> Properties -> Java Build Path -> Source tab), and see if the root folder contains the code is properly specified here.
2.Maybe a Project->Clean will help as well.
Hii,
Just Create a new project with File -> New menu
you need to open Java Perspective and there you will find a package named "src" you need to copy your "com" directory and paste it at the src folder.
I hope this will work for you.