I tried out the JavaFX tutorial for Netbeans with Maven and got it running without a problem. Maven found the artifacts, downloaded them, build the project and started it. But I get no code completion (Missing sources and Javadocs).
I tried to download the sources and javadocs for the maven dependencies in Netbeans, but only the sources/javadocs for the wrapper artifacts (e.g. the empty javafx-controls-11) are available. But no sources are found for the actual implementation (e.g. javafx-controls-11-linux).
Where do I find the sources/javadocs and how do I add them to Netbeans?
There is an issue already filed about this at the OpenJFX docs.
While it hasn't been resolved yet, there is a possible workaround, based on:
NetBeans only adds javadoc/source jars for a jar with the exact same name and -javadoc/-source suffix
So here are the steps to solve it:
Install NetBeans 10 and JDK 11.0.2.
Clone the HelloFX sample for NetBeans and Maven, from the OpenJFX samples.
Update the JavaFX dependencies to 11.0.2.
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
Run it:
mvn clean compile exec:java
Check that the JavaFX dependencies have been downloaded to your local m2 repository. Under <user home>/.m2/repository/org/openjfx/javafx-base/11.0.2 for instance you will find javafx-base-11.0.2.jar and javafx-base-mac-11.0.2.jar (or win, or linux based on your platform).
Back on NetBeans, right click in the Dependencies folder and select Download Sources (see the task progress in the bottom right taskbar), and then Download Javadoc(see the task progress).
Go to your m2 repository and verify that there are now -source and -javadoc jar files.
However, this won't solve the issue yet, there is an extra step:
In your m2 repository, manually rename the -source and -javadoc jar files using your platform classifier, to -mac-source and -mac-javadoc (or win, or linux based on your platform). Do this for the different JavaFX modules:
Back to NetBeans, check that now you have JavaDoc, or if you press Ctrl/CMD+Click you can access the source.
Note that this fix has to be done only once, the rest of your Maven projects should pick JavaDoc and Sources.
Related
I am using Intellij IDEA 2021.3.1 Community edition on Linux for one of my Maven project. In the pom.xml file, there is a dependency with system scope having version 3.0-20211116.183306-362 as mentioned below:
<dependency>
<groupId>com.wd.xml</groupId>
<artifactId>wdXml</artifactId>
<scope>system</scope>
<systemPath>/home/mylib/wdXml-3.0-20211116.183306-362.jar</systemPath>
<version>3.0-20211116.183306-362</version>
</dependency>
The pom.xml does not have any issue, and mvn package command runs fine. However, the editor shows compilation errors in the Java class using this dependency.
Upon hours of digging, I found that in the 'Project Dependencies View' Intellij lists this dependency as com.wd.xml:wdXml:3.0-SNAPSHOT instead of com.wd.xml:wdXml:3.0-20211116.183306-362.
UPDATE
I believe it is because of this Maven convention
version if you distribute it, then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look. For example,
2.0, 2.0.1, 1.3.1
How do I resolve this? Is there any setting in the IDE that can be tweaked.
I am currently using Intellij Idea 2020.2.4.
I want to replace a dependency with a newer version of itself.
I replaced
<dependency>
<groupId>com.company.digital.fmk</groupId>
<artifactId>dgt-security</artifactId>
<version>2.6.24</version>
</dependency>
with
<dependency>
<groupId>com.company.digital.fmk</groupId>
<artifactId>dgt-security</artifactId>
<version>3.9.0</version>
</dependency>
I've checked that in the effective pom, the version has changed to the new value. However, after running
mvn -U clean install, when I click on a class from the dependency, it still shows the old version.
When I try to delete the old version from the project structure, it says that it is still used in a module, even though I can't find the old version number anywhere in the project.
I can't manually delete the old library from my local folder, because it is used in another project.
Other answers have suggested using Maven -> Reimport, but I didn't find this in my intellij
What can I do to make intellij use the new dependency version in my project ?
EDIT
When I right-click on a project and select Maven, here are my options:
Reload project (already tried, did not work)
Generate sources and update folders
Ignore projects
Unlink maven projects
Open 'settings.xml'
Create 'profiles.xml'
Download sources
Download documentation
Download sources and documentation
Show effective pom
Show diagram
Show diagram popup
You can go to your Maven repository:
.m2/com/company/digital/fmk
Delete jar files
Rerun command, it will download dependencies again.
Right click on project -> maven -> sync shall do the trick
previous versions did this by default on changes in pom.xml
now it seems to be not available anymore
I tried out the JavaFX tutorial for Netbeans with Maven and got it running without a problem. Maven found the artifacts, downloaded them, build the project and started it. But I get no code completion (Missing sources and Javadocs).
I tried to download the sources and javadocs for the maven dependencies in Netbeans, but only the sources/javadocs for the wrapper artifacts (e.g. the empty javafx-controls-11) are available. But no sources are found for the actual implementation (e.g. javafx-controls-11-linux).
Where do I find the sources/javadocs and how do I add them to Netbeans?
There is an issue already filed about this at the OpenJFX docs.
While it hasn't been resolved yet, there is a possible workaround, based on:
NetBeans only adds javadoc/source jars for a jar with the exact same name and -javadoc/-source suffix
So here are the steps to solve it:
Install NetBeans 10 and JDK 11.0.2.
Clone the HelloFX sample for NetBeans and Maven, from the OpenJFX samples.
Update the JavaFX dependencies to 11.0.2.
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
Run it:
mvn clean compile exec:java
Check that the JavaFX dependencies have been downloaded to your local m2 repository. Under <user home>/.m2/repository/org/openjfx/javafx-base/11.0.2 for instance you will find javafx-base-11.0.2.jar and javafx-base-mac-11.0.2.jar (or win, or linux based on your platform).
Back on NetBeans, right click in the Dependencies folder and select Download Sources (see the task progress in the bottom right taskbar), and then Download Javadoc(see the task progress).
Go to your m2 repository and verify that there are now -source and -javadoc jar files.
However, this won't solve the issue yet, there is an extra step:
In your m2 repository, manually rename the -source and -javadoc jar files using your platform classifier, to -mac-source and -mac-javadoc (or win, or linux based on your platform). Do this for the different JavaFX modules:
Back to NetBeans, check that now you have JavaDoc, or if you press Ctrl/CMD+Click you can access the source.
Note that this fix has to be done only once, the rest of your Maven projects should pick JavaDoc and Sources.
I'm trying to add Stanford CoreNLP 3.9.2 as dependency to my Eclipse/Maven project:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.9.2</version>
</dependency>
Next to my POM.xml file I see a little red x icon. When I open POM.xml there is no additional information regarding the error.
When I click on Java -> Properties -> Java Build Path -> Maven Dependencies I see that the Jars that were expected to be added to Maven via this dependency are missing. This is odd because I regularly add dependencies this way without any error.
Apparently, something is preventing Maven from downloading the dependencies. What could it be?
Update:
I changed POM file to version 3.5.2 (instead of 3.9.2) and now all errors are gone.
If anyone can explain WHY this solved my problem (and how to make things work with version 3.9.2) I will accept it as the answer.
Update:
When I go to my Maven repository I see that most of the required Jars have been downloaded by Maven. For example, Maven repository will contain the folders: \\maven\.m2\repository\edu\stanford\nlp\stanford-corenlp\3.9.2 However the folder will not contain the Jar: stanford-corenlp-3.9.2 - but it will contain every other Jar such as stanford-corenlp-3.9.2-models and stanford-corenlp-3.9.2-sources etc.
This makes the whole situation even more confusing. If Maven is downloading the Jars why is it skipping just one Jar? I looked in several other folders (dependencies of corenlp) and I see similar phenomenon - it's always the main Jar of that folder that is missing.
What's worse, when I download and add the missing Jars manually to Maven folder, the (missing) text next to Jar goes away but there's still a little red x icon next to POM file. I have no idea what is going on.
Any insights?
Thanks!
I have no idea why this fixed the problem but in my POM file I had an entry:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.debug.core</artifactId>
<version>3.13.0</version>
</dependency>
I update this dependency to:
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.debug.core</artifactId>
<version>3.14.0</version>
</dependency>
Now all errors have disappeared.
3 Questions:
Below are two maven dependencies for JUnit. I have been scouring the interwebs for hours and cannot seem to determine if the second one is Javadoc + code or only Javadoc. Do I need one or both? Further, what is the most effecient way to include Javadocs in a project for development yet not in the production build? (I would prefer not to manually download javadocs for every dependency on every machine.)
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<classifier>javadoc</classifier>
</dependency>
EDIT: Questions:
What is the difference between these dependencies?
Do I need both of
them to be able to use the dependency & have Javadoc on hand?
What is best practice for including Javadocs for development?
Generally Javadocs are not primarily used as dependency. Because these are neither required at compile nor runtime. It’s just to help the developer while developing or debugging.
Assuming using the java IDE Eclipse we can use the java docs as referenced. Following are the approaches we can associate the javadocs/sources with the respective jars.
1. If it’s non-maven project :
Download the javadocs jar or zipped file, whatever available and placed it in some directory.
Right click on the application project in the IDE Eclipse, click Properties and choose Java Build Path then select tab Libraries under the Java Build Path. Now expand the jar you want to link with java docs/source. Select the Javadoc location link and click on Edit button, a new window appears where we need to choose the javadocs jar path. Click OK and we have linked the javadoc/source with the respective jars.
2. If it’s a maven project
If we are using the Maven project then go to jar files under the Maven dependency under the project in Project Explorer view as shown below. Now right click on the jar file you want to add the Javadoc/source, choose Maven then click on Javadoc or Source you want to link with the project. Now IDE will automatically download the required javadoc/source and will link it with the respective jar in the project.
You can verify this by right click on the project in the IDE and click on Java Build Path and select the Libraries tab under the Java Build Path and then expand the desired jar, here when you click the Edit button you will see the linked path of the Javadoc/Source with the respective jar as shown below in the image.
3. If it’s Maven project and we are setting the default behaviour:
Eclipse will aquatically download the javadoc/source along with the main required jar at the starting.
By default setting instruction to Maven to download the Javadoc/sources for all the jars linked in the project.
Click Windows – preferences – select Maven and click the checkbox Download Artifact Javadoc as shown below
Now click on apply and save it and now when you create new Maven project , by default the Javadocs will get downloaded and linked with all the dependent jars in the project.
You can verify by right click on the project and Properties and under Java Build path can see the javadocs are linked with all the jars as shown below.
If your project is Maven project then It’s always best to use 2nd approach because by using this approach the IDE and Maven, takes care of downloading the correct version of the Javadoc/source and linked it with the relative jar as well.
Approach 3rd is bit costly because the javadoc/sources will be downloaded forall the dependent jars, may be you are not interested for javadocs/sources for all the dependent jars.
Generally speaking, your IDE will handle the resolution of javadoc for you in a maven project. This is assuming your IDE understands maven - e.g. netbeans, intellij or eclipse w/ m2e.
The second artifact is only the javadocs. The first artifact is the code. There's almost never a good reason to include the javadoc artifact as a dependency.
I stumbled upon this problem when I created a maven project in eclipse and neither javadoc nor source of my dependencies where attached to my project, and I wondered which dependency to add.
What helped me was adding
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
to my pom.xml. That way, you only have to use the first dependency, and maven/eclipse take care of downloading the second (which is, as pointed out in the other answer, only the javadoc).