I'm trying make a project using Jsoup library.
I imported the library using maven.
My problem is when I have start to code using Jsoup classes and methods, eclipse don't show me anything available to import and to use from "org.jsoup"
I've already used Maven update project but my project has all dependencies placed right.
Someone got this problem too and could help me?
That is my current pom.xml on dependencies section:
<build>
<finalName>crawler-api</finalName>
</build>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
and my project libraries screenshot:
project libraries
Well. After some struggles I will leave some details about what I did to solve my problem.
Unfortunately for some reason if you try add Jsoup library from maven repository I can get the classes and methods from the api.
I found some comments on github from people who said that the only solution for that is including the jars into your project. What sounds a bit old fashion.
Well. Let's get started.
First, create a folder called lib into src/main/webapp/WEB-INF/ and have included the jsoup .jar that I have downloaded from the official web site.
After that I've added into pom.xml on dependencies section the follow child tag.
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/jsoup-1.11.2.jar</systemPath>
</dependency>
So when I've started code my app using the classes and methods from the api everything seems available when I called. And after that when I built my artifact using maven the dependencies has been available inside my artifact.
I really hope this could help someone. And I hope that the developers of Jsoup somehow fix that.
Related
I'm using the following Maven dependency for the auth0 jwt library for Java:
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
When I try to import the package in a Java servlet like this:
com.auth0.jwt
the auth0 isn't recognised, and I get the message Cannot resolve symbole 'auth0'
I've tried different versions of the dependency, and also cleaning and rebuilding the project, and closing and opening IntelliJ, but it still isn't recognised.
I've also looked at the auth0 Java quickstart, which suggests that for a Java servlet I may need to use these Maven dependencies:
<dependency>
<groupId>com.auth0</groupId>
<artifactId>mvc-auth-commons</artifactId>
<version>1.+</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
I'm already using the 2nd one (for the servlet-api). The com.auth0 dependency isn't recognised at all though, as a valid dependency.
What can I try in order to import com.auth0.jwt?
I tried the same dependency in a Google Cloud Endpoints project:
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
I could then import com.auth.jwt. I'm guessing that the library only works inside an Endpoints API.
I'm trying to upgrade an application to Java 11.0.2, from Java 8. So those are my very first steps with Jigsaw modules!
My application uses Guice, and the Assistedinject, and Throwingproviders extensions.
Here's my current module-info.java:
`
module com.example.mymodule {
requires com.google.guice;
requires com.google.guice.extensions.assistedinject;
requires com.google.guice.extensions.throwingproviders;
//...
}
`
The application is based on Maven and when I run mvn package I get no error. But In Eclipse (2018-12), I have this error "`The package com.google.inject is accessible from more than one module":
I tried commenting each of the required module in module-info.java but I clearly need the three of them.
Is there something I can do to remove this error? Or is this an Eclipse bug?
Here's my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-throwingproviders</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>
Here is a minimal project to reproduce my error.
And here's a video of the issue (to be watched in 1080P for clarity!).
Eclipse uses its own compiler which is even stricter than javac in following the specs. You are requiring different Modules/Jars in your module-info which are all using the package com.google.inject. This is some kind of a split package situation which is not allowed in the JPMS spec. AFAIK javac only yields an error if there are actual classes in the same packages of different moduls, but the eclipse compiler is even more picky here.
There are some solutions out there for solving split package problems. If you don't find a newer version of the libs where the problem is solved (which unfortunately is not very likely for most dependencies today) you could f.e. merge the modules into one custom modules, but this is not a perfect solution of course.
For more background information on the issue see also
Eclipse can't find XML related classes after switching build path to JDK 10 and https://bugs.openjdk.java.net/browse/JDK-8215739
I can reproduce the error on my machine (same Eclipse version, OpenJDK 11), works fine on Apache NetBeans IDE 10.0.
Seems to be a bug in Eclipse, you should file it here. You already have a minimal project that reproduces the error, that helps a lot.
Your test project already works in RC2 of 4.11 (which will be released on March 20, 2019)
You can download the release candidate at https://download.eclipse.org/eclipse/downloads/drops4/S-4.11RC2-201903070500/
Better way to deal with this kind of problem by just go to dependencies hierarchy in pom.xml, where you can find duplicate jar, sometimes it could be difficult to find duplicate jar as jar itself have pom dependencies and "Dependencies hierarchy" will help you to deal with maven problem
`
Using Intellij IDEA (version 2017.2.1) I have a Java/Maven project in which I want to include slf4j with the slf4j-binding.
I know that StackOverflow as an abundance of questions about slf4j and its missing binding, but most refer to Eclipse. My problem however occurs under Intellij.
In the pom.xml I list under <dependencies>:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
Now when I let Intellij build an artifact JAR and I then run the JAR from the command line I get the (dreaded) error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
Upon inspection the JARdoes indeed not contain slf4j-simple classes (slf4j classes are present though). How can I fix this and instruct Intellij to incorporate slf4j-simple as listed ion the pom.xml?
For completeness, here full project pom.xml Intellij is using:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.gov.acic.travelalert</groupId>
<artifactId>extract-data</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency> <dependency>
<!-- jsoup HTML parser library # https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.3</version>
</dependency>
</dependencies>
</project>
Final note: At the beginning when I set up the project logging didn't even work inside the IDE, despite the correct entries in the pom.xml. But somehow, after additionally adding (and subsequent removing) of a dependency entry for slf4j-log4j12, the IDE picks the slf4j-simple up, but still does not bundle it when writing out the artefact JAR...
execute mvn dependency:tree and check:
slf4j-api and slf4j-simple must be present there.
No other slf4j binding library shoud be present
slf4j bridges can be present (those that end with "-slf4j" suffix on library name; for example, log4j-over-slf4j).
ensure all slf4j library versions match
ensure no duplicate slf4j libraries with different version.
If all of this is ok, no reason for slf4j-api present on artifact but no slf4j-simple. What are you doing to package jar?
The problem is that IntelliJ's XML configuration for the JAR artifact does not contain the slf4j-simple library.
This explains that IntelliJ finds the lib ray (downloaded according by maven according to the `POM/XML~) and uses it for internal execution of the project, but it does not pack it into the JAR.
The solution is to add the libarary to the XML config, either
manually, by editing the XML file. (You find it under [projectroot].idea/artifacts/[projectname_jar.xml)
or
via IntelliJ's GUI, by opening the Artifacts dialog (File --> Project structure --> Artifacts) and then adding the Libra to the Output Layout list.
you can try this solution; go to home directory and delete the .m2 directory(hidden) the update the maven project and try to rebuild. and also check your eclipse version if you are using (Indigo, Juno and Kepler ) version of eclipse the upgrade with latest version or stil if you want to work in it then you can refer below like; this stackoverflow link having most sutable answer on this issue:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error Question by Konstantinos Margaritis and answer by many java experts.
In the pom.xml, i include logback & SLF4J like below, this works perfectly fine using maven build. It will give compilation error if i import directly from logback.
<dependencyManagement>
<dependencies>
<!-- We want to have slf4j with scope compile -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- logback we only want runtime, compiletime we want SLF4J -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
But how can I make eclipse honor the runtime scope of logback dependency and prevent import-suggestions from there?
Unfortunately it seems not to be possible on Eclipse with a normal build, as mentioned by #A4L, it is a known bug, check Bug 414645 and Bug 376616. Eclipse (m2e) can't properly manage Maven dependencies scope.
However, if you place the runtime dependencies on a profile, then Eclipse will not add them to the classpath (the profile shouldn't be active by default, though). I just tested it on Eclipse Mars and it works perfectly.
Hence, in your case you could add to your POM:
<profiles>
<profile>
<id>runtime</id>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
As such, it can't be used to compile on Eclipse. However, your build would then need to use it at runtime, running with -Pruntime in this case.
Although adapting your POM and build to an issue of an IDE might not be ideal, it could be a good compromise to achieve your goal.
I'm following a tutorial on Vogella on how to work with JAX-RS to create RESTful web applications.
The trouble for me is that I am not able to import the dependencies through Maven. Is it possible?
When I try finding jsr311 or javax.ws.rs as suggested here, Maven doesn't seem to know it exists.
If you are satrting your project from scratch, it would be better to let maven generate your project for your using one of the Maven Archetypes that Jersey provides (More in the Jersey getting-started page) then you can easilly add the eclipse nature to the generated project using below command:
mvn eclipse:eclipse -Dwtpversion=2.0
Choose your suitable Web Tool version, then import that project into your Eclipse IDE.
This method, will leave you out of poviding any dependencies related to Jersey as those are already mentioned in the archetype descriptor.
Otherwise, if you are already working on a project and you want to add the RESTful features (which assume is not true since you mentioned that you are following a tutorial), you will have to provide dependencies to Jersey yourself. All dependencies can be found in Maven Central Repo but you would only need the jersey-server one:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18.1</version>
</dependency>
As #Gimby stated, there is absolutely no sense in declareing the jsr311-api alone, only if you are intending to provide a JSR implementation :)
please try as following:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
Ended up finding a similar question here.
Solved the problem by manually adding the dependency under pom.xml:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
foun it on : (http://mvnrepository.com/artifact/org.glassfish.jersey.archetypes/project/2.22.1)
it will work inchalahh ;D
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.22.1</version>
</dependency>