Ant: ftp error due to NoClassDefFoundError

I have been following some source code example, but I am getting an error while completing the ftp task. Here is my build.xml file:

?xml version="1.0"?> <project name="HelloWorld" default="deploy"> <target name="init"> <mkdir dir="build/classes" /> <mkdir dir="dist" /> </target> <target name="compile" depends="init"> <javac includeantruntime="false" srcdir="src" destdir="build/classes"/> </target> <target name="doc" depends="init"> <javadoc destdir="build/classes" sourcepath="src" packagenames="org.*" /> </target> <target name="package" depends="compile,doc"> <jar destfile="dist/project.jar" basedir="build/classes" /> </target> <taskdef name="ftp" classname="org.apache.tools.ant.taskdefs.optional.net.FTP"> <classpath> <pathelement location="/usr/local/ant/lib/ant-commons-net.jar"/> </classpath> </taskdef> <target name="deploy" depends="package"> <ftp classname="org.apache.tools.ant.taskdefs.optional.net.FTP" server="${server.name}" userid="${ftp.username}" password="${ftp.password}"> <fileset dir="dist" /> </ftp> </target> </project> 

Here are a few settings:

 $ ant -version Apache Ant(TM) version 1.9.0 compiled on March 5 2013 $ echo $ANT_HOME /usr/local/ant $ ls -l $ANT_HOME lrwxrwxrwx 1 root root 17 May 20 11:54 /usr/local/ant -> apache-ant-1.9.0/ 

Here is the result with the error I get. I thought ant build files should be portable. What is the problem? Somehow the FTP task "Ant" is looking for a class name that comes from a class that is not distributed with ant. I tried specifying a class task distributed using ant, but ant does not seem to find the corresponding class to the ftp task it is looking for.

 Buildfile: /home/johndoe/ex/build.xml init: compile: doc: [javadoc] Generating Javadoc [javadoc] Javadoc execution [javadoc] Loading source files for package org.example.helloworld... [javadoc] Constructing Javadoc information... [javadoc] Standard Doclet version 1.7.0_21 [javadoc] Building tree for all the packages and classes... [javadoc] Building index for all the packages and classes... [javadoc] Building index for all classes... package: [jar] Building jar: /home/johndoe/ex/dist/project.jar deploy: BUILD FAILED /home/johndoe/ex/build.xml:30: Could not create type ftp due to java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClientConfig at org.apache.tools.ant.taskdefs.optional.net.FTP$LanguageCode.getValidLanguageCodes(FTP.java:2698) at org.apache.tools.ant.taskdefs.optional.net.FTP$LanguageCode.<clinit>(FTP.java:2694) at org.apache.tools.ant.taskdefs.optional.net.FTP.<init>(FTP.java:137) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.apache.tools.ant.AntTypeDefinition.innerCreateAndSet(AntTypeDefinition.java:328) at org.apache.tools.ant.AntTypeDefinition.createAndSet(AntTypeDefinition.java:274) at org.apache.tools.ant.AntTypeDefinition.icreate(AntTypeDefinition.java:219) at org.apache.tools.ant.AntTypeDefinition.create(AntTypeDefinition.java:206) at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:285) at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:263) at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:417) at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163) at org.apache.tools.ant.Task.perform(Task.java:347) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) at org.apache.tools.ant.Project.executeTarget(Project.java:1364) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1248) at org.apache.tools.ant.Main.runBuild(Main.java:851) at org.apache.tools.ant.Main.startAnt(Main.java:235) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ftp.FTPClientConfig at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 26 more Total time: 2 seconds 

Ideally, I don't need to load other classes to work with ant. It should work out of the box, otherwise it is not tolerated. Also, if someone could help me with where to download classes that are missing, this will be of great help.

Thanks.

+6
source share
5 answers

I was able to solve the problem by downloading commons-net-3.2-bin.tar.gz from http://commons.apache.org/proper/commons-net/download_net.cgi and installing commons-net-3.2.jar in the / usr folder / local / ant / lib.

Sincerely.

+14
source

According to https://ant.apache.org/manual/Tasks/ftp.html , you need to install Apache Commons Net and Jakarta Oro.

Copy these jars to the \ lib directory, as Jason Posit said.

If you use Eclipse, you may need to update the Ant build path. Go to Settings> Ant> Runtime> Add External JARs to add these libraries to your Ant path.

+1
source

If you are using a Debian Linux or Raspbian distribution on a Raspberry Pi, you can simply solve this problem by doing:

 sudo apt-get install libcommons-net-java 
0
source

There was the same problem. This happened to me when I used ant -1.9.1 instead of ant -1.8.2.

The inclusion of the ant version is fixed.

0
source

Steps that worked for me

Go to the folder where Jenkins is installed

 jenkins>>tools>>hudson.tasks.Ant_AntInstallation>>(ANT VERSION Installed)>>lib 

place the files below and restart Jenkins

  • Total Net 3.3.jar
  • Total Net 3.4.jar
  • Jakarta-oro.jar
0
source

Source: https://habr.com/ru/post/945797/