I've tried opening class file in eclipse that I have copied pasted from the jar that I have imported into the project and am receiving this as first error:
org.eclipse.core.runtime.CoreException: The class file is not on the classpath.
Evidently I have included the class file incorrectly into my project. I need to use this class file to access Java applet. Suggestions please
Rather than trying to copy the class file into your project, you should reference the Jar that the class you want is part of.
Go to: project->properties->java build path->libraries tab->add external jars...
Right Click on project > Maven > Update Project
worked for me :)
Related
I made a java project. It has dependencies. I have the class files. So what i did i made a classes folder and put all the class files in that folder and then add that folder to my project. All the dependencies have been removed. But i think class files also have anonymous classes. SO i am getting error at that line. Here is my project structure
The error that i am getting is
The project was not built since its build path is incomplete. Cannot find the class file for com.suprema.ufe33.UFScannerClass$UFS_SCANNER_PROC. Fix the build path then try building this project
The type com.suprema.ufe33.UFScannerClass$UFS_SCANNER_PROC cannot be resolved. It is indirectly referenced from required .class files
How can i solve this error ?
Thanks
I think the problem is that the folder structure you created in the classes/ folder does not exactly match the package name of the classes you are referencing. Check the capitalization of ufe33.
By the way, it's usually better/easier to use a JAR of such dependencies instead of folders of .class files.
I solved the issue. Yes E-Riz is right that folder structure is not right. It should be small ufe33. Also i created the jar. What i did is I ran this command where i copy all the four class files.
D:\jars>jar cf myjar.jar com\suprema\ufe33*.class
It made the jar file myjar.jar. Then i simply add this jar to my eclipse project class path and the problem solved.
I have two jar files - jar1 and jar2. Both of them are located in C:\Eclipse projects\ and I have added the paths to both of them to the Environment Variable CLASSPATH as follows
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Eclipse projects\stdlib.jar;C:\Eclipse projects\algs4.jar
the ".;" at the beginning were there so I left them. Then I added the jars to the project from their location C:\Eclipse projects\ and they showed up as Referenced Libraries. However, when I try to instantiate a class from the jars it does not recognize it. I am also not able to import the jar (import jar1).
After I tried adding a lib folder in the project and I added the jars there. After, I added them as references once again (so not they appear twice in the Referenced Libraries), however, I am still not able to use the inner classes. Any help will be much appreciated.
UPDATE:
Something must be wrong on my end. None of the suggestions worked for me. Here is a video with all the steps: screencast.com/t/gC81YzCsLY0e
RESOLUTION In my project I had a package called TestProject and it seems that those jars needed a default package. After deleting the TestProject package and using a defaultPackage everything worked correctly after adding external JARs as explained below.
I've got the same problem as you today, And no answer from the web can solve it. However, I fixed it at last.
In fact, there is nothing wrong with the setup, it is right to import those jars through "Add External JARs". The real problem is the location/package of you java code. I found that you have to put your .java file in the default package. For example, you will get errors if you put your java code in a package like com.xxx.yyy.ccc, below is an image which shows the right location/package you should use(see WTF.java). After doing that, you program will be able to run.
However, that is how i fixed my problem, i'm not sure that could work for everyone..
In eclipse, right click on a project->Propeties->Java Build Path->Add External JARs (Add JARs if the jar is inside the project's folder) and then choose your jar file.
From now you can use the inner classes of the jars you added. Eclipse will import them when you'll start using them.
Why don't you use these two JARs—— stdlib-package.jar and algs4-package.jar.
And below the code page(http://algs4.cs.princeton.edu/code/)
Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar or algs4.jar. Why not?
A. The libraries in stdlib.jar and algs4.jar are in the "default" package. In Java, you can't access classes in the default package from a named package. If you need to use our libraries with a named package, you can use these package versions: stdlib-package.jar and algs4-package.jar.
Warning: if you are taking Princeton COS 226 or Coursera, Algorithms, Part I or II, you must use the default package verison of our libraries to facilitate grading.
Showing my test success:
If you have a folder with your JAR files into the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add JARs, search and select the JARs files you want to use.
If you have yours JAR files any other place outside the project:
Right click on the project>Build Path>Configure Build Path;
At the tab "Libraries" click on Add External JARs, search and select the JARs files you want to use.
I am taking a course on Coursera and as part of a quiz I am supposed to download their xyz.class and run it. I want to do it in eclipse as all of jar files are added in eclipse and I dont want to modify the class path of system as it is very untidy.
But I dont know how to run a external .class file through?Can anyone help me with that?
Why do you want to run it in Eclipse ?
java classname
souhld do the trick. You can't use Eclipse to run an external class file with a main method without creatin a java project with this class in its class path.
Right-click your Eclipse project, Build Path, Configure Build Path, Libraries, Add (External?) Class Folder.
Just run
java xyz
eclipse might not required.
If you want to really work out through the eclipse then refer How do I include .class files in my project in Eclipse? (Java) answer.
There is another way of approach without using eclipse.
Approach is by creating a executable jar file and by including all required libraries & xyz.class.
Right click on the class file from the Package Explorer -> Run.
goto file >> new project >> Import>> add executable jar files >> select your path where you have stored your .class files>> check include in work place
apply>> ok >>>>>>>>>>>>>>>>>>>>Done
I have added this jar file to my project's build path under "libraries":
http://sunet.dl.sourceforge.net/project/jeplite/jeplite/jeplite-0.8.7/jeplite-0.8.7a-src.jar
and cannot get Eclipse to resolve ANY of the included classes.
Packages are visible, but no classes.
Error message is:
"JEP cannot be resolved to a type"
In eclipse, it should be on the build path if its a source tree .... Remember , a jar is just a glorified zip file, so be sure that the binaries are actually in your jar file. The steps to test are
1) unzip the jar file
2) if its source : then either try adding it to your build path, or just directly import the source folders into your project
3) if you see class files in the jar, then it should be okay to add them to "libraries"
This is only a jar containing the source code. You need a jar with the compiled classes in it. Try the jeplite-0.8.7a-bin.jar.
I have the gdata-calendar-2.0.jar file, but I get the error "CalendarService class not found".
CalendarService myService = new CalendarService("example");
Have you included the library in your project? You should place it in the libs\ folder of your project, and then in Eclipse you need to add it to the Java Build path. Right click on the project, goto properties, Java Build Path, then pick the libraries tab and add your Jar.