Problems with Xtext in eclipse - java

I'm working on a Java project in eclipse. Trying to open a file through Ctrl+Mouse click, I got a popup that asked me if I want to add "Xtext nature to my project". I said ok. And now, I tried to put on a CSS file the following line:
#import "myfile.css";
as first line. But I get this error, because of Xtext Check (fast):
missing EOF at ';'.
Can anybody help me on how to deal with this kind of error?
Thanks.

You have two ways to solve this issue:
First, you could uninstall the plug-in contributing the CssDsl editor. A quick Google search told me that it is contributed by the e(fx)Eclipse plugins. To uninstall a plug-in, go to the About dialog, click on the Installation details feature, and in the upcoming dialog you could look for the feature to uninstall.
If the previous solution does not work for you (e.g. you need the e(fx)Eclipse environment), you have to change the default file associations to avoid opening css files with the Xtext-based editor, and remove the Xtext nature from the projects you added.
Setting file associations: open Eclipse Preferences, navigate to the General->Editors -> File Associations page, where you can look for the CSS extension, and select a different default editor for it.
Removing the Xtext nature: you can right click on your project, and select Configure -> Remove Xtext nature. If that does not work for some reason, you have to open the hidden .project file, and remove the <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> entry and the corresponding org.eclipse.xtext.ui.shared.xtextBuilder buildCommand manually.

I had the same error, when I was creating CSS via New -> Other... -> Web -> CSS File.
Zoltan's solutions did not work, but when I create the file with New -> File and name it *.css the error did not occur.

Related

IntelliJ Not Highlighing Anything

When I create a new Java project or open an existing one, IntelliJ doesn’t highlight any of the text nor does it suggest anything. All the code is 1 single color. I’ve marked my src file, made sure power safe is off, made sure highlight is enabled, and even reinstalled IntelliJ CE. I’ve also disabled all plugins. Any suggestions is appreciated.
picture here
Your screenshot shows that the file is not recognized as a java source file.
Go to Preferences -> Editor -> File types
Scroll down in the list of Recognized File Types and click Java.
In the list of registered patterns make sure it shows *.java.
Also ensure the file is not marked in the Ignore files and folders section at the bottom of this preferences panel. Perhaps you added it by accident (with some shortcut).
Also, while reinstalling IntelliJ, you have probably imported your previous settings. With it, you inherited this issue.
If this doesn't help, please share a screenshot of your project/module structure and setup.
Last but not least, try to create the file using the context menu. E.g. try to right click on your src folder and select new and select Java class or Package from the options. Would be good to check anyway, to see if these are valid options. If they do not appear here, it indicates the project setup is erroneous.
Solved! Thanks to #yole I did the following 'make sure that the *.java extension is listed in "Registered patterns" for the Java file type in Settings | Editor | File Types".

No syntax highlighting in eclipse for java

There is no syntax highlighting in java files in my eclipse..This happened all of a sudden..Not sure why..
This is how it is looking now..
As mentioned in other posts..i tried to change the color from preferences window and there is nothing when i type java..something really messed up...
AAny suggestions..
Update:
It seems Java plugin is not installed..as per the below screeenshot
And when i try to install java plugin it says new version is already installed as per the below screenshot
Closing the file's tab and re-opening it fixed it for me.
(I actually closed all the tabs...)
I faced the same issue all of a sudden after a commit/update project operation.
The point is, default editor of Eclipse has changed somehow and we have to set it back to normal.
Try the below method,
1. Goto Windows -> Click Preferences
2. From the Preferences window goto General -> Editors -> Click File Associations
3. You can choose the default editor for *.java files here
When I first opened Preferences, 'Text editor' was set as the default editor for .java files and then I changed it back to 'Java Editor'.
Now it works perfectly fine.
You probably have a corrupt installation or you have recently installed a corrupt plugin.
The following steps might help.
In your Install window,
view your "already installed" plugins.
select the "Installation History" tab.
select a previous stable configuration
Click the "Revert" button
TLDR; open another workspace, then come back to the original workspace.
Ok this is odd, but for me, all the highlighting suddenly went away for Java files. I explored all of these ideas here, with no effect. I created a new workspace, planning to move everything to it. I realized that can be a pain to move many projects over, so I went back into the original workspace to look at some settings, and poof - the highlighting was working again.
I have one java class file like a text editor.
I tried following,
Select the respective java class file from eclipse.
Right click on the file and mouse hover on "Open with".
Select java editor.
Now its works.

How to display eclipse project type

In Eclipse IDE there are icons to display the project type, but I can't find a text description. I would expect right click -> properties to show this info but according to this all projects are of type "project" (even if they are a java project, or maven project etc.)
Does anyone know?
Thanks!
According to this, you won't find the text description in Eclipse GUI.
One way is to go to the root folder of your project, open the file named .project and check the elements in the tag <natures></natures>.
But don't worry about that, these icons are often explicit.

Eclipse Open declaration in Java project

In an Eclipse SVN project I have a problem; when I tried to open a declaration of one class, I got this error:
Problems opening an editor Reason : projectname does not exist.
Also refactoring does not work.
I have searched the web and tried all found solutions but nothing helped.
I have downloaded different Eclipse and Java versions and switched to a clean workspace but I still have the problem.
How can I solve my problem or which solution can I try?
Right Click on the project -> Properties -> Project Facets -> Click on the Configuration Link -> Click on Apply Button -> Click on OK button.
The above steps should set your project as a Java project.
If the project is a multi-module Maven project, then you need to import the child/module projects in addition to the parent/pom project. Then ensure that you only open source files via the child project. Java files opened this way will have the Refactor right-click menu item, and F3 Open Declaration etc. work properly. However if the Java file is opened from the parent project, these Eclipse functions will be missing.
It's quite frustrating when opening a file via a Search result, as the file will be found and listed in both the parent and child project. You need to ensure you only work with the file accessed via the child project.
I can't explain precisely what's going on with Eclipse, but it appears that Eclipse does not recognize the parent project as being Java projects, although it will correctly syntax-highlight the Java files whether they are accessed via the parent or child project.
You needed to to check it out as a Java Project, or preferably, its creator should have committed the .project and .classpath files for it.
I had this problem, too.
It looks like after a search-in-workspace Eclipse opened a wrong file.
I pressed Ctrl + Shift + H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.
The difference in icons is:
you can solve the problem by create a new java project.
when you check out the project,you should select the default option,
[Check out as a project configured using the new project wizard].
It might lack a builder. Check your PROJ_HOME/.project that should be like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>the-one-user</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Ref:
FAQ How do I add a builder to a given project?
Are you importing a maven project? If you importing a maven project, a file will be viewed in few perspective, especially if you open the file via "Open Resource (Ctrl + Shift + R)".
Let's look at the example above, "servlet-filter" (mark as 1) imported as maven project, and maven perspective project created in 2. If you open a file in 1, your "Open Declaration F3" will no work, because it is not a valid maven project. It will work if you open the same file in 2.
Hope this helps.
You need to import it as a Java/Maven project. Once you are done importing the project do the following steps
Go to Project -> Select Properties -> Select Project References -> Select/Check all the
dependent/Child projects which you reference in the code base -> Apply
and Close
Once you are done, try to clean the whole project. This should solve the issue.
There is a bug in Eclipse (in Luna at least) for a very specific workflow, which might not be the answer to this specific question, but might be helpful for others.
If you perform an import into the src (meaning src folder has focus before performing import) folder from an extracted jar (as source code), and you place breakpoints in the nested *.java files in the nested packages, it won't hit those breakpoints. In order to get things to work, you must keep hitting F3 instead of using "Open Declaration" to get to the *.java file you want to set a breakpoint in, then add the breakpoint by double clicking in the far left margin. Then Run > Debug As > Java Application.
If the format of the project you checked out is of type Maven, you need to convert it to a Maven project first. It may be because the required classes haven't been generated yet. To do this, right-click on the project, click Configure, and then click Convert to Maven Project.
I had the same in Eclipse Luna on Debian 8.
I was missing the .classpath file when checking out from SVN.
I manually copied it and changed some path names, refreshed the project and it was working again.
It happens, when libraries are not available on class path of the project where F3 does not work.
Select any other project and try to use f3 for navigation. It will work.
The solution is to add JAR files in your libraries or add libraries in your project.
Try to use MAVEN project so that the problem can never occur.
I am using Eclipse Oxygen.2 (4.7.2). I don't see Project Facets after clicking project -> Properties. My solution is right click the project and click Configure, then select configure and detect nested projects, Eclipse will automatically generate the nested projects for you. May get some build errors in the new created projects, that should be easy to fix.
Go to Project properties,Select Project Facets then convert to project facets then click Ok then you will able to open editor.

How to change an Eclipse default project into a Java project

I checked out a project from SVN and did not specify the project type, so it checked out as a "default" project. What is the easiest way to quickly convert this into a "Java" project?
I'm using Eclipse version 3.3.2.
Open the .project file and add java nature and builders.
<projectDescription>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
And in .classpath, reference the Java libs:
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
Manually changing XML and/or settings is very dangerous in eclipse unless you know exactly what you're doing. In the other case you might end up finding your complete project is screwed. Taking a backup is very recommended!
How to do it just using Eclipse?
Select project.
Open the project properties through Project -> Properties.
Go to "Targetted Runtimes" and add the proper runtime. Click APPLY.
Go to "Project Facets" and select the JAVA facet which has appeared due to step 4. Click APPLY
Set your build path.
If it's a Maven project, you might want to select the project, click Maven -> Update Project configuration...
That did it for me. And Eclipse is configured correctly. Hope it'll work for you too.
In recent versions of eclipse the fix is slightly different...
Right click and select Project Properties
Select Project Facets
If necessary, click "Convert to faceted form"
Select "Java" facet
Click OK
I deleted the project without removing content. I then created a new Java project from an existing resource. Pointing at my SVN checkout root folder. This worked for me. Although, Chris' way would have been much quicker. That's good to note for future. Thanks!
Using project Project facets we can configure characteristics and requirements for projects.
To find Project facets on eclipse:
Step 1: Right click on the project and choose properties from the menu.
Step 2:Select project facets option. Click on Convert to faceted form...
Step 3: We can find all available facets you can select and change their settings.
In newer versions of eclipse (I'm using 4.9.0) there is another, possibly easier, methods. As well as Project Facets, there are now Project Natures. Here the process is simple get the Project Natures property page up, and then click the Add... button. This will come up with possible natures included Java Nature and Eclipse Faceted Project Properties. Just add the Java Nature and ignore the various warning messages and your done.
This method might be better as you don't have to convert to Faceted form first. Furthermore Java was not offered in the add Facet menu.
Joe's approach is actually the most effective means that I have found for doing this conversation. To elaborate a little bit more on it, you should right click on the project in the package explorer in eclipse and then select to delete it without removing directory or its contents. Next, you select to create a Java project (File -> New -> Java Project) and in the Contents part of the New Java Project dialog box, select 'Create project from existing source'.
The advantage this approach is that source folders will be properly identified. I found that mucking around with the .project file can lead to the entire directory being considered a source folder which is not what you want.
You can do it directly from eclipse using the Navigator view (Window -> Show View -> Navigator). In the Navigator view select the project and open it so that you can see the file .project. Right click -> Open. You will get a XML editor view. Edit the content of the node natures and insert a new child nature with org.eclipse.jdt.core.javanature as content. Save.
Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentry with the attributes kind with content con and another one named path and content org.eclipse.jdt.launching.JRE_CONTAINER. Save-
Much easier: copy the files .project and .classpath from an existing Java project and edit the node result name to the name of this project. Maybe you have to refresh the project (F5).
You'll get the same result as with the solution of Chris Marasti-Georg.
Edit
Another possible way is to delete the project from Eclipse (but don't delete the project contents from disk!) and then use the New Java Project wizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.
Right click on project
Configure -> 'Convert to Faceted Form'
You will get a popup, Select 'Java' in 'Project Facet' column.
Press Apply and Ok.
Depending on the Eclipse in question the required WTP packages may be found with different names. For example in Eclipse Luna I found it easiest to search with "Tools" and choose one that mentioned Tools for Java EE development. That added the project facet functionality. Searching with "WTP" wasn't of much help.

Categories

Resources