How to set NetBeans project properties to use Java 7? - java

I am new to NetBeans, and have previously been using Eclipse. I have started using NetBeans now because I need to learn a variety of Java EE concept, and I have found more relevant tutorials for the NetBeans IDE. A lot of the abstract concepts in EE still has me confused, so I have found that step-by-step holding hands-tutorials works best for me for now.
I have however met a dead end. I am following this tutorial, on setting up a web service client. However, one of the lines include a try-with-resource statement, which is new in java 7. Picture here:
When I started this tutorial, I was using Netbeans 7.1.3, with Glassfish 3.1.2. I knew it didn't have support for EE7, so i downloaded NetBeans 8.0.1 with Glassfish 4.1. I have realized later on that the try-with-resources is a part of SE, and my upgrade was in this matter reduntant.
I figured there was something wrong with my project settings, so i right-clicked it and opened it's properties. Under the Libraries option, I found that the JDK was correctly set to Java 1.7 (update 51). Picture here:
I also checked the oter options, and under Run I found that Java EE is set to 6, even though Glassfish 4.1 is selected as server. I figured this was an implementation of EE7, but the option is locked to EE6. This confuses me a bit, but shouldn't be the cause of the problem. I still attach a picture of it, just in case it is relevant:
So what is wrong with my Java settings for this project? Why can't it accept a Java 7 feature, when it seems like it is set to use Java 7? Are there other places where i need to set java version/home?

You use Java7 for the system library but compile your source code to be compatible with Java6.
To change this you have to go to sources in your project settings and change the source compatibility to Java7.

Related

Visual Studio Code CTRL+Click with Java stops working after a while

For some reason after having a Java project open for more than 20 minutes, maybe a little more, the CTRL+Click shortcut to inspect classes/methods stops working. When clicking it only appears a loading indicator on the tabs section that keeps going forever without actually loading anything.
Another problem is that when hovering on a method it will stay on "Loading..." forever.
Strangely enough IntelliSense keeps working, so it will still give suggestions while writing.
I am using "Extension Pack for Java" latest version and latest version of VSCode. I am also using JavaSE-11.
Edit: maybe it's worth pointing out that I'm encountering this problem on a Spring Boot project.
Have you installed the extension Lombok Annotations Support for VS Code? It can modify your "java.jdt.ls.vmargs" in the settings.json. Although you have uninstalled it, this configuration will not be removed.
Please check whether you have modified "java.jdt.ls.vmargs" in the settings.json.
If it still does not work please disable all the extensions and only enable the Java-related extensions, and clear the settings.json then to reopen the VSCode.
I had the same problem in the past! So it was because VS Code can't use OpenJDK for its own work. More precisely, it works, but not all plugins work correctly. For VS Code you have to install Oracle JDK particular version and make configured JAVA_HOME environment variable as path to this Oracle JDK. After that you need to restart your VS Code. So, OracleJDK will be used only for VSCode, but if you need, inside your project you can use OpenJDK without any problems.

JavaFX and IntelliJ no errors althought the documentation says I should have some

I'm currently following this tutorial: https://openjfx.io/openjfx-docs/ (JavaFX and IntelliJ IDEA). I use Intellij 2021.3.2.
I have created a project (1. Create a JavaFX project), which worked out great and didn't need to 2. Set JDK 16 because it was already set to 17 (which I guess is fine).
But here begin the weird stuff (and I'm very new to programming so I'm sorry if it sounds silly). "You can also set the language level to 11 or greater." I don't have this option. Because it's "can" I felt like it wasn't a big deal but if someone can explain what this is all about? Just out of curiosity, because I'm at the very beginning of the tutorial and I kinda only understand half of it.
Then 3. Create a library, and I don't have what they have, and my stuff is red:
So when they said "add the JavaFX 17 SDK as a library to the project" I didn't know what to do. I also didn't know what to do to fix the red stuff.
And finally, they say "Warning: If you run now the project it will compile but you will get this error: ..." but if I click on this button
everything works! which you know i'm not complaining about but I would like to understand a bit more what is happening.
And then they suggest I should 4. Add VM options to fix the problem that I don't have. So I figured maybe my computer set the VM options correctly without me knowing it but there is currently no VM option (and it works). Should I add them nonetheless?
Thank you for your help, I'm very lost and feel like I don't really understand anything.
The current documentation in the openjfx tutorial for getting started with JavaFX using Idea is incorrect, at least for recent Idea releases (2021.3 +).
The tutorial is written as though a new Java project was created, rather than a new JavaFX project. Once a new JavaFX project has been created, most of the rest of the steps in the tutorial are either redundant or wrong.
Step 1, “Create a JavaFX project", does a lot more than just “Create a Java project”, which is why everything else is different from the tutorial.
A better tutorial for getting started with JavaFX with Idea, is the official Idea documentation:
Create a new JavaFX project.
Differences between creating a new Java project and creating a new JavaFX project
The new JavaFX project:
Provides a build script for Maven (pom.xml) or Gradle (build.gradle).
Adds the appropriate dependencies for JavaFX base, graphics, controls and fxml.
Provides an example application and controller code that you can run immediately.
The example project is modular and provides a module-info.java
Because the program is modular and dependencies are downloaded via maven and recognized by the IDE, you don’t need to manually configure VM runtime options for the module path and adding modules.
Idea will recognize the Maven or Gradle projects and automatically synchronize the initial transitive dependent libraries with the Idea project.
There are options in the Idea Maven tool window which will allow you to synchronize further changes to dependent libraries or javadoc and source code in libraries.
Selects a JDK and attaches it to the project, automatically downloading the selected JDK version if not already present.
Sets an appropriate language level for the project.
When you just use the create new Java Project option, it doesn’t do any of those things, so you need to do things manually instead, which is what the rest of that tutorial is about:
Manually download the JDK and configure it in the SDK.
Manually download the JavaFX SDK and add the libraries from it to your project.
Manually configure VM modular arguments.
Manually maintain any other dependencies.
Manually associate javadoc and source code.
Manually write the code for a basic application.
Manually set the project language level.
Doing all this stuff manually is more work and more error prone. The manual work usually leads to a worse outcome and a project that is more difficult to maintain for many people getting started with JavaFX, so I do not recommend it.
Versions
In terms of the versions to use, I recommend using the most recent stable (non-beta) releases of both JDK and JavaFX, regardless of what versions may be referenced in any tutorials you may be using.
You can set JavaFX versions in the Maven file generated by the new JavaFX project wizard, then press the button in the Maven Tool window to synchronize the Maven project with the Idea project.
Language level settings
These are important later on, but pretty irrelevant when just getting started.
The language level settings:
Tell the compiler what version of the java byte code to compile the application to.
Tell the IDE what language syntax rules to enforce and provide help with.
If you use Java 17 only features, the app won’t run on a Java 11 VM.
You can define the settings in Idea manually:
language setting level.
But it is better to set them in the compiler section of the maven project and synchronize the project with Idea, which will also configure the settings in the IDE.
IMO, set it to the most recent stable version and have a requirement that your application be run with that Java version as a minimum (you can enforce that by using jlink or jpackage to bundle the JRE version you choose with your packaged app).

Netbeans scala javadocs missing in Netbeans 8.0

I've been looking into scala lately and from the conciseness and language features I'm completely thrilled.
I have netbeans 8.0 running on ubuntu 12.04 and downloaded scala, edited netbeans.conf (netbeans_default_options="-J-Dscala.home=...), installed plugins from plugin manager inside netbeans (ALL OF THEM). Then, I created scala project (not maven one) and tried out autocomplete. It works, compiles, runs, however, it shows no document found in autocompletion.
This is how I added javadocs Tools > Scala platforms > javadoc tab
I tried adding following ways:
added the entire scala api doc zip from http://downloads.typesafe.com/scala/2.11.2/scala-docs-2.11.2.zip
extracted the previous zip to scala-home folder under $SCALA_HOME/docs/javadocs/scala-docs-2.11.2 and added that
same as 2 but added $SCALA_HOME/docs/javadocs/scala-docs-2.11.2/api in netbeans
None of these pick up documentation! Of course, I could live without it, but it's such a killer for such a concise language where I could just find out stuff instantly from autocompletion. Also, I don't want to use eclipse special ide for scala because I don't want to throw out all the experience with netbeans out of the window and learn new IDE.
P.S. - Netbeans navigator also seem not to work in scala.
And I wonder why there's so little content on google for such a wonderful language?
There is no need to change to IntelliJ. Use the right build tool -sbt or Maven- and everything works fine.
In Netbeans you can use e.g. free Application Servers.
Netbeans support for scala seems pathetic so I just decided to jump to IntelliJ IDEA. It was little bit of learning curve but I'm glad I did because now everything was working (autocomplete, documentation, awesome SBT support etc. etc.)

GWT Designer not working with Eclipse 4.2 service release 2?

I'm trying to do this tutorial after having installed Eclipse Juno 4.2 service release 2 (Java EE distribution) und following exactly the GWT installation instructions over here.
However, I neither get the WindowBuilder entry under Preferences, nor is there a WindowBuilder entry in the new projects dialog appearing. What am I doing wrong?
I'm running Ubuntu 12.04.02 LTS on amd64, and I have tried oracle jdk 7u17 and Ubuntu's own jdk6 distribution, but to no avail...
Just tried the same in Win2k3. Exact same result. Google is starting to annoy me. GWT 2.5.1 throws an error when trying one of my simplest projects...
Update: it is working to some extent. Meaning: WindowBuilder does not recognize GWT Designer's installation and offers to install GWT Designer for Eclipse 3.7. The designer toolbar's GWT selection possibilities therefore are not there.
Update: bug filed.
Update: bug was closed as won't fix. They don't care.
They do care. GWT is a magical development environment, under constant evolution.
They have to race with new versions of browsers, Javascript and releases of Eclipse, so sometimes tiny things may not be always documented up to date. The tutorial you are trying to run is made for GWT Designer 2.3, GPE 2.3, Eclipse 3.7 & Java 1.6.
This tutorial works also perfectly well for Juno 4.2 SR2 with a few minor changes:
In step 1, just Create a Web Application Project. You can generate project sample code, make sure that things work and then clean it up and stick with the folder layout.
In step 3, just add a class and make it extend com.google.gwt.user.client.ui.Composite. Add an empty Constructor and then you can open the GWT Designer as always, in order to do the rest. The CSS styleName property has been improved. There are tool-tips to guide you.
PS: My tests were made in Ubuntu12.04-32bit, WinXP-32bit and Win7-64bit with JDK1.7.0_17-32bit and Eclipse-32bit.
In case the designer tab does't show up by default, I noticed that I can get it by right-clicking the .java on the package explorer and selecting 'open with ...' 'WindowBuilder Editor'.

Netbeans: Error in loading component property: Other components->

And it continues:
mainPanel->panMain->border Cannot read property.
This is the result attempting to go from Netbeans 6.8 to Netbeans 7.0 and 7.1 and 7.2. the latter two don't support the Swing Application Framework and 7.0 won't let me build new projects so I am on a crusade to get back to 6.8 in order to support and maintain a large system in use by some very large companies indeed. I've asked some questions on the netbeans forums and gotten minimal response, only a small fraction of which was helpful.
stackOverflow, however, knows everything, which is why I'm here.
Can anybody help me figure out this error condition? I have been pounding on this for a week.
If my software didn't maintain some sort of backwards compatibility path, we'd have been out of business long ago.
Well it appears that this error is caused by building a project with a newer version of Netbeans and then trying to work on it with an older version. Lesson learned? Don't create a project with NB 6.8, build it with NB 7.0.x and then try to revert to NB 6.8 or 6.9 because of bugs in 7.0.x.
I had similar problem and I fixed it by activating "Java SE". For some reason when I installed Netbeans, Java SE wasn't activated. The way to activate is by going to Tools->Plugins->Installed and then check the Java SE box and then click on Activate. Restart Netbeans IDE. That's all folks and it worked for me.

Categories

Resources