I am trying to use EqualsBuilder in the apache commons library. So, I downloaded commons-lang3-3.1.jar from the apache site, and in Eclipse I configured my build path to add it to my set of libraries. I see it listed in my libraries, and if I hit cmd+shift+o it automatically adds this import:
import org.apache.commons.lang3.builder.EqualsBuilder;
However, when I run my application and try to use it, I get:
Could not find class 'org.apache.commons.lang3.builder.EqualsBuilder', referenced from method com.gnychis.awmon.DeviceAbstraction.Interface.equals
Is there something simple I'm missing, here?
Having in build path just satisfies compile time requirement
You need to add it to your project runtime also (If it is web-app, add it to lib folder)
In case you are using maven, add the following dependency to your pom.xml file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
Or if you ever need "lang" dependencies rather than "lang3", use this one instead:
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
Related
I have some code, its depend org.apache.batik.*. Many jars are necessary.I tried import this im my pom.xml.
<dependency>
<groupId>org.apache.batik</groupId>
<artifactId>org.apache.batik</artifactId>
<version>1.6.0-20070705</version>
</dependency>
So, That I found all jars I need have entered in project libraries.Following this.
Inside this jar that has a lib folder, That all jars I need are in there.
The problem is my code seems can not find some jar they need.
I can't sure if cause is the jar that I imported has a lib folder, and I found other maven jar's structure doesn't like this.
So thank if you can help me!
EDIT 1
I imported this successful, this dependency's type is 'pom', so I think my
code should can find those dependency they need, but in fact, it didn't work. I don't know why.
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik</artifactId>
<version>1.10</version>
<type>pom</type>
</dependency>
The artifact you are using is not directly usable in maven.
If you can use a more recent version (1.9, 1.10) of batik you can try this:
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.9</version>
<type>pom</type>
</dependency>
If not search on https://mvnrepository.com/artifact/batik
In the latter case it seems you need to add each dependency one by one
Define dependencies for all jars you use in your source code. This usually means all jars from which you import at least one class in your source code.
Run clean package with Maven.
If you have errors, check if dependencies are missing.
If you get stuck, try a new question on Stackoverflow.
I'm trying to use the copyInput method in my code, but seems like Intellij told me that the method does not exist
FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile);
I'm using the code from here
http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/
But it seems like the method exist here
https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html
I'm using maven, I tried with 2.0, 2.1, 2.4 without luck
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
</dependency>
Java 1.8
Here is the error message
Error:(201, 22) java: cannot find symbol
symbol: method copyInputStreamToFile(java.io.InputStream,java.io.File)
location: class org.apache.commons.io.FileUtils
You probably have another (older) org.apache.commons.io.FileUtils on your classpath, which would explain the issues you're having. Most likely one of your dependencies has an old org.apache.commons:commons-io artifact on the classpath. Due to the groupId difference, Maven considers them different artifacts and puts both on the classpath.
If that is what's really happening, you can explicitly forbid maven from including this transitive dependency by adding an exclusion to the dependency that references the old commons-io (even if it depends on it transitively):
<dependency>
<groupId>offending.artifact.groupId</groupId>
<artifactId>offending.artifact.artifactId</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
I was able to see the wrong version using the menu options "To find the offending class in IntelliJ IDEA: Menu > Navigate > Class > type FileUtils", there were like 4 FileUtils,
I imported the correct version on the jar file and it fix the problem, Thanks #Anton.
FileUtils.copyInputStreamToFile(inputStream,file);
This function may be used in versions larger than two (2). You need to add this line to the gradle:
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
I got the same problem, but it seems that I had old version of version of commons-io. I fixed it by changing version to 2.6 in pom.xml file.
I'm new to Maven and I'm trying to build a project for the first time. I want to write some code that depends on apache lucene. Here's a list of artifacts in maven that I'm trying to get.
Is there any way instead of explicitly listing each artifact, I could simply depend on all artifacts of a given version? I tried this:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>*</artifactId>
<version>3.6.1</version>
</dependency>
which gave me the error
'dependencies.dependency.artifactId' for org.apache.lucene::jar with value '' does not match a valid id pattern. # line 19, column 19
I can verify that I can download dependencies when I explicitly state them. IE this works fine:
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>3.6.1</version>
</dependency>
I realize depending on everything in lucene is probably sub-optimal, but for doing something quick-and-dirty I'd hate to have to manually populate all these little lucene libraries. What is the typical practice for getting a large set of related dependencies in maven?
Short answer: you can't. Remember you just do this once and later you can simply copy-paste dependencies (not very DRY though). Also consider creating an archetype that will quickly create a skeleton with all required dependencies (for quick and dirty projects).
Longer answer: well, you can work around that. Create a separate pom.xml with:
<packaging>pom</packaging>
and declare all Lucene dependencies there manually, one after another. Once and for all. Later you can simply add a dependency to your pom.xml (that is to groupId/artifactId/version defined there) which will transitively include all dependencies of that pom.xml.
Talking about transitivity: if you depend on a JAR in maven and that JAR has other dependencies, you get that transitive dependencies implicitly. Examine Lucene poms, maybe it's enough to import few of them and rely on transitive dependencies?
Inside a single dependency for a groupId add different artifactId's
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<artifactId>spring-context</artifactId>
<artifactId>spring-beans</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
I am confused by the Jersey Documentation Chapter 6
http://jersey.java.net/nonav/documentation/latest/linking.html
The configuration section (6.5) doesn't say where to add the dependency etc. What file(s) need to be edited?
I am confused what I need to do all together in order to use the #Ref attribute in my code.
EDIT/UPDATE
How do I use Jersey Hyperlinking without Maven. I've grabbed the jar file jersey-server-linking-1.9-SNAPSHOT.jar but I don't know what it depends on. Can some one give me a list of jars I need to get this working?
The dependency appears to be a maven dependency, So you'd put it in the typical maven configuration files, I'm not all that familiar with maven. This is really to make sure the Jersey linking module libraries are included in your application.
The rest of the code samples in that section refer to modifications you need to make to web.xml.
From the Jersey Hyperlinking POM,
here's the list of dependencies you need at runtime:
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
I recently am trying open JDK, for obvious reasons the SUN libraries are not included as part of the openJDK runtime.
I am wondering what I have to add to my POM file to use mavin to include the SUN libraries.
Currently in my environment I am using the following annotation.
package com.sun.xml.internal.txw2.annotation does not exist
#XmlElement
If this is javax.xml.bind.annotation.XmlElement then you need to add dependencies to either JAXB or java-ee API.
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
Or
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
Both should be available on Maven Central. Note that the API dependencies will let you compile your code, but if you have any unit tests that actually use JAXB you'll also need to declare dependencies on an actual JAXB implementation.
You can try downloading the JAR containing the required classes and importing external dependencies into your project, but it will explode if the project is embedded on a continuous integration server.