0

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 intellisense for the word WordUtils Eclipse auto puts the import statement at the top of the file.

I get 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 

Thanks

2
  • What IDE are you using? (eclipse, netbeans, intelliJ, ...) What steps have you taken to get the jar in your project? These clarifications can help get you an answer. Commented Dec 31, 2008 at 16:35
  • oops, I see eclipse in there now, my bad, still would be useful to know what steps you've taken Commented Dec 31, 2008 at 16:36

8 Answers 8

4

That is correct java, and correct use of the WordUtils function. This is likely an eclipse issue. I'd check that the jar is imported and is on the compile path.

Sign up to request clarification or add additional context in comments.

Comments

1

Go into your project properties and under Java Build Path (I think) you need to add the commons jar as an External Jar, this is pretty straight forward once you find the right tab in the properties, once there you'll be able to browse to where you downloaded the jar and add it, that should clear up your problem.

Comments

1

When you get the compiler error, where are you getting this? Is this when you try to compile your source on the command line? If so, then you need to make sure that jar is either set in your CLASSPATH variable or used on the commandline or added to your build.xml or set for whatever mechanism you're using to compile the class.

Comments

1

Ah fantastic, that was the one Suppressingfire, thanks.

I was compiling via command line. I still need to learn about ant. Am used to php, its a lot simpler to start off with!

Comments

1

Thanks everyone. The class is in the build path.

I've pasted the class I'm using below (minus some unnecessary bits).

As I said Eclipse adds in this import statement.

import org.apache.commons.lang.WordUtils; 

Do I still need this if I have downloaded the JAR?
btw: I haven't taken classpath 101, I'm just figuring it out as I go along, completely 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 Comment

I cleaned this up for you, but really it's not an answer. You should add any extra information to the question instead.
1

If you are using ant script to build your code in eclipse, check if the classpath is also mentioned in the build.xml file. You can use something like this under 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 Comment

This should be comment not answer.
0

This is classpath 101. The JAR containing that class isn't in the build path. Easy enough to add in Eclipse: right click on project properties and it should be in the list. of choices.

Comments

0

You don't ever "need" to use a single import. All it does is save you typing: you can type "WordUtils" instead of "org.apache.commons.lang.WordUtils" whenever you want to use the class.

If you're still having the issue, it says the class is NOT in the build path and you still have to figure out how to get it there.

Comments