How to resolve classes with source src-jar library in Eclipse? - java

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.

Related

(file) not found in build path

I downloaded and decompiled a jar file for a plugin for minecraft, and I added it to eclipse by creating a new java project, Import > archive file > [decompiled jar.zip]
That results in this:
After that, I changed a single line of code, then I tryed to export it.
However, when I attempt to export it, I get this message:
I have no idea what I'm supposed to do to fix this. Please help.
de (and not only its content) and the other folders as well must be included in the source folder.
Try to move all the folders (except META-INF) and files to src and then create your jar.
(Note that there would be a warning if you didn't exclude META-INF because it is generated you would override it but it wouldn't prevent generating the jar).
NOTE
I don't know what you will do later with this but you'd better use Maven, Gradle (or even Ant) to manage you future jar builds.

why xml files in eclipse project's source directory is copied to target/classes directory?

I have xml files in eclipse project's source directory, like:
src/java/main/com/xx/zz.xml
1.When using eclise to build automatically, xml files are copied to target/classes.
2.When using 'mvn complie', xml files are not copied to target/classes.
For the second case, I found this:why xml files in eclipse project's source directory is not copied to target/classes directory?.
but for the first case, I cannot find any document.
Can someone explain it for me ?
Thanks!
Eclipse works quite a bit differently than standalone Maven. Maven uses javac from JDK. By default javac only processes .java files and generates .class files in the same directory as .java sources. Maven asks it to generate classes in a separate directory and javac only moves .class files there.
The reason for this is that javac gives you more freedom in organizing your source files than most developers use. For instance javac does not care if your class is located in a folder structure that mimics declared packages. You can put a module together by putting several .java files along with some other files like .properties or .xml in the same folder. Your .java files can have different package declarations. For instance you can have files A.java:
package aaa.bbb;
class A {}
and B.java:
package zzz.uuu;
class B {}
If you ask javac to put classes in a target directory, it will create necessary subfolders for .class files, that will resemble the package structure. However it cannot do so for properties and xml files, because they do not contain package declarations. Such 'resource' management is left for the build tool.
Maven expects that you put such resources in another source folder (resources). They will be copied to generated package structure, so you should match it in resource folder. This is why it does not copy non-java files in source folders.
Eclipse expects you to put even .java files in a target package structure and complains if your package declaration does not reflect relative path of the file. This is where you have less freedom compared to bare javac. Thanks to this rule it can copy resources along with .class files and does not need another 'resource' folder.
You can configure Eclipse to use source folder as output folder. Eclipse will not touch resources in this case.
If you right click on the project in eclipse and select 'properties', then Java Build Path you see an input at the bottom for the Default Build Path, which should be target/classes. The source folders are shown in the main dialogue. If you click on the source folders then you can modify each, to exclude the xml files (if that is what you want to do).
Maven will include your xml files automatically if you put them in src/main/resources.
If you don't want to have xml files in build directory, you need to configure eclipse excluded source file types -
right-click on the file in the Project Explorer, choose Resource Configurations > Exclude from Build and choose the configurations that you want.

getting error while importing .class files in a project in eclipse

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.

How to import a jar file into eclipse as a project to use source code of classes of that jar

I have one jar file. I want to see the source code of classes of this jar file and i need to use source code of this jar file. Is there any option to view and use that jar file source code?
Is there any option in eclipse to extract jar file and to see the source code of that jar file?
if you add a jar as dependency to your project, you can also link sourcecode to it.
Rightclick on project->Build Path->Configure Buildpath. There, choose the jar that you linked into your project, extend it and under "source attachments", you can add the jar that contains the sources of this specific jar
You can add the JAR file with the byte code and attach the source JAR as well. You can't do without the first; the second is optional.
It's easy to do in IntelliJ; I'm not sure about the steps in Eclipse.
Right click on Your procjet. Chose properties.
Select Libraries
Chose Your jar
Profit
The JAR file you are refering too may not have source code attached.
Usually, when downloading third party library you can download JARs with byte-code and source code separetredly. The best way to check is to simply extract JAR file (with ZIP extracting tool) and check whether you have source there. If so, you can do the following:
1. Add the JAR to your Eclipse project (just drag it there and choose whether you want to copy or link to the JAR).
2. Whenever you are opening class file that does not come with source-code and you are shown "Source not found" page - just press button "Attach Source.." and find your JAR file with source code.
[EDIT] use JD-GUI to extract source code (*.java files) from *.class files contained in JAR file.
In my case I had in Java Build Path Source attachment with meaningful path (not NONE), but file itself was absent in this place. I configure project to Maven nature. And then from Maven make Download sources - file -source.jar appears.
Yes,You can see the source code of all the files those are added in your jar file.first you have to add jar file same as shown by the Marcin Szymczak. and after that click on "Referenced library". After that click on Your jar.and you can check all the classes source code.In my case jar file-Hackerrank.jar and you can see source code of classes:
This applies to plugin jars (if that is your case):
Ensure to put the jar into your target platform folder
Refresh your target platform: Window -> Preferences -> Target Platform -> Select your current target -> Edit -> Finish -> Reload -> Ok
Open the "Plug-ins" view: Window -> Show view -> Plug-ins
In that view, locate the new plugin jar: right click and Import As -> Source Project.
You will have it as a plugin project in your workspace.

Java - Problem with the classpath on Eclipse

I'm trying to recompile a project I've been working on and I keep getting an error message when trying to load a property file:
The system cannot find the path specified.
I guess this has to do with the classpath. But I've added the path to the file in Properties-> Java build path-> Libraries (external class).
I also checked the .classpath file generated by eclipse, and the path is really there!
Why isn't Eclipse looking at the right path?
There 2 different classpaths, build classpath and runtime classpath. The one you are setting is the build classpath.
Check your runtime classpath by going to Run -> Run Configurations and select your application configuration. Check the classpath setting there.
There is another workaround for this also. Eclipse by default will include your output folder (usually named bin) in your classpath. Typically anything that are not compilable in src folder will be copied to bin as is. I assumed your property file is not located in src folder. What you can do is to open your project property and add the folder where your property is located into Java Buld Path -> Source (tab). This way eclipse will copy the content of that folder into bin and will be in the classpath.
There are several ways to read a property file:
Have it in the current working directory (the one cd'ed to). You can do this in the Eclipse launch configuration. (Run -> Run...)
Include it in your application, by having it in a source folder. You then need to read it in through a class loader to be able to get it always (when jarred up, through Java Web Start, etc).
Double check if the property file or its directory is in the excluded list of the project Source. If it is remove the exclusion filter and try recompiling.

Categories