Java cannot find symbol compilation error

new to Java. I want to use the org.apache.commons.lang.WordUtils package. Tried importing it. Tried downloading it and adding it to my build path. When I use word intellisense WordUtils

, Eclipse automatically puts an import statement at the beginning of the file.

I am getting the following error when compiling:

ConvertToUrl.java:3: package org.apache.commons.lang
import org.apache.commons.lang.WordUtils;
                              ^

ConvertToUrl.java:36: cannot find symbol
symbol: variable WordUtils
location: class d6.common.ConvertToUrl
                url = WordUtils.capitalizeFully (url);
                      ^
2 errors

And when I remove the import statement at the top, I get:

ConvertToUrl.java:34: cannot find symbol
symbol: variable WordUtils
location: class d6.common.ConvertToUrl
                url = WordUtils.capitalizeFully (url);
                      ^
1 error

thank

0


source to share


8 answers


This is the correct java and correct use of the WordUtils function. This is probably an eclipse problem. I would check that the jar is imported and is on the compilation path.



+4


source


Go to your project properties and in the Java Build Path (I think) you need to add the commons banner as an external Jar, it's pretty straight forward, once you find the tab you want in the properties, once you can view where you downloaded the jar and add it which should fix your problem.



+1


source


Thanks everyone. The class is in the build path.

I pasted in the class I am using below (minus the unnecessary bits).

As I said, Eclipse adds an import statement to this.

import org.apache.commons.lang.WordUtils;

      

Do I still need this if I downloaded the JAR?
btw: I didn't choose classpath 101, I just get the way I go, brand new to Java.

package d6.common;

public class ConvertToUrl {
    private static String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        url = WordUtils.capitalizeFully(url);
        this.url = url;

    }
}

      

Thanks for the help!

+1


source


When you get a compiler error, where are you doing this from? Is this when you try to compile the source on the command line? If so, then you need to make sure the jar is either set in your CLASSPATH variable, used on the command line, added to your build.xml file, or set to whatever mechanism you use to compile the class.

+1


source


And fantastic, it was the only suppressive fire, thanks.

I was compiling via command line. I still need to learn about ant. I'm using php, it's much easier to start with!

+1


source


If you are using ant script to build your code in eclipse check if classpath is specified in build.xml file. You can use something like this in the javac tag in your build file. Where pathelement here is the dependent library:

<target name="compile" depends="init" description="compile the source " >
    <javac srcdir="${src}" destdir="${classsfiles}" >
        <classpath>
            <pathelement path="${libdir}/common-io.jar"/>
            <pathelement path="${libdir}/xerces.jar"/>
        </classpath>
    </javac>
</target>

      

+1


source


This is classpath 101. The JAR containing this class is not in the build path. Easy enough to add to Eclipse: right click on project properties and it should be listed. options.

0


source


You will never need to use one import. All you need to do is save the text: you can type "WordUtils" instead of "org.apache.commons.lang.WordUtils" whenever you want to use the class.

If you still have a problem, it says that the class is NOT in the build path and you still need to figure out how to get it.

0


source







All Articles