Dear All,
I feel like this problem is based more on my lack of understanding of error messages and eclipse rather than programming.
In part of my homework assignment I was asked to rename a template folder, its files, and change class names/packages in order to start the assignment and create my own interactive game inspired by the code/game given. After going to search>search... and replacing the previous name to the new name inside every file, then refactoring every folder/file that was based on the previous name I am no longer able to run my program without seeing "Could not find main class: BearDemoJava". BearDemoJava does exist, though.
I was given a more specific error from the console tab of eclipse:
java.lang.NoClassDefFoundError: BearDemoJava
Caused by: java.lang.ClassNotFoundException: BearDemoJava
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
When I clicked on the link: java.lang.ClassNotFoundException I was alerted that an "Archive does not exist at "C:\Users\Me\.m2\repository\com\sun\tools\1.6\tools-1.6.jar". I went to look for it in the location .m2\repository\com... and it's not there (or not visible) but it is in C:\Program Files\Java\jdk1.6.0_24\lib (or at least tools.jar is there). I'm not really sure what I have to do to get it to work, but I attempted to import>maven>install or deploy an artifact to a maven repository, upon the new window I browsed for the artifact tools.jar file, set the group id as com.sun, artifact id as tools, version as 1.6.0 (at least I think it's that) with no avail.
I also tried to re-run the solution program of the first half of the assignment with the same issue, but for other types of files it does not have that problem. Is there also a possible issue with paths that might suddenly cause these issues? I have installed gwt and maven. I'm using eclipse: indigo, if that matters at all.
I looked up the common causes for ClassNotFoundException, but apparently there is also a distinction between NoClassDefFoundError which I did not understand upon reading it and whether or not I had one or the other.
I'm sure there's a simple solution, I just don't know what I'm doing.
ClassNotFoundException
Page 1 of 18 Replies - 719 Views - Last Post: 30 March 2012 - 04:19 AM
Replies To: ClassNotFoundException
#2
Re: ClassNotFoundException
Posted 28 March 2012 - 05:09 AM
Have you tried cleaning your project? If not, you should click Project->Clean and then Project->Build. If, after that, it doesn't work, please post again.
#3
Re: ClassNotFoundException
Posted 28 March 2012 - 05:30 AM
Yes, I've done the clean and build part and I've also restarted eclipse. The same error shows up, I want to add that when I tried to import, it was still looking for that .jar file in the same directory regardless.
#4
Re: ClassNotFoundException
Posted 28 March 2012 - 01:47 PM
Hikaroshi, on 28 March 2012 - 07:47 AM, said:
After going to search>search... and replacing the previous name to the new name inside every file, then refactoring every folder/file that was based on the previous name
You shouldn't have done that
You should have Cut & Paste (<ctrl>C <ctrl>V) the files you wanted to rename, Eclipse would have prompted you for a new name. After you had entered the new name, it would have save the file under that name changing all the references inside the file for you.
Then you could have created a new package and drag the files there. Eclipse would have edited your files to put the good package statement into them.
Now your project data is completly out of synch with the file system.
The easiest way to fix that, is to copy all your .java files in a completly new directory structure. Delete completly your Eclipse project and its subdirectories.
Create your project, and then File->Import->FileSystem
Good luck
#5
Re: ClassNotFoundException
Posted 28 March 2012 - 05:22 PM
I have yet to do what you have suggested, but before I do so I have some questions.
Is this why the solution file is also having errors when I try to run it as a java application, because of the refactoring issue from the other project set? Meaning, is it common for this to affect other similar typed projects?
Since I had imported it as an existing maven project (and still have the skeleton file zip), couldn't I just delete project and its subdirectories (the one I'm attempting to do, not the solution), then re-import as an existing maven the skeleton? Then I would end up starting 'fresh' and then would be able to ctrl c+ ctrl + v the files that need to be renamed, and do a search and replace for variables that also should be renamed (ex: solutionGameTimer to myGameTimer), would that work? I'm also assuming your advice to copy the .java files into a new directory structure (I think you mean src, src/main/java, etc) is so that I won't have to re-create what I have already added to the program?
Is this why the solution file is also having errors when I try to run it as a java application, because of the refactoring issue from the other project set? Meaning, is it common for this to affect other similar typed projects?
Since I had imported it as an existing maven project (and still have the skeleton file zip), couldn't I just delete project and its subdirectories (the one I'm attempting to do, not the solution), then re-import as an existing maven the skeleton? Then I would end up starting 'fresh' and then would be able to ctrl c+ ctrl + v the files that need to be renamed, and do a search and replace for variables that also should be renamed (ex: solutionGameTimer to myGameTimer), would that work? I'm also assuming your advice to copy the .java files into a new directory structure (I think you mean src, src/main/java, etc) is so that I won't have to re-create what I have already added to the program?
#6
Re: ClassNotFoundException
Posted 28 March 2012 - 08:51 PM
Hikaroshi, on 28 March 2012 - 08:22 PM, said:
Is this why the solution file is also having errors when I try to run it as a java application, because of the refactoring issue from the other project set? Meaning, is it common for this to affect other similar typed projects?
Actually your project should not even compile
Hikaroshi, on 28 March 2012 - 08:22 PM, said:
Since I had imported it as an existing maven project (and still have the skeleton file zip), couldn't I just delete project and its subdirectories (the one I'm attempting to do, not the solution), then re-import as an existing maven the skeleton?
This is what I would do
Hikaroshi, on 28 March 2012 - 08:22 PM, said:
Then I would end up starting 'fresh' and then would be able to ctrl c+ ctrl + v the files that need to be renamed, and do a search and replace for variables that also should be renamed (ex: solutionGameTimer to myGameTimer), would that work?
It should
Hikaroshi, on 28 March 2012 - 08:22 PM, said:
I'm also assuming your advice to copy the .java files into a new directory structure (I think you mean src, src/main/java, etc) is so that I won't have to re-create what I have already added to the program?
Eclipse should handle that for you. If your .java and .class are not in the same directory yes it should be /src
#7
Re: ClassNotFoundException
Posted 29 March 2012 - 04:21 PM
Solved the problem, I deleted my project and re-imported the skeleton. From there I had to refactor the folders (because copy and paste didn't work for them, but they did for files). I then did search and replace, but after I finished renaming everything I still had the same issue.
So, I found something on my pom.xml tools.jar artifact not found error here http://maven.apache....-jar-dependency
Still didn't work, but apparently once I changed the section between the <systempath></systempath> brackets to the exact directory of my tools.jar folder ex: C:\Program Files\Java\jdk1.6.0_24\lib\tools.jar I didn't have that issue anymore once I cleaned and built the project, closed the project and eclipse and re-started eclipse again... Interesting, I don't understand where this error came from if I didn't have it before.
Question though:
I saw my teacher on behalf of my issue and she told me that I must have had an issue with my path, then again the tutor also assumed so a few days ago when I had this problem.
I found out after searching for the problem more thoroughly it (hopefully) does not have anything to do with my paths, though I was told by the teacher to do %path% in windows cmd prompt and apparently it's abnormal for your path to start off as C:\Windows\System32 if when you changed or added to the path in the environment variables section of system properties to something like: %JRE_HOME%\bin;%JAVA_HOME%\bin;%MVN_HOME%\bin;%PATH%;C:\Program Files\java\jdk1.6.0_24\bin\;C:\Program Files\SSH Communications Security\SSH Secure Shell
(note jre, maven, and jdk1.6.0_24), is she right? This is the first time I've ever learned about paths and apparently they're pretty integral in java. I remember seeing instructions for some freeware programs that stated 'change your path to _____' and I never understood it. Can someone explain the use of paths or give me a link without all the jargon (or at least explained jargon).
So, I found something on my pom.xml tools.jar artifact not found error here http://maven.apache....-jar-dependency
Still didn't work, but apparently once I changed the section between the <systempath></systempath> brackets to the exact directory of my tools.jar folder ex: C:\Program Files\Java\jdk1.6.0_24\lib\tools.jar I didn't have that issue anymore once I cleaned and built the project, closed the project and eclipse and re-started eclipse again... Interesting, I don't understand where this error came from if I didn't have it before.
Question though:
I saw my teacher on behalf of my issue and she told me that I must have had an issue with my path, then again the tutor also assumed so a few days ago when I had this problem.
I found out after searching for the problem more thoroughly it (hopefully) does not have anything to do with my paths, though I was told by the teacher to do %path% in windows cmd prompt and apparently it's abnormal for your path to start off as C:\Windows\System32 if when you changed or added to the path in the environment variables section of system properties to something like: %JRE_HOME%\bin;%JAVA_HOME%\bin;%MVN_HOME%\bin;%PATH%;C:\Program Files\java\jdk1.6.0_24\bin\;C:\Program Files\SSH Communications Security\SSH Secure Shell
(note jre, maven, and jdk1.6.0_24), is she right? This is the first time I've ever learned about paths and apparently they're pretty integral in java. I remember seeing instructions for some freeware programs that stated 'change your path to _____' and I never understood it. Can someone explain the use of paths or give me a link without all the jargon (or at least explained jargon).
#8
Re: ClassNotFoundException
Posted 29 March 2012 - 08:55 PM
A path is simply a list of directories that will be searched to find a program when you do not specify its patch
At the console you can type
> "\\Program Files\java\jre1.6\bin\java" MyClass
or simply
> java MyClass
in the second case, all the directories specified in the PATH varible will be searched until java.exe is found
At the console you can type
> "\\Program Files\java\jre1.6\bin\java" MyClass
or simply
> java MyClass
in the second case, all the directories specified in the PATH varible will be searched until java.exe is found
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|