Eclipse editor/build losing access to imported javax classes - java

I fixed my problem but I don't know how/why this fixed it so I am looking for an explanation.
I opened my project yesterday and I could no longer build due to the fact that the java and jsp imports could no longer see javax.* classes. I had another project that worked fine but could find no differences in their build paths.
After reading several threads on build path, etc. and not finding any problems in the configuration file I simply retyped the import in one of the source files, eclipse was able to lookup class tree as I typed in the editor, and once one of the imports was retyped the project would now build.
I would like to understand what in the Eclipse project configuration was hit and why this happened and how this method I used actually resolved the problem.

Related

Java intellisense not working when imported projects not available

I'm reviewing an isolated Java project in VSCode. By that I mean that I have the project itself, but not any of the projects that it depends on. From what I can tell, the result is that Intellisense has been turned off for the project, which makes navigating around the code a pain.
For example, you can see below that VSCode can't find the definition of a method, even though it's just 3 lines down. On the side, you can see the errors it's encountered trying to load various artifacts.
Is there a way to turn Intellisense back on, at least for the objects that are defined within the project itself? I have the MS Java extension pack installed.
To clarify, these are internal projects that it depends on and I don't have on my machine.
I just noticed there's a feature that might help you get around this. Check out "Lightweight Mode" here: https://code.visualstudio.com/docs/java/java-project
Maybe this will get away from having access to mvn full resources and just get the quick-n-dirty navigation as the docs seem to indicate!
Lightweight Mode
VS Code for Java supports two modes, lightweight and standard. With
lightweight mode, only source files and JDK are resolved by the
language server; with standard mode, imported dependencies are
resolved and the project is built by the language server.
...works best when you need a super quick-to-start and lightweight
environment to work with your source files, for example, reading
source code, navigating among source code and JDK, viewing outline and
Javadoc, and detecting and fixing syntax errors. Also, code completion
is supported within the scope of source files and JDK... Lightweight mode doesn't resolve imported dependencies nor build the project.
Your project throwed project build error: Non resolved parent pom for com.....
When errors are resolved, the intellisense should work as normal.
Please have a look at this question. Try and see if error goes away.
Project build error: Non-resolvable parent POM.

Cannot figure out error importing jme3 in eclipse

**UPDATE:
I closed and re-opened eclipse (which I've done before), and was presented with a new "quick fix" solution of moving the library to the module path (which it has been in before), and now I can reference it, but now
import com.jme3.app.SimpleApplication;
says
The package com.jme3.app is accessible from more than one module: jme3.core, jme3.desktop
my module-info now have warnings as well:
module-info.java:
module vast {
requires jme3.core; //Name of automatic module 'jme3.core' is unstable, it is derived from the module's file name.
requires jme3.desktop; //the same(ish)
requires jme3.lwjgl; // and so on
}
I'm going to fiddle around a bit and see what I can figure about those
**
So, I've decided to migrate one of my projects from LWJGL3 to JME3 (using Eclipse). I followed the advice of Setting up JME3 in Eclipse, specifically downloading the library, extracting it to a lib subfolder in my project, I then added the contents of the library to a User-Library (using Add JARs, since they are in my project), and added the library to my classpath. I know eclipse sees the library (code suggestions), but I keep getting access errors.
Setup:
Arch Linux (latest)
Eclipse IDE for Java Developers (2019-12 (4.14.0))
Here's the code (small test class to make sure it runs before I refactor):
Test.java:
package lab.stone.werlious.vast;
import com.jme3.app.SimpleApplication; //the type com.jme3.app.SimpleApplication is not accessible.
public class Test extends SimpleApplication { //SimpleApplication cannot be resolved to a type
}
module-info.java:
module vast {
requires jme3.core; // jme3.core cannot be resolved to a module
}
I've tried many different combinations of adding the library (modulepath, classpath, user library, external JARs, internal lib JARs), and referencing it. I keep getting errors, even though SimpleApplication suggests importing com.jme3.app.SimpleApplication, which suggests adding requires jme3.core to module-info.
I am not using maven or gradle (detest those), and prefer to do things locally. I also prefer eclipse over jme3 sdk. Can someone tell me how to properly import this library (without maven or gradle)? and how to properly import it in my code? I didn't have this issue adding LWJGL3 to eclipse before, and currently jme3 is added the same as lwjgl3 in my source project (jars in lib folder in project, lib folder added as user library, user library added to classpath).
Thank you all for your help
As a side note, because I'm sure someone will mention it, I've been on various forums for about 2 hours trying to figure this out, including stackexchange. I can't find a similar issue with a solution that works for me.

How to solve the IIB10 toolkit errors for IIB9 projects

I have imported the projects that I'm using in IIB9 without any errors, now I have installed the IIB10 toolkit and I have imported the same IIB9 projects in my IIB10 toolkit. But I found few errors which I'm unable to resolve those, only few projects are getting the error as: "unable to locate a class definition named com.src.helloworld.java in the project or reference project" but I have given the required references to the projects and when Im checking the java compute class I can go into that class code. Please suggest and help me out on this.
I also got this error after upgrading to IIB10.
The reason is exactly what #Alaychem described above - internal differences between "Normal" java projects and javaCompute nodes.
When a Java project is created by adding a JavaCompute node to a MsgFlow, a '.project' file is created with internal definitions of IIB. However, when a Java project is created by making 'new -> Java project' (="normal Java") - also a '.project' file is created, but this time with some less definitions in it.
Therefore, if you created A "normal" Java project, and afterwards connected it to a MsgFlow, after upgrading to IIB10 it might not be recognized anymore, because of these missing definitions in the '.project' file.
A quick way to solve the error in IIB10 without re-defining a JavaCompute node, is to add the missing definitions to the '.project' file of your Java project with the errors.
How? -> Open another Java project that you have, and compare the differences between it's '.project' file, to the '.project' file of the Java project with the errors. Just copy the missing definitions. Afterwards - refresh the Java project (F5) and rebuild the project.
Some pictures to make it clear:
First image - '.project' file of a Java project created by JavaComputeNode. In yellow are the missing definitions. Just copy them.
Second image - '.project' file of a Java project created by a "normal" Java project. Copy to it the lacked 'yellow' definitions from previous picture.
I got this error when mixing JavaCompute classes and "normal" classes.
From My answer at mqseries
"Normal" java projects and javaCompute projects are not the same, for some reason. The src/output libs in. classpath file are not the same, and probably some other differences, that cause the toolkit to treat them differently.
My project was normal java project, that a java compute class added into it later. The v8 toolkit manage with it, but v10 does not.
Moving the javaCompute class to a new javaCompue project (through double clicking new javaCompute Node) did the trick
P.S Adding the normal java files into javaCompue project seems like a bad strategy. It caused some import issues at IBM classes.

IntelliJ multiple Modules which lie in the same package-namespace?

I try to migrate from eclipse to IntelliJ IDEA 13.
Up until now I had multiple eclipse projects which are all in the namespace xxx.yyy.zzz.
(Kind of a plugin infrastructure with one main app and plugins using the same namespace...).
After migrating the eclipse projects to IntelliJ modules everything builds fine, until I open a File of the main app. IntelliJ then complains: "Package name "xxx.yyy.zzz.Foo" does not correspond to the file path "src.xxx.yyy.zzz.Foo", and therefor also fails to find the imports depending on this package.
This happens even though I set the source-folder to src. The weird thing is: This only happens to some of the imported modules, others (in the same namespace) are fine.
And also the modules which show this behavior start behaving like this only after I import other modules (so I guess there is some problem with conflicting package-namespaces in modules?)
Any input would be highly appreciated, since I can't find a solution to this.
Thanks!

Class file not found in IntelliJ

In IntelliJ I get this weird error when I try to compile.
Cannot find annotation method 'cascade()' in type 'javax.persistence.ManyToOne': class file for javax.persistence.ManyToOne not found
I know, it seems pretty obvious what the problem is, but having spent too much time on this problem I now turn my trust to you!
I use ideaCommunity-9, where I have created a global library for JBoss, which contains all JBoss jars including ejb3-persistence.jar. My module includes this library, and I have moved it to the top of dependencies.
No otherwhere in classpath I have a javax.persistence.ManyToOne class, and it also opens up in IntelliJ without problems.
If I open the file where I get the compile error, IntelliJ shows no problems and also navigates to the class file on pressing Ctrl+B.
The code is also build with ant and here it works fine.
Besides the above error I get six others along the same path (name in Table, etc.) - all related to JPA. I also get a message saying "Please file a bug to JDC yada yada yada."
Try to tick a checkbox "export" in your dependencies.
I mean: "File" menu -> Project Structure -> Modules -> Dependencies, and there you can see libs included to the module. You should also see a checkbox near each lib in column 'Export'.
Just got this myself but non of those things were my issue. I downloaded a project from github, then opened in intelli J with the problem after trying to run a junit test.
Solution: Project Structure -> Modules -> 'Project_Name' -> Sources (tab) -> click src folder -> Mark as: Sources
This should highlight src to be blue and all the class files should be the circles with C instead of looking like normal files. Try running a test again and see if that does it.
I'm sure, it is too late to answer, but I had to follow a different approach for this error to resolve this issue.
I had to create this as global library and add that library to the module, then only the error is resolved.
Isn't that similar to this SO question?
The solution there was to add all JBoss jar (which you did), but also all persistent-related libraries (like Hibernate)
See this JBoss project configuration for example:
alt text http://jdick.co.uk/blog/wp-content/uploads/2008/12/projectstructure1.jpg
In short, ejb3-persistence.jar might not be the problem here, just a symptom of other elements missing.
Or, if it is the problem, it may be related to the fact that it is not deployed correctly (for the WebApp configuration).
Here's an idea:
Maybe you have multiple versions of your jar file.
Search your folder hierarchy for the file ejb3-persistence.jar,
using a file management tool such as Total Commander.
Multiple appearances of the file in your classpath may confuse IntelliJ Idea
into not recognizing the proper class in the proper jar.
had a similar problem ("cannot find class spring...DefaultResourceLoader even though it was in my maven dependencies) and no amount of tweaking of revalidating caches seemed to help. Blowing away my $HOME/.Idea* paths and (basically) starting from scratch fixed it for me. At least for now...
I was getting the class not found error message when trying to execute a .groovy test class, which referenced a .groovy file (located in the root of the source directory of a submodule - i.e. no packages).
Moving the source file .groovy into a package, fixed the issue for me.
Move:
src/main/groovy/RunMe.groovy
to
src/main/groovy/somePackage/RunMe.groovy
In intelliJ I got this problem when I built (ctrl+shift+F9) at the file level.
The reason is, I had changes in other files in the same maven project, that were not getting picked.
I solved it by building at the project level (Select the Maven project in intellij and press ctrl+shift+F9)

Categories

Resources