wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compile error:It is indirectly referenced > from required .class files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile error:It is indirectly referenced > from required .class files" Watch "compile error:It is indirectly referenced > from required .class files" New topic
Author

compile error:It is indirectly referenced > from required .class files

bill zhang
Greenhorn

Joined: Jul 08, 2009
Posts: 8
I couldn't get my application compiled.
1. I created an application called second.jar which imports first.jar. There is a method in second jar throws an exception implemented in first.jar.
2. And then I created another application called third.jar which imports second.jar.
3. There is a method in third.jar uses the method in second jar. Therefore, I need to declare the exception in first.jar in third.jar.
4. Error: compiler complains on the exception in first.jar 'The type ....Exception cannot be resolved. It is indirectly referenced > from required .class files'
Can someone give me any clue? Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Welcome to JavaRanch

Which compiler are you using?
You would need to import the classes in each .jar directly. A class in jar2 uses a class in jar1, and a class in jar3 uses that same class in jar2. You have to import it from jar1 into jar3.
Have you set up a classpath? You would need to use the -cp options for the java and javac tools.

Not sure what else to suggest. Sorry. But this question is too difficult for beginners. Moving it.
bill zhang
Greenhorn

Joined: Jul 08, 2009
Posts: 8
Thanks for your reply.
OK. I'll move the post to one level higher.
Since second.jar contains first.jar and I imported second.jar into third.jar, there ought to be a way that we can make first.jar visable in third.jar. I just wanna try to avoid importing first.jar to third.jar directly.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi Bill,

Jars can neither contain nor import other jars, so we actually can't understand what you mean. Can you talk in terms of classes and files? Classes can use other classes, so a class in one jar could depend on a class in another jar, and so both jars would be required at runtime. But you can't pack one jar file inside another (if that's what you're saying.) You need to have all the jars available directly on the file system. It's possible for one jar's Class-Path attribute to mention another jar file, but again, that second jar must be available as a file, not inside the first jar.

When you run an application that needs multiple jars, you can just specify all the jars on the command line:

java -cp a.jar;b.jar;c.jar com.me.MyClass


[Jess in Action][AskingGoodQuestions]
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Hello Bill,

If what Campbell understood of your post is correct, then it's ok else I didn't get what you mean by importing jars. If importing classes, you will have to import the classes based on the need.

If you do not want to import classes from jar 1 into jar 3 because you already imported them in classes of jar 2, then, sorry - can't be done!

If your classes in jar 1 or 2 are made such that the objects encapsulate those classes, then maybe.

Regards


Experience and talent are independent of age
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Ernest Friedman-Hill wrote:
When you run an application that needs multiple jars, you can just specify all the jars on the command line:

java -cp a.jar;b.jar;c.jar com.me.MyClass



Just to add, in case you are on UNIX:


bill zhang
Greenhorn

Joined: Jul 08, 2009
Posts: 8
Sorry about the confusion. I am using RAD. So I just used 'import' in my previous posts. What I did in RAD was: 1. I created First project and then export it as first.jar. 2. created Second project, and import first.jar into the project. When I export this project to second.jar, first.jar is included in second.jar automatically. So this is actually a wrong practice according to the previous posts, correct?
Thanks.
Anita Karacs
Greenhorn

Joined: Oct 17, 2013
Posts: 1
Dear bill zhang,

Some years passed since you faced this, and now I faced this issue too. How did you manage to solve this? I want to avoid importing first.jar to third.jar directly, too, but now I can't see any other solution, and I need that exception. I think the third program should only import second.jar, otherwise it is pointless. To make it clear I want to create my own mail sender API, and the third program requires the MessagingException, but I don't want to import mail.jar into my program.

Thanks for the replies!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Anita Karacs wrote:To make it clear I want to create my own mail sender API, and the third program requires the MessagingException, but I don't want to import mail.jar into my program.

Er...why not?

If that's where MessagingException is, I don't think you have much choice.

My advice: Back up and explain the problem, not the solution.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
GeeCON Prague 2014
 
subject: compile error:It is indirectly referenced > from required .class files