Using Jsoup library on eclipse [duplicate] - java

I have just recently started using Eclipse and am running into problems trying to install external libraries. Following online tutorials, I add the .jar file to the classpath and I see it in the referenced libraries folder. Despite this, when trying to import, I get the error:
The package org.apache.commons is not accessible
For reference, I am trying to install the apache math commons library.

Your code probably has two issues.
First, the import statement is wrong since in Java you cannot add a package itself, but all classes of a package as follows (note .*; at the end):
import org.apache.commons.math4.linear.*;
or a specific class, e.g.
import org.apache.commons.math4.linear.FieldMatrix;
Second, you use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9 and you have Java 12.
Do one of the following:
Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

Related

How do I resolve "the type is not accessible" error in Eclipse when using an external JAR? JAR in question is algs4 from Princeton [duplicate]

I'm new to the whole programming stuff but here's my problem:
I used to add my JUnit test cases in Eclipse by right clicking on the project, and just add New > JUnit Test Case.
Currently, I am not able to implement any test methods because Eclipse tells me on the line
import static org.junit.jupiter.api.Assertions.*;
the error message
The type org.junit.jupiter.api.Assertions is not accessible.
Error I get in the IDE:
I tried the following:
Reinstalling Eclipse, using a fresh workplace.
Adding the JUnit to Build path
Nothing helped.
It worked and works in older projects just fine.
Here is how the Package Explorer looks:
What am I missing?
You use the Java Platform Module System (JPMS) by having a module-info.java file in the default package probably without the required requires <module>; statement. JPMS was introduced in Java 9.
Do one of the following:
Delete the module-info.java file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java)
In module-info.java add the corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)

How do I set up extJWNL in a Java project?

I am trying to determine whether a set of strings, from an English sentence, are all words from the WordNet dictionary. I put the JARs in a folder in my project in eclipse.
I've downloaded the binary release of extJWNL and put the JARs in a folder called lib.
I also added these jar files to the class path and the module path using Right Click > Build Path > Configure Build Path:
I used the following code to try to import dictionary
import net.sf.extjwnl.dictionary;
This error is shown on the import statement
The package net.sf.extjwnl.dictionary is accessible from more than one module:
<unnamed>, extjwnl
I thought that this error was showing up because it was a package, not a class/type. But adding a new class and trying to change the package doesn't show this new package, namely WORDNET_JARS, just the default package.
Why is this error being returned and what do I need to do to get rid of the error and import the wordnet packages?
Platforms
I am using Eclipse IDE, and write all this code in Java. The API I am trying to import is the WordNet API.
Edit (8/21/2019)
By removing the module path, it gives a new error:
Only a type can be imported. net.sf.extjwnl.dictionary resolves to a package
I'm surprised it was this easy:
Instead of
import net.sf.extjwnl.dictionary
I had to do
import net.sf.extjwnl.dictionary.*
to get all the types. The only other thing that had to be done had already been done where I add the JARs to the class path

Unable to use apache commons ftp import

I've been trying to create my own FTP client written in Java. I wrote one ages ago in C#, so I would like to try in Java. I created a user library for apache commons and added it to my build path. The problem is that when typing the import statement it doesn't recognise it. It finds a error at org, saying "import org cannot be resolved".
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
I am using eclipse as my IDE.
Here two screenshots showing the error:
The following line is probably missing in the module-info.java file:
requires org.apache.commons.lang3;
and in the Java Build Path the Classpath contains the broken (as you can see from the red error mark) item apache-commons-lang by mistake: select it and click Remove.
Since Java 9, modules can be specified, but this requires a correct module-info.java file and the libraries must be added to the Modulepath instead of to the Classpath. Without the module-info.java file it would be easier. Therefore, perhaps the simpler solution would be to delete module-info.java file.
In addition, the *-source.jar should be as Source attachment a child of the main JAR and the *-javadoc.jar is not needed with the source (but if, then as Javadoc location child of the main JAR).
Hint: If an error or a warning is shown with a light bulb, go to the line and click Ctrl+1 and Eclipse will suggest solutions for that problem.

Can't import class from jar file although it's visible among IntelliJ External Libraries

Like screenshot shows. I have project party-management that uses common-lending-lib. common-lending-lib then uses math2 library.
When I open common-lending-lib project, it can easily detect math2 dependency and use it.
When I open party-management-project, it can detect common-lending-lib, and math2, but during runtime, it fails on functionality that common-lending-lib takes from math2.
What can be the reason? These projects are in Spring Boot, if it matters at all. I use IntelliJ 2017.1.5 and Java 1.8
Can package name be the reason? I have:
party management in org.kd package
common lending lib in org.kd package
math2 in org.kd.math package
Details of the project can be found on https://github.com/LendingBusiness

Integrating a Java Class into a PyDev Project (Jython) in Eclipse

I have a Java class that i would like to import into my Jython script. Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. How do I rectify this? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). Thank You !!!!!!!
What you can do is to create second module which would be java project. Anyhow, logically it should be that way. Please check out other similar question - PyDev: Jython modules & Java classes in the same project.
Other links that might help - http://pydev.org/manual_101_project_conf2.html
So what nefo_x suggested is correct. You need to create a new Java project that will contain your Java class. Then import the Java package as you would a python module. But there are a few things to watch out for in eclipse to make it work. I list the whole process below:
Your Java class (or classes) should not be in the default package. You need to create a new package and make/put your java class files there.
Export the package as a jar file to some place on your computer.
Add the jar file (located at some place on your computer) to your python path.
Import the package by writing "import PackageName".
The problem for me was that I had my java class in the default package. That does not work due to some naming issues. Anyhow, hope that this helps.

Categories