I am using Eclipse neon.
I have a JAR filed stored in my lib directory. I have a class that uses that jar file but when I do a ctrl + click on one of the classes in that jar then I get a source not found. I am trying to look at the code of that class.
This isn't a duplicate question because the others questions similar to this relates to debugging.
Related
I'm working in a project environment Eclipse Luna Service Release 2 (4.4.2) in which I am using classes imported from some libraries. Currently I have to build a class diagram of the work done so far and to do that, I'm using the "ObjectAid Explorer Eclipse UML plugin" without problems. Unfortunately I can not create it anyway integrating relationships to classes imported and then I was planning to re-create them in a package so that you can create this class diagram. How can I read the code of a class imported from a jar library?
Thanks so much !
If you want to read just the method signatures, inside Eclipse from Project Explorer, navigate where the .jar is located and expand it; you will be able to view the classes and their methods.
If however you want to read the entire code of every class, you need the .jar that attaches the sources on it. Developers usually package a Java Project without the sources files and create separate JARs that contain them. Look for the a JAR named <library_name>-src.jar.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have read many sites and then decided to ask this question on stackoverflow, question is pretty basic
What is .classpath file? Is this file related to the Java project or Eclipse?
Some people think that this file related to Eclipse and some thinks that it is related to project?
.class files are related to Java.
You write your code in java, it is compiled by javac into bytecode. The bytecode is stored in the .class files, and further interpreted by the Java virtual machine (JVM).
About .classpath on Wikipedia:
Similar to the classic dynamic loading behavior, when executing Java programs, the Java Virtual Machine finds and loads classes lazily (it loads the bytecode of a class only when this class is first used). The .classpath tells Java where to look in the file-system for files defining these classes.
So the .classpath mechanism is related to Java, and is handled by eclipse thanks to the .classpath file.
Hope it helps :)
It's java bytecode in .class file. Whenever you compile the javacode, you will get .class file per java class. Behind the scenes, Eclipse incrementally does compile your java code in the project and hence you don't end up manually compiling our java code.
The .classpath file is Eclipse's way to keep track of a project's classpath and other build related settings. If you right click on your project and go to Java Build Path, those are the things that are saved in the .classpath file.
The .classpath file is maintained by Eclipse's JDT . JDT holds multiple such "meta" files in the project (see the .settings directory inside the project); the .classpath file is just one of them. Specifically, the .classpath file contains information that the JDT feature needs in order to properly compile the project: the project's source folders (that is, what to compile); the output folders (where to compile to); and classpath entries (such as other projects in the workspace, arbitrary JAR files on the file system, and so forth).
From the wiki
Java class file is a file (with the .class filename extension) containing a Java bytecode which can be executed on the Java Virtual Machine (JVM).
Java class file is produced by Java compiler from Java programming language source files (.java files) containing Java classes.
If a source file has more than one class, each class is compiled into a separate class file.
I can say .classpath is a file required/related only if you are running java project in the eclipse.
Explanation:
You may need some jar file required to run your project, so in this case you have to include these jars in your classpath in order to run your project/application. If you are running manually you have to include jars to classpath and then execute, but if you are using Eclipse this classpath information i.e. the jars that needs to be added will be there in the .classpath file so that you need not add jars manually to the classpath.
NOTE: .classpath file will be automatically generated by the eclipse, this will have the information of the jars you added in you eclipse build path.
I realize similar questions have been asked, but mine seems to be unique. When I attempt to export my project as a JAR the project itself does not appear in the export window. Can anyone help me?
Also, I'm not sure if this changes anything, but I used a Java Decompiler to decompile the source, put it in a folder, and created a project with the same name as said folder to be able to edit it. As well I have asked the devs of the JAR and they said it was fine.
Does the project have an output folder? Is it an actual Java project that is compiling? Take a look at the build path and see if anything is funky.
I have inherited a jar file with two JNI class files and related libraries (.so files). I am not familiar with c++ or JNI. How do I reference these in my Java project in Eclipse?
So far, I have created a Java project, added the jar file as an external jar to the buildpath and then have attached the folder containing the jni libraries using Properties -> Java Build Path -> Libraries tab, expand the jar file (containing the class files) and edit "Native library location".
I have a driver program in Java with a main method which makes the jni object. Eclipse says "ObjectName cannot be resolved to a type".
Why would this happen even though the class files are in the build path?
I have just put all the libraries under /src/main/resources.
Right click on the project and go to Properties>JavaBuildPath. In the Libraries section expand the jar you need the libraries for and click on "Native library location", then press "Edit..".
You just need to give the /src/main/resources path as location.
Then in the "Order and Export" section of the Properties>JavaBuildPath you need to make sure that /src/main/java is above /src/main/resources.
In the Java file, where you instanciate your JNI defined object, make sure you have imported the class files:
import your.jni.classes;
I suggest you have a look here, at the video:
http://mmbtools.crc.ca/content/view/53/78/
(look at this video on Youtube and set the resolution to 720px to see clearly)
It is a good step-by-step example of how to integrate JNI classes in a Java application, in Eclipse. It is pretty much what you're trying to do.
Hope it helps,
I recently downloaded the Java JNA from https://github.com/twall/jna/servlets/ProjectDocumentList?folderID=7408&expandFolder=7408&folderID=0 and tried using it. However, as exemplified by the screenshot below, the demo source code provided in https://github.com/twall/jna/ won't compile, no matter where I place the files. Mind you, I've tried placing them both in the default package an every other combination of package mix-ups, and this is only the latest version. Does anybody know why the compiler can't find what is contained within the JAR file? (Also, as you can see, the class files are all in the jar file to be found)
Basically, the JAR should go in the classpath. In Netbeans, you can do it by adding it as library to the build path of the project through the project properties.