Using Jsoup in Java - get not accessible - java

I'm trying to use Jsoup in a Java project. For this I have included the Jar File in Referenced Libraries. However, I keep getting 'The type org.jsoup.Jsoup is not accessible' error
The type org.jsoup.Jsoup is not accessible

You want to add a 3rd party lib to a Maven project, if I understand correctly, which is already answered here: Add a dependency in Maven
However, in your case, there is no need to install the jar in your local Maven repository as Jsoup is already available on Maven: https://mvnrepository.com/artifact/org.jsoup/jsoup/1.15.3
Don't forget to add requires org.jsoup; to your module-info.java.

Related

Using other plugins or dependencies from custom maven plugins

I have ended up in a situation where I need to create a Maven Plugin which as part of it's job needs to inspect a number of dependencies and find certain xml files.
(If anyone has a better way of reading files inside an artifact jar, please say so as that will very much also be considered an accepted answer)
I need to inspect a number of known dependencies that I have referenced as org.apache.maven.artifact.Artifact references and find all XML files within them. The only way I know of is to unpack the artifact and search though the file system. I basically need to do exactly what the Maven Dependency Plugin's "unpack" goal does. So how do I use the Maven Dependency Plugin from my own plugin? Do I simply use it as a normal Dependency or is there a more "maven" way of doing it?
EDIT:
I encountered another thing which is close enough to this one that I will update the question instead of posting a new one.
If I need to use an outside dependency, such as Jackson for example, how do I include the dependency for the plugin? It feels wrong to create a fat jar with the dependencies in it. Is there another trick I am missing?

How to download Gradle dependency from java code?

My Java application needs to copy artifacts from Artifactory to AWS S3 temp bucket on demand (application group, name and version will be passed as parameters at runtime). The simplest way would be constructing URL and downloading files directly from Artifactory, but application should support 'latest.integration' and 'latest.relase' versions. So I want to add Gradle binaries to the classpath and use it to download dependencies.
Google results overflown with questions about dependency management using build.gradle.
So far I saw https://discuss.gradle.org/t/execute-gradle-task-from-java-code/21859/4 but looks like it also relies on preexisting build.gradle file.
So the question is: is there any way to use Gradle API from Java application to download certain lib without generating build.gradle file?
You should be able to use Ivy (http://ant.apache.org/ivy/) either as is or as a library itself to accomplish what you need, possibly with a bit of additional code.
(answer created from my comments)

Incorporate javadoc URL for external jar dependency in Maven

I've searched for similar questions already asked, but most have been related to generating new java documentation using javadoc for all of the included dependencies.
My question is more basic - I just want to be able to view the javadoc documentation for an external library in Eclipse when using the "Ctrl+Space" or hovering over an object/method.
For example:
I have a dependency for the "commons-cli" library
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3</version>
</dependency>
By default though, I am not able to view the API documentation for the classes located in this library. I can do this manually, by using the Project Explorer to navigating to the "commons-cli-1.3.jar" file located in Java Resources->Library->Maven Dependencies and then specifying the URL (https://commons.apache.org/proper/commons-cli/apidocs/) for the javadoc in its property dialog box.
Is there a way to incorporate this information into the maven pom.xml file? That way, I don't have to do this manually for every dependency and also it works for anyone checking out my project to their own computer.
Thanks in advance.
Run mvn dependency:sources which downloads the sources for the libraries. Check Maven repo dir (normally ~/.m2 ) if you have sources there - there should be jar with the same name as the lib artifact but appended with -sources. Like this:
If this is the case and you still don't see the javadocs in IDE then you should setup your IDE to use Maven repo as a source for sources.

cannot access org.eclipse.core.runtime.IProgressMonitor

I've added org.eclipse.core.runtime-3.7.0.jar library to classpath. I'm using Maven to manage project's dependencies. I also tried adding related dependency to pom.xml of module but the word <dependency></dependency> turned into red. So I removed that. Basically, the problem was supposed to be solved when I added org.eclipse.core.runtime-3.7.0.jar file to classpath but it didn't. When I compile I get this error:
Error:(13, 8) java: cannot access org.eclipse.core.runtime.IProgressMonitor
class file for org.eclipse.core.runtime.IProgressMonitor not found
IProgressMonitor is in the org.eclipse.equinox.common plugin.
Note: org.eclipse.equinox.common and org.eclipse.core.runtime are Eclipse plugins and will generally not work in a plain Java program. They must be used by an Eclipse plugin or RCP.

Why I can't use a library in my Android project from Maven repository? How to write a correct pom.xml for this?

I want to use Jackson JSON parser library in my android project. I saw this library in Maven repository, but I don't know how to use it. I've downloaded sources from the Maven repository and Jackson jars and attached sources to jar, but in the logcat I saw error message NoClassDefFoundError. When googling I' ve read that I have to declare Jackson dependencies in pom.xml file.I' m a newbie in Java development so I don't know what all these means. And have some questions:
1.How to write pom.xml for the Jackson library
2.Where to put this pom.xml
3. Do I really need to install Maven if I just want to use the library.
4. What else I need to begin work with the library?
No, you do not need to write a pom file, unless you are using Maven for building (in which case you need it regardless of Jackson).
What you need are just Jackson jars -- there is more than one, since some projects only need some pieces. This page:
http://wiki.fasterxml.com/JacksonDownload
should show what you need, and where to get them from. If you are starting from scratch, I would strongly recommend using Jackson 2.1 (not 1.9). And then you most likely need 3 jars (jackson-annotations, jackson-databind, jackson-core) -- although minimal is just jackson-core, if you use so-called "streaming API" (low-level, highest performance, but more work).
The benefit of using Maven would be just that you can define logical depenendency (group and artifact id of jar), and Maven would resolve it to physical jar, as well as references to other jars.

Categories