Mouhammed Soueidane
Mouhammed Soueidane

Reputation: 1066

Can't create object from custom class

I have a problem instantiating a class that's inside a custom jar file. The problem is that the project that contains this class, is being able to use the class, but once I build a jar out of the project, and try to use this jar in another project, I'm not being able to instantiate it.

for instance, this code:

System.out.println("Reached here 1"); CustomClass customClass=new CustomClass(); System.out.println("Reached here 2");

Wouldn't create the object, and wouldn't get print "Reached here 2". The other problem is that I'm not supposed to handle exceptions in this class just 'cause I'm not intending to change an earlier design.

Any suggestions?

Upvotes: 1

Views: 2734

Answers (4)

Mouhammed Soueidane
Mouhammed Soueidane

Reputation: 1066

The problem wasn't in the .jar file itself. It was in the setup of my project. I should have included the .jar file in the ext folder inside the java directory which I didn't do. Thanks a lot for everyone's help.

Upvotes: 0

Costi Ciudatu
Costi Ciudatu

Reputation: 38195

Assuming you get no error messages (and you dont do some catch (Exception e) {} in your code), as the "Reached here 2" is never printed, one thing I'd check would be whether the constructor of CustomClass simply wait()s for some notification and blocks the thread.

Try to spawn a different thread providing it with a Thread.currentThread() reference and then try to interrupt() the thread that's running the constructor after a timeout...

Upvotes: 0

MJB
MJB

Reputation: 9399

try {
   System.out.println("begin");
CustomClass customClass=new CustomClass();`
} finally {
   System.out.println("done");
}

If that doesn't print "done", your class is hanging during initialization. So give us more then. Like the class code :)

Upvotes: 1

karmakaze
karmakaze

Reputation: 36154

It might be helpful to at least see what the exception exactly is without handling it:

try {
  System.out.println("Reached here 1");
  CustomClass customClass=new CustomClass();
  System.out.println("Reached here 2");
}
catch (Exception e) {
  e.printStackTrace();
  throw e;
}

Upvotes: 1

Related Questions