This is the problem:
import org.apache.commons.math3;
That's trying to import a package - you can't do that. You have to either use a wildcard import:
import org.apache.commons.math3.*;
or import a specific type:
import org.apache.commons.math3.SomeTypeHere;
In your case it sounds like you actually want:
import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;
I've tried a sample class with just that import and the jar file downloaded from Apache, and it works fine.
Answer from Jon Skeet on Stack OverflowVideos
Did you unpack that Apache JAR and add the .class files to your application? Why didn't you just add the JAR to your CLASSPATH?
You should not be depending on a CLASSPATH environment variable. Better to use the -classpath option for javac.exe when you compile and java.exe when you run.
Unless it's a typo, notice you said com\apache\commons\cli but the import wants org.apache.commons.cli -- org vs com
Try running the following commands and examine the output:
$ mvn dependency:tree
$ mvn help:effective-pom
Look for commons-lang, maybe something will draw your attention like excludes or dependency overrides. Also, is:
$ mvn dependency:copy-dependencies
copying commons-lang JAR to your target?
Adding following dependency to pom.xml in dependencies tag helped me:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
I was having same issue then realized that the version of commons-io getting picked up was lower than what I need (2.4)....I need to Override the already managed version as below to get the right one picked up:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
I also faced the same issue, but after adding dependency in pom error got removed.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
you can also refer URL http://zetcode.com/java/fileutils/
it started working now. I downloaded commons-io-2.4 from a different resource and imported to my project. Thanks
I had the same issue, solved by adding 'commons-io:commons-io:2.4' to dependencies in build.gradle:
dependencies {
testImplementation (
'commons-io:commons-io:2.4'
)
}
With few minute changes I am able to execute this code:-
CommandLineParser parser = new PosixParser();
Options options = new Options();
options.addOption("a", true, "First parameter");
args=new String[]{"-a abc"};
try {
CommandLine commandLine = parser.parse(options, args );
System.out.println(commandLine.getOptionValue("a"));
} catch (ParseException e1) {
e1.printStackTrace();
}
Output :- abc
In my pom.xml :-
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
commons-cli-1.2.jar is not visible to your code.
You need to pack the jar along with the dependencies.
Add this to the plugins tag in your pom.xml file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Your main class here</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
Then build your project with this command:
mvn clean compile assembly:single

