• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exclude java.util.Currency from javac/build path  RSS feed

 
abhijatalok alok
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am using Ant for compilation and build, my borrowed code has its own xxx.Currency which needs to be refered throughout the code and not java.util.Currency.


"This is present, not in few files but throughout the source code.....i dont know how the ex-developer could have built it 4 years ago like that....."
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than trying to get Ant to remove some classes from your class path, why not attack it from the code - side, which is better practice anyway (you no longer would be dependent of the build system in order to get correct code).

Your problem is that you need to use xxx.Currency instead of java.util.Currency. There are two solutions:
1) Don't import java.util.Currency into your source files. This would include NOT doing this:

Instead import the individual classes from the java.util package you need:


2) Use a fully qualified class name whenever referring to Currency. The fully qualified class name is the name of the package + dot + the name of the class. So java.util.Currency or my.app.money.Currency. Example:


I always try to do the first option (don't import 2 classes with the same name) whenever possible, but there are times when I need to fall back to the fully qualified names as well.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhijatalok alok wrote:i dont know how the ex-developer could have built it 4 years ago like that....."


java.util.Currency was added in Java 1.4 - maybe (s)he was using an earlier version.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question clearly demonstrates why importing complete packages with *, such as

is not a good idea, and why it is better to import only the classes that you need from a package.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!