I have a java project: simple telegram bot. It worked while I didn't tried deploy it on Heroku. I did a backup for stable version, but Eclipse keeps showing me this ERROR. IDK what's wrong with it, I tried a lot of stuff, like what's the problem? I have src folder, classes also, I have main... Maybe problem in .gitignore file?
But I deleted from it *.class, it's still not working. Help
It's not a duplicate, because I'm workin in Eclipse and it worked earlier. Added my folder properties. I need short answer, not just a wiki of possible problems because it doesnt help.
Folder props
Screenshot error and folders
Your project configuration is very bizarre; you have class files in a directory named 'SRC'. It's hard to tell what you did to manage to create a project def this bizarre. Some ideas:
You've compiled this on the command line. You should probably look into build systems like maven or gradle to build your code. Even if not, use the -d switch on javac to ensure the class files end up in a directory named 'bin' or 'build'.
You've turned off eclipse's autocompile function. Turn it back on.
Right click your Point.java file (not Point.class) and pick 'run...' from the context menu. Assuming autocompile is on this will work.
Generally, use packages. Stuff in the default package is unrunnable in various scenarios. From what I can tell you're not in one of those 'default package is not runnable' scenarios but perhaps I'm missing something.
Related
I realize this may seem like a completely stupid question and this question is a "wall of text", but I'm feeling like I've gotten way out of my depth here and need some guidance. I've read several SO questions on this topic, but still can't seem to find one that addresses this particular situation. (please reference update(s) at the end of this post)
BACKGROUND
Our company has an application that was built in Java and released as an executable JAR package by a developer who passed away a couple of years ago. Since then, there has been minimal need for even looking at that code, let alone making any changes. That's been really good because I do my programming in VB.NET (Visual Studio) and, while I can read and make sense of Java code, I'm not proficient in actually writing/debugging that code.
However, a recent issue has come up that forced me to try to take a look at this Java code due to some internal changes in organization and data structure. I've looked in his "src\" directory and found older versions of his original code but wasn't able to find the most recent version anywhere. I found some code that made it possible for me to extract the JAR that's currently being used to a local directory on CodeProject (JarsVB), so I've been able to look over some of the .java files when trying to figure out what query is being used for some random operation. I don't know what tool(s) the original developer used to create the project/JAR, so I've installed the IntelliJ IDEA Community Edition 2018 as an IDE, and it's worked for me so far to simply view the code so I can understand a bit about what it's doing.
PROBLEM/GOALS
Unfortunately, now there is a need for me to make a change to the Java code and update the JAR, and this is where I can't seem to make heads or tails of what I need to do. I have my local copy of the code from the "unzipped" JAR containing all the .java and .class files (along with all the other resources), but I'm not sure how to go from that to modifying the code and recompiling the executable JAR.
So, my goals here are as follows:
(properly) Decompile the existing executable JAR. (If the JarsVB solution I mentioned above did what it was supposed to do, I should already have this part handled, but if there's a better, more "integrated" way of doing it, I'd be open to that as well.)
Modify one or more .java files. (I believe I can figure out the syntax well enough to get this part done.)
Debug/test my changes.
Recompile the changes into an updated executable JAR for release. (THIS is where I'm experiencing the most confusion.)
WHAT I'VE DONE
I've been looking at the documentation for IntelliJ to try to figure out how to make this all happen, but I feel like I'm missing stuff. I set my "Project Structure" settings to point to a specific folder, but I can't seem to get it to actually build anything in my specified path.
I went into one of the .java files and made/saved a small change to test, then went to the Build menu and tried all the building options available to me: "Build Project", "Build Module", and "Rebuild Project". Each time, the event log shows that "All files are up-to-date" (even though I changed one), so I go to my output directory to see what it built, but the folder is empty.
I looked at the IntelliJ documentation for Packaging a Module into a JAR File, which says to
On the main menu, choose Build | Build Artifact
But that option is disabled in my Build menu, and when I look in the Project Structure dialog, the Artifacts section is empty, so I try to add a new setting (Add -> JAR -> From modules with dependencies...), but I'm not sure how to properly set that up either.
I tried to select a Main Class from my classes/ directory, but it wouldn't actually accept any of the .class files I selected, so I just left it blank. Then, I did a search for a MANIFEST file, but couldn't find one anywhere so I left that blank as well. The Build menu option is enabled now, but when I tried to Build Artifact, again, I get nothing in my output directory. In fact, the only files I can find that have changed are in my local working directory. I'm just dumbfounded at this point.
FINAL THOUGHTS/QUESTIONS
I've tried to provide as much detail here as I could think of about all the things I've tried and gone through to get this JAR updated, but if there's a question about anything, please let me know. I'm not looking for a "handout" and I don't expect anyone to do this for me, but I'm also not wanting to become a Java developer just for the sake of making some minor changes to an application that will eventually be replaced by a .NET application. I simply am not familiar enough with the tools or Java development in general to know how to get to where I want to be from where I am.
My decompiled source files are in a totally separate directory from the original, production JAR file because, when I recompile this time, I want to completely recreate the JAR. Am I understanding the Java development process correctly in editing one of the .java files I got from decompiling with the JarsVB and then recompiling the JAR?
Thanks in advance for any assistance in finding the resources I need to accomplish these goals.
EDIT/UPDATE
So, looking at the link in the accepted answer in another SO question, How to build jars from IntelliJ properly?, I figured out at least one part of my issue: Leaving the Main Class setting of my Artifacts configuration blank was a problem. Since I hadn't been able to select a .class file and I wasn't sure how to correctly populate that field, I hadn't given the IDE enough information to operate correctly. I entered the namespace and class (namespace.class) I found in the class file that apparently defines the main method for the application, then set the path for the MANIFISET.MF file to my output directory and tried again to Build Artifact.
This time, at least, it DID produce a JAR in my defined output directory, but it's only 1KB in size. As stated above, the source files are in a completely separate directory from the original JAR file from which they were decompiled. The output directory, too, is completely separate from the location of the original JAR file. Do I need a copy of the original JAR file in the output path for recompiling to work correctly?
I'm making progress, but I'm sure I'm overlooking something "stupid" at this point that's primarily due to my unfamiliarity with the IDE and developing Java applications in general.
UPDATE 2
Looking at another SO question - how to create jar of java package in intelliJ idea - I learned that I have to individually add the necessary files for repackaging into the JAR. However, this brings up the question, what files do I add? The linked question identifies the .class files, but when I go look at the .class files in my working directory, none of those have been updated recently, so it looks like I'm still missing a step somewhere.
Another question this brings up is, are there certain conventions for Java development of which I need to be aware when preparing my environment? I have my output path set to a completely separate folder than any working or production code, so I'm wondering if something in that setup might potentially cause issues.
As I said before, I made a small change to one of the .java files, then tried both the Build Module and Rebuild Project options, but those are still telling me that "All files are up-to-date". Even so, I tried adding just the .class files from under my classes\ directory to my Artifact configuration and tried again to Build Artifact. I got a bit larger file (approx. 5MB), but when I try to execute the JAR, it just doesn't appear to do anything, let alone actually launch the application.
I tried again by adding the root folder of my local copy of the source adding everything the root folder contains. (yes, the directory probably needs some "spring cleaning", but that's for another day)
This time, I got a much larger file this time (approx. 21MB), so I thought I might have fixed the problem. Unfortunately, no such luck. The JAR still doesn't appear to execute.
For reference, the original JAR file from which the code was decompiled is approx. 59MB in size so, either IntelliJ is doing an incredible job with compression, or there's yet another step I haven't yet found. I'm sure this is all a matter of getting my IDE configured correctly, but I just can't seem to find the right combination of settings.
I have no idea why, but from today Eclipse doesn't compile .java files into .class. I press the "Run" button and Eclipse only tries to run the program rather then compiles it first, so i get this error all the time:
Exception in thread "main" java.lang.NoClassDefFoundError
open problems view from window -> show view -> problems, if there's any error, fix it
eclipse will reject to compile if there is any problems in your project
Close Project -> Open Project -> Clean -> Refresh
Hope it helps for someone else
This problem happens when "for some reasons" your project is corrupted and has a red icon near the project's name in Eclipse. The solution is to save the project's folder, delete the project in Eclipse, than create the project again in Eclipse coping all the previous files saved.
I ran into this problem with Eclipse Luna, for some reason the Java builder was missing from the project. Verify that in your .project file you have something like
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
You can also configure builders from Project Properties -> Builders
When I have had this exact same problem, its cause has always been the same and the solution has worked 100% of the time for me. It's caused by a missing jar file in the project's Java build path and it's indicated by a red exclamation point decoration on the project icon. To fix the problem, go to Project|Properties|Java Build Path, click on the Libraries tab and either remove or fix the path for all missing jar files. If your project is configured to rebuild automatically, it should start a build as soon as you apply your changes.
The eclipse needs to erase the output folder when building classes.
The folder is found on Project Properties -> Java Build Path -> Default Output Folder. It can differ from general output folder name found under Eclipse Preferences. If this output folder cannot be erased for some reason (for instance, on Windows, when a shell is opened on this location), the project is marked as corrupted (as Marco Micheli describes) and the classes then are not built.
You just need to make sure the output folder can be erased.
Yes I was facing this issue. Coz Eclipse cannot build the project for Build Path error. Check that your external jar files is not showing any error. Delete the Jar file which one is missing or which one is showing re color. delete that one. add a fresh one from the correct path or location. if all the error are gone. then in the project bin folder one class file will be created and then could not load main class error will be removed too.
there can be errors in your project, or other reasons like mentioned in above answers.
or you may be a fool like me
who moved the source code to other folder and not updated source path in project build properties. in this case it was not giving any error or class files too.
check that too.
goto
Project Properties -> Java Build Path -> Source
Add or Link new source folder location.
Do clean all projects ! This will erase all old class files, so eclipse is forced to generate them again.
Some times jars in the build path might be missing even though we are not using it. Since error is there, java files wont compile into classes.
Can check errors from problems view.
Either remove jars from build path or place the missing jars in the build path.
I had problem in eclipse for load module not found and no class file was getting created.
Solution: Go to Create New Project > Under JRE section Choose Use project Specific JRE.
Now Class files are created.
Please check if all the jars are there in your build path settings.
If any jar is missing this issue might come.
I had this problem, I tried the clean, the build manually, open, closing the project, deleting, and open, etc., nothing works, and after 4 hours I get a workaround what works for me.
Please, Make a RAR, ZIP, or copy from your entire project folder as a backup if it doesn't work and you mess around, OK, now:
Clean the Project. It cleaned all my class files from the output folder, but doesn't generate the class files after the clean with the building (but we already know that)
Delete the project (warning, make sure the Delete contents is not selected or your project will dissapear). For me it says something about that desynchronysation with code mix, and hibernate, blabla)
Close myEclipse
Restart your computer.
Open myEclipse
Import the project with the option "Projects from folder or Archive", not with the "existing projects into workspace" option.
Myeclipse start to build the class files, I don't know why, but works for me, I hope this helps somebody else.
Also ensure that there are no projects with fatal errors (projects with ! symbol over it) in the build path of the project which is not generating classes under the bin directory
Just restart your machine.
Its weird but it helps we had loads of problems this type in our company for unknown yet reason. Always restarting the machine helped.
It was normally encountered while trying to run Junit tests and it could not find a class even when the Run configuration was pointed to /bin.
I encountered a similar problem: previously compiled and running java files couldn't run anymore. Eclipse showed "couldn't find class xxxx". When I checked bin folder, the previous .class files were gone. That's why Eclipse couldn't run the files, NOT because of errors in files. I don't know why it can't just re-compile the file, and why the .class file gone missing in the first place.
But I found a solution:
Simply create a dummy java file in the same package (without doing anything just create), then run it. Then magically all previous .class files came back. And I can run those files as before.
Just Remove Your all Jars (Libraries) from the Build Path and refresh and add all jars and clean and build the project
This is probably a rare event but I declared a servlet with annotations and left off the "/" before the servlet mapping name. I spent over an hour chasing my tail, installing new servers, thinking I might even need to re-install my IDE and it was this simple error! Every time I tried to load any page from my Dynamic Web Project I got a 404 error. I could not even load a plain vanilla html page. There really needs to be better error logging with the IDE and Server interaction as there was zero indication of the error and my servlet was never called at the start of my web app. Hope this helps save someone else some frustration. Always name your servlet with a / slash like /myServlet never just myServlet.
I tried many different potential solutions: cleaning, rebuilding, removing, re importing, Update Maven Project and nothing. I still couldn't run my app from Eclipse. In my case the reason was that I was running Eclipse using openjdk-11 while my project was in Java 8. After I've reconfigured Eclipse to be ran from Java 8 everything started to work (in eclipse.ini).
-vm
/usr/lib/jvm/jdk1.8.0_202/bin
I'll explain my solution to this problem: "eclipse not compiling java files into class files". I'm using Eclipse version '2020-03 (4.15.0)'. I have a project that is dependent on a java project. For the dependent project, I was not able to export a jar file containing the compiles classes and resources. To be more precise, the exported jar file did not contain any class files. The output bin folder for the project is empty after doing a project build. In examining the console output when I tried to build all projects indicated that the build failed because the dependent project was missing. In looking at one of the log outputs, I saw something indicating that the build failed because some eclipse class was missing.
One of the things I tried was to do an eclipse update. Eclipse offered up the list of changes and I tried to apply them, but the update failed. I tried to update several times but they all failed. Looking more carefully at the offered up list of updates I noticed that one of the suggested update involved "deleting" Java Development Tools. That line had an warning indicating that the entire feature could not be deleted due to other dependencies and that only the non dependent features would be deleted. Doesn't that sound suspicious. Why was the update trying to delete Java Development Tools? My speculation is that something got deleted from the Java Development tool that was causing the build process to fail. The missing class I saw earlier also suspiciously sounds like it might be part of the Java Development Tools feature.
So what I did to solve the problem was to reinstall eclipse. I used the eclipse loader application to do the reinstall. (Note, I did not uninstall it first). After the reinstall, the dependent project was able to produce classes, and things once again worked as they should.
I certainly don't know how the eclipse release got into this compromised state, but in my situation the re-install of eclipse was the only way I could find to resolve the problem.
There would be the case : if you have opened project explorer in eclipse then it may not show you classes generated under /**/build/classes, in such case open Navigator view of that project and check build directory under the same project.
another problem. I have already placed my Jython.jar into what my computer recognizes as the Java CLASSPATH. This done, importing anything from Org.Python is not found by the compiler! Do I need to have the Jar in the same folder as the java code as well?
Thanks to anyone who replies :D
---------------------------------------------UPDATE-------------------------------------------
Still not working
within CLASSPATH I have Jython.jar.
within the location of my code and batch-compiler, I have the jar.
and I have typed "import org.python.util.*;" and nothing else are the beginning of my code
and it is still giving me errors :C
Make sure that you spelled the package correctly! In java the convention is to have packages with small letters: org.python
If you are using command line to compile and run your code then you will need to add the folder containing the given Jyhton.jar file.
For more help take a look at: http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html
If you are using an IDE:
Eclipse:
Got the Properties/Java Build Path/Libraries. From there you can add external Jars.
Netbeans:
Go to the projects Properties/Libraries/Compile tab and add all the JARs that you want to be included.
I'm trying to export a small program that I have made in Eclipse Indigo today to an executable, however, every time I do so one of two problems occur. The program uses one resource which I was hoping to put inside of the JAR but Eclipse will not put in the executable jar no matter which option I tick when I export or which folder the resource is in - the first problem!
The second problem is that whenever I tell eclipse to "Extract required libraries into generated JAR" I receive the following error when I double click on the executable Jar:
Could not find the main class: main.Launcher. Program will exit.
I don't suppose that the second problem is too much of an issue at the minute but the first one is extremely frustrating so I would appreciate any help or advice. Thanks in advance.
(Strangely, and even more frustrating, if I go through the same process with a project I made a while ago with a previous version of Eclipse it works perfectly.)
The folder structure of the project is as follows:
In the project folder there are the following directories .settings, bin, src as default. I have put the resource, which is a png in the bin folder but I have also tried it in the src folder.
Can you give some details?
What is the structure of your eclipse project?
Of what type is the resource?
More important where in the project structure resides the resource file?
Is the folder of that resource file included as a source folder ? (seems to be a prerequiste to get exported to the jar)
Is it copied over to the bin folder when the project is built?
Many Thanks
Michael
Update:
I have built a very simple java project 1 Java class with a main method and put a sample png file in the source folder. I refreshed the project to have the png visible in the project, then I cleaned the project to have it build again, then I ran the Main class inside eclipse. This will give you a run configuration when exporting throught the wizard. Thereafter I exported the complete project as "runnable jar", selected the run configuration and selected "Copy required libraries in a sub-folder next to the generated JAR". The png was included and the Main class was found. The executable JAR could be executed.
(Environment: Eclipse Indigo R1, Ubuntu, JDK 6)
You might want to play through the complete sequence of steps I went through. Maybe eclipse just did not pick up a file or other updates.
regards, Mike
First of all, I would like to thank Mike (marksml) for being so helpful and attempting to provide a solution for my problem. Unfortunately, his answer did not work for me!
I began to look at all of my previous projects and noticed that the one I was having trouble with was the odd one out (because it was the only one that didn't work) and the factor that made it the odd one out, I found to be the JRE system library version. The project was using the JavaSE-1.7 library but when I changed it to the JavaSE-1.6 like my other projects were using it miraculously worked and exported flawlessly! I'm still curious as to why this is the case, but at least I have it working now...
With thanks and kind regards, Andy
Ok I'm completely googled-out.
I have a few java projects in my eclipse workspace (about 25). Most projects use linked source folders.
When I rename a class in Project1, the references to that class in the other projects are not updated. The references within the project are updated just fine. The net result is compilation errors on the next automatic recompile.
I'm using Eclipse 3.5.1, but the same behavior was shown by 3.4.0 and 3.4.2
Any ideas about how to fix this?
My current plan - after googling for 20 minutes - is to write a script to convert the linked source folders to be OS links (I'm on linux) in the project folders themselves. So then I'm no longer using linked source folders.
Like Philippe Faes said, it works fine if your projects are set as a dependency on each other. Make sure that your project's build path are set up that way.
IMHO linked folders are for external files, not for another projects.
Another problem is that if you are just referencing a jar as a dependency (ie, on the project's class path), eclipse will not be able to know that the jar was build based on another project's source thus will not refactor properly.
Try to ask your colleagues for the eclipse project files (.project and .classpath) and edit the files if you need, then check if your refactor still doesn't work. I am guessing that your project is set up differently than your colleagues.
Cross-project renames work just fine if your projects depend on each other.
What exactly do you mean with linked source folders: do you link to the same source folder more than once?
This is a shot in the dark, but make sure that your project is a Java project. I am not sure if other project types (like the generic Project) might not refactor properly. I have never seen this problem before and it has always worked as expected for me...