Results 1 to 18 of 18
  1. #1
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Post Compiler runtime package load error

    Hi all,

    please read help with the following common error that occures only durin runtime.

    F:\CommandJava>java -classpath F:\CommandJava\jms.jar;F:\CommandJava\appserv-rt.
    jar;F:\CommandJava\imq.jar;F:\CommandJava\javaee.j ar MyProducer

    Exception in thread "main" java.lang.NoClassDefFoundError: MyProducer
    Caused by: java.lang.ClassNotFoundException: MyProducer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: MyProducer. Program will exit.

    As you can deduce, I have used the -classpath option to include all the library packages required by the program. The compiler however is failing to unpack the packages even though they are specified.

    Java Code:
    import javax.jms.*;
    import java.util.*;
    import javax.naming.*;
    
    public class MyProducer
    {
    
        public static void main(String[] args)
        {
            // TODO code application logic here
            try
            {
            	new MyProducer().createConnection();
            }
            catch (Exception e)
            {
            	e.printStackTrace();
            }
        }
    
        public void createConnection() throws Exception
        {
        	Hashtable<String, String> evn = new Hashtable<String, String>();
    
        	evn.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        	evn.put(Context.PROVIDER_URL, "file:///C:/imq_admin_objects");
    
        	Context ctx = new InitialContext(evn);
    
        	ConnectionFactory connFactory = (ConnectionFactory)ctx.lookup("MyConnectionFactory");
        	Connection connection = connFactory.createConnection();
    
        	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    
        	Destination mydest = (Destination)ctx.lookup("MyDest");
    
        	MessageProducer producer = session.createProducer(mydest);
    
        	TextMessage msg = session.createTextMessage();
    
        	for(int i = 0; i < 10; i++)
        	{
        		msg.setText("This is message " + (i + 1));
        		System.out.println("Sending message " + (i+1));
    
        		producer.send(msg);
        	}
    
        	producer.send(session.createMessage());
    
    	/*	msg.setText("Sending message ");
    		System.out.println(msg.getText());
    		producer.send(msg);*/
    
        	connection.close();
        }
    }
    The above is the exact code I am busy with. I am not using an IDE when this error occures, but if I use an IDE(JCreator) it run after having to include the libraries explicitly.

    please help.

    Thanks in advance.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Quote Originally Posted by Dark-Redd View Post
    Hi all,

    please read help with the following common error that occures only durin runtime.

    F:\CommandJava>java -classpath F:\CommandJava\jms.jar;F:\CommandJava\appserv-rt.
    jar;F:\CommandJava\imq.jar;F:\CommandJava\javaee.j ar MyProducer

    Exception in thread "main" java.lang.NoClassDefFoundError: MyProducer
    Caused by: java.lang.ClassNotFoundException: MyProducer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: MyProducer. Program will exit.

    As you can deduce, I have used the -classpath option to include all the library packages required by the program. The compiler however is failing to unpack the packages even though they are specified.

    please help.

    Thanks in advance.
    I don't see a compiler anywhere in the vicinity; all I see is that you are trying to run your class file MyProduer.class and the Java runtime (the JVM) can't find it; did you compile your class and can you find it somewhere on that classpath?

    kind regards,

    Jos

    ps. I like your topic title; it's a nice bunch of buzzwords.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Quote Originally Posted by JosAH View Post
    I don't see a compiler anywhere in the vicinity; all I see is that you are trying to run your class file MyProduer.class and the Java runtime (the JVM) can't find it; did you compile your class and can you find it somewhere on that classpath?

    kind regards,

    Jos

    ps. I like your topic title; it's a nice bunch of buzzwords.
    Quote Originally Posted by JosAH View Post
    I don't see a compiler anywhere in the vicinity; all I see is that you are trying to run your class file MyProduer.class and the Java runtime (the JVM) can't find it; did you compile your class and can you find it somewhere on that classpath?

    kind regards,

    Jos

    ps. I like your topic title; it's a nice bunch of buzzwords.
    Hi Jos,

    I have compiled the MyProducer class, and it compiles with no errors. However, during runtime thats when I see the specified error; and I copied all the files and packages to the same directory just in case it was the problem. I read some where online, were it said the error is due to the fact the the JVM cannot find the packages that are needed during runtime. The line below shows how I compiled the class with no errors

    Java Code:
    F:\commandJava\javac -Xlint:unchecked -classpath F:\CommandJava\jms.jar;F:\CommandJava\appserv-rt.
    jar;F:\CommandJava\imq.jar;F:\CommandJava\javaee.jar MyProducer.java
    ps: as for the title had to make it a bit eye catch so you guys can help me.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Is there a file MyProducer.class in the directory where you want to start the Java virtual machine? It is whining about that file ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Quote Originally Posted by JosAH View Post
    Is there a file MyProducer.class in the directory where you want to start the Java virtual machine? It is whining about that file ...

    kind regards,

    Jos
    Yes I have all the classes in the same directory. Every single file I am using is in the same open directory. The only proplem is with the import packages. Because when I use the IDE it runs, but not from the command prompt.

    ps: The evironment variable are set correctly, but it cannot upack the javax.jms package.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    According to your first error message, the JVM couldn't find your class file; it had nothing to do with unpacking packages or environment variables or open directories or whatever; please don't use those buzzwords and show us the error message verbatim (copy and paste).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Hi Jos,

    How is it that when I run it with JCreator(IDE) it works, and not with command prompt; if the error is with the class MyProducer.class file?

  8. #8
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    This is what I get after compiling and run the file:

    Java Code:
    F:\COMMAN~1>javac -classpath F:\CommandJava\jms.jar ExerProducer.java
    
    F:\COMMAN~1>java -classpath F:\CommandJava\jms.jar ExerProducer
    Exception in thread "main" java.lang.NoClassDefFoundError: ExerProducer
    Caused by: java.lang.ClassNotFoundException: ExerProducer
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: ExerProducer.  Program will exit.
    
    F:\COMMAN~1>

  9. #9
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    If you could I would appreciate you trying the exercise out, on you machine to get axactly what I am talking about.
    If you are to try it out you as you may already know, you will need glassfish Open Message Queue installed.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Quote Originally Posted by Dark-Redd View Post
    If you could I would appreciate you trying the exercise out, on you machine to get axactly what I am talking about.
    If you are to try it out you as you may already know, you will need glassfish Open Message Queue installed.
    Your JVM just can't find your ExerProducer.class file and that's what it's complaining about. Check for the existence of that file. It has nothing to do (yet) with those other packages in .jar files; the JVM will complain about it later when they need to be loaded and can't be found. First check the current directory for the existence of your ExerProducer.class file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    This is what my directory looks like:


    F:\COMMAN~1>dir /w
    Volume in drive F is New Volume
    Volume Serial Number is 4271-2A19

    Directory of F:\COMMAN~1

    [.] [..] appserv-rt.jar Consumer.java
    ExerProducer.class ExerProducer.java fscontext.jar HelloWorldMessage.java
    imq.jar javaee.jar jms.jar jndi-properties.jar
    MyConsumer.class MyConsumer.java MyProducer.class MyProducer.java
    Producer.java Test.java Tester.class Tester.java
    18 File(s) 690*114 bytes
    2 Dir(s) 108*429*500*416 bytes free

    F:\COMMAN~1>java -classpath F:\CommandJava\jms.jar ExerProducer
    Exception in thread "main" java.lang.NoClassDefFoundError: ExerProducer
    Caused by: java.lang.ClassNotFoundException: ExerProducer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: ExerProducer. Program will exit.

    F:\COMMAN~1>

    That the structure and the output after executing the file.

    regards
    Dark-Redd

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Try to run it this way:

    Java Code:
    java -classpath F:\CommandJava\jms.jar;. ExerProducer
    Notice the trailing ";." which indicates that the jvm should look for classes in the current directory as well.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Quote Originally Posted by JosAH View Post
    Try to run it this way:

    Java Code:
    java -classpath F:\CommandJava\jms.jar;. ExerProducer
    Notice the trailing ";." which indicates that the jvm should look for classes in the current directory as well.

    kind regards,

    Jos
    Thank you very much Jos that worked. I am getting new Error that I am trying to sort out on my own before asking for help.

    Kind regards
    Dark-Redd

    ps:I hope i will still be helped in future if im unable to solve the other errors.

  14. #14
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Much appreciation for the guidence through the errors, managed to the the stand alone program to run

    Kind regards
    Dark-Redd

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Quote Originally Posted by Dark-Redd View Post
    Much appreciation for the guidence through the errors, managed to the the stand alone program to run

    Kind regards
    Dark-Redd
    I'm glad it works; next time please don't throw that many buzzwords around; it only obfuscates the problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    Dark-Redd is offline Member
    Join Date
    Oct 2011
    Posts
    19
    Rep Power
    0

    Default Re: Compiler runtime package load error

    Hi,

    Why is it that the JVM does not recognize wildcard? like java -classpath C:\*.jar; Test
    I'm just curious.

    regards

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    Quote Originally Posted by Dark-Redd View Post
    Why is it that the JVM does not recognize wildcard? like java -classpath C:\*.jar; Test
    I'm just curious.
    For you *.jar may represent all the .jar files you need; for me *.jar includes too many other .jar files I don't want on my classpath.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Compiler runtime package load error

    No there isn't and please don't hijack someone else's thread; I'm closing this one. Please start your own thread for your problem.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Compiler error please help
    By ShortIt in forum New To Java
    Replies: 5
    Last Post: 02-16-2011, 12:11 AM
  2. java compiler error
    By arshesander in forum New To Java
    Replies: 7
    Last Post: 02-21-2010, 05:18 AM
  3. Replies: 8
    Last Post: 12-30-2009, 12:40 PM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. Compiler Error
    By jeneal in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •