Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"So it appears that the JVM needs all Exception classes to be defined when the program starts running, and not when they're needed" - no, I don't think this is correct.</p> <p>I'm betting that your problem is due to these potential errors on your part, none of which have anything to do with the JVM:</p> <ol> <li>You're missing a package statement at the top of your MyException.java file. It looks like you meant it to be "package dynamictestjar", but it's not there.</li> <li>You did have the correct package statement in your MyException.java file, but when you compiled you didn't end up with the MyException.class file in a folder named "dynamictestjar".</li> <li>When you packaged your code into DynamicTestJar.jar (Star Wars fan, you are) you didn't get the path right because you didn't ZIP up the directory containing the folder "dynamictestjar", so the path that the class loader sees is incorrect.</li> </ol> <p>None of these are due to great mysteries about the class loader. You need to check and make sure that you're doing your stuff properly.</p> <p>Why do you need to load the JAR dynamically like this? What are you doing that couldn't be accomplished by simply putting the JAR in the CLASSPATH and letting the class loader pick it up?</p> <p>I hope this is just an example and not indicative of your "best practices" in Java:</p> <pre><code>catch(MyException e) { } </code></pre> <p>You should at least print the stack trace or use Log4J to log the exception.</p> <p>UPDATE:</p> <blockquote> <p>I should point out that whenever I run my tests from NetBeans, everything goes according to plan. The weirdness begins only when I forcefully remove the external Jar from Java's eyes and run the test app from the command line.</p> </blockquote> <p>This suggests that the path you've hard-wired into the path to the JAR isn't satisfied when you run from the command line.</p> <p>JVM doesn't work one way with NetBeans and another way without it. It's all about understanding CLASSPATH, the class loader, and path issues. When you sort yours out, it'll work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload