Eclipse IDE won't resolve classname automatically - eclipse

I have a Jar, which I have included in my project.
When I import a class from this project by specializing the full name as org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor the class is imported well.
Writing ICellEditor and doing "Organize Imports" doesn't work.
Doing "Open Type" and typing ICellEditor finds the right class, so Eclipse is aware of this JAR amd class; but does not show the class on "Organize Imports".
Do someone know what the reason could be?

Make sure that your jar path is included in the CLASSPATH. When you give fully qualified name as shown below CLASSPATH is not required. (as you give the complete path explicitly).
org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor
So if you want your import in eclipse to work properly :
So either put this jar in the existing jar directory or make sure that the jar path is added in CLASSPATH.

Related

Importing classes & utilities in the manifest // JNA

I'm a CS student and am in way over my head for an end of the year project, for which I need to find the dimensions and locations of a separate window. I've found that I need to use JNA libraries and understand how to do that but I don't understand how to import the JNA libraries through the manifest. Here is my file structure so far (I'm working in netbeans):
Project Folder
dist Folder
nbproject Folder
src Folder
Test Folder
Build.xml
Game.exe <-- This is the exe I run from the java file itself. I need to find this window's size and location for use later in the project
jna.jar <-- need to implement this as a classpath
Manifest.mf <-- I supposedly need to edit this.
The reason I show you this is to ensure that I've put the JNA Jar in the correct place.
Next, here is my manifest:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Class-Path: C:\Users\justi_000\Google Drive\4. APCS\JZMinesweeper\jna.jar
So I need to edit the bit after the java -cp but I don't know what to put there, and in what order. The java tuts, etc aren't of much help.
Additionally, are these imports correct? They may be the problem and I have correctly imported everything, but I doubt that.
import com.sun.jna.*;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.*;
And, turns out, that it was a stupidly easy solution that my general incompetence caused me to miss.
Turns out it is actually possible to directly import libraries in IDEs...probably why they all include a tool for it. Blind old me has only ever used them once before (the perils of being a student) but we're all set. Simple as right click libraries>add jar.
Figured i would stick this here for future reference.

Java import directories

I want to ask smaller question about Java VM and thing about it.
If I understand import process correctly, then when I request contents of packages by import keyword in Java, packages are being imported from it's specified import directory. Then when I'm running Java application from a directory in computer and some of the imported packages could not be found in JVM import directory, JVM is looking for them in current directory. But in that case something must be wrong, because when I run my project from Eclipse and I request some package from the project, it's found. I think that Eclipse is changing directory where packages are being searched. Am I right? Is this all way of importing in Java?
The import statement is just syntactic sugar so you don't have to specify the fully qualified name everywhere in your classes. It doesn't actually import anything in terms of code.
Classes are looked up in the classpath.
In eclipse you can configure the build path (for each project) option project - - > build path.
There you can either add a directory, jar file, external jar files, etc.
Also you can check what's already defined.

How to export GWT project classes into JAR file

I find it difficult to export classes from one project into JAR file, so that I could import it in another project.
How do I try?
I right-click on project in Package Explorer -> Export -> Java -> JAR file -> select all the packages I need. 'Export generated class files and resources' option is checked, other options are left unchecked. Then I click Finish.
When I import such generated .jar file into the dependent I encounter a list of errors:
The import pl.abc.xyz cannot be resolved
Xyz cannot be resolved to a type
It seems like the classes from the JAR file were not found by the compiler.
Please correct me, if I do it in a wrong way. Thanks.
It seems that you need to include in jar also java source files from the client package (sometimes also shared package depending on your GWT module structure as defined in *.gwt.xml file).
The GWT compiler requires java source for the part which has to be compiled into Java Script, to be availabe as classpath resources along with compiled classes. It is simple to achieve with ant or maven build.
You can also check Export Java source files and resources when exporting, but it will add all the source code, not only the client part.
Make sure you inherit the module in your .gwt.xml file. You want to inherit the .gwt.xml file from the GWT jar you are importing, for example:
<inherits name="com.example.youmodule.Name" />

Eclipse not using jars from add classpath variable

I added a classpath variable (via eclipse's build path) that points to a cache of jars. While this folder is represented in eclipse's folder view, the contained jars are not recognized for some reason.
For example, when I import a class that is present in a jar in the cache (and thus the added classpath variable), eclipse indicates that the class can not be resolved.
Any ideas what is wrong and how to resolve it?
You have to make sure that the jar(s) that you want are actually included in the classpath of the project you're working on. Right-click on the project, go to properties -> java build path and make sure you've added the jar to your project.
I think this is the problem you are having : https://bugs.eclipse.org/bugs/show_bug.cgi?id=70417
So go vote for the enhancement - it's the only way things like this get done!
I too struggled with the same problem and finally got the solution for it. Just copy the jar's in your server's lib folder eg)apache tomcat's lib folder and then run the project.

How can I import eclipse JDT classes in a project

I want to do the following imports in a class.
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
How can I import the JDT within Eclipse?
Cheers.
I think I found an easier way to do this:
right-click on your project in the Package Explorer;
choose "Build Path...";
choose "Configure Build Path";
choose the Libraries tab;
click the "Add Variable..." button;
in the list box, choose the "ECLIPSE_HOME" entry, and then click the "Extend" button;
in the list box, open up the "plugins" folder entry, scroll way down, and shift-click all the org.eclipse.jdt.* JAR files that are in the file listing beneath the folders;
click OK until you're all the way back out.
That should do it.
Unless I'm misunderstanding you, you just need to include the JDT JAR files on your classpath; they're all available in your Eclipse plugins directory. So for your project, right-click on the project's name in the Package Explorer, go to the Build Path... submenu, and choose Configure Build Path. Then in the Libraries tab, use the "Add External JARs" button to add each of the relevant JAR files from the Eclipse plugins directory.
If your'e writing plugins for Eclipse, you shouldn't really be trying to instantiate the internal packages. According to this API Rules of Engagement
Stick to officially documented APIs. Only reference packages that are documented in the published API Javadoc for the component. Never reference a package belonging to another component that has "internal" in its name---these are never API. Never reference a package for which there is no published API Javadoc---these are not API either.
For the others, add the package name to the Import-Package entry in your manifest.
There are extension points into the JDT, but if what you want to do falls outside of these, then I'm afraid you're out of luck.
If you're just looking to use a compiler in your code, without relying on the JDK (i.e. on a JRE), then I would consider shipping with a more standalone Java based Java compiler like Janino.
If you need these classes, you are probably in a plug-in project already. You should be able to import these classes by applying the quick fix "Fix project setup..." (Ctrl+1) on the line where Eclipse is complaining about the imports. That will add the required plug-ins to your MANIFEST.MF file in the META-INF directory (org.eclipse.jdt.core and org.eclipse.jface.text in your case). You can also add them manually in your MANIFEST.MF file. If your project is no plug-in project (and you have no MANIFEST.MF file) you can convert it by right-click on the project -> PDE Tools -> Convert Projects to Plug-in Project first. If you add dependencies to plug-in projects in the normal way ("configure build path") the classloading won't work properly at runtime (though it will compile).