Results 1 to 7 of 7
  1. #1
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Question problem running compiled class file

    Hello All!

    I'm learning java still, so please bear with me if this turns out to be something obvious (cuz its not to me! ;-P ) I was hoping someone may be able to shed some light on this error i'm getting...

    I'm working with some source files and compiled a .java file into a .class file and used the -cp to specify my working directory as there are a lot of other .java files that are imported. I successfully compiled into .class with no errors.

    When i attempt to go and run the file from the command line, I get one of two errors depending on if i use the -cp switch again or not.

    command:
    Java Code:
    java GetServiceStatusSample
    | results in:

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: GetServiceStatusSample (wrong name: com/amazonservices/mws/sellers/samples/GetServiceStatusSample)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            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)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    command:
    Java Code:
    java -cp "C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\Complete" GetServiceStatusSample
    | results in:

    Java Code:
    Error: Could not find or load main class GetServiceStatusSample
    my code from GetServiceStatusis as follows:

    Java Code:
    /******************************************************************************* 
     *  Copyright 2009 Amazon Services.
     *  Licensed under the Apache License, Version 2.0 (the "License"); 
     *  
     *  You may not use this file except in compliance with the License. 
     *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
     *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
     *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
     *  specific language governing permissions and limitations under the License.
     * ***************************************************************************** 
     * 
     *  Marketplace Web Service Sellers Java Library
     *  API Version: 2011-07-01
     *  Generated: Fri Jun 24 20:08:04 GMT 2011 
     * 
     */
    
    
    
    package com.amazonservices.mws.sellers.samples;
    
    import java.util.List;
    import java.util.ArrayList;
    
    import com.amazonservices.mws.sellers.*;
    import com.amazonservices.mws.sellers.mock.MarketplaceWebServiceSellersMock;
    import com.amazonservices.mws.sellers.model.*;
    
    /**
     *
     * Get Service Status  Samples
     *
     *
     */
    @SuppressWarnings("unused")
    public class GetServiceStatusSample {
    
        /**
         * Just add few required parameters, and try the service
         * Get Service Status functionality
         *
         * @param args unused
         */
    	public static void main(String... args) {
    
    		/*
    		 * Add required parameters in SellersSampleConfig.java before trying out
    		 * this sample.
    		 */
    
    		/************************************************************************
    		 * Uncomment to try out Mock Service that simulates Marketplace Web
    		 * Service Sellers responses without calling Marketplace Web Service
    		 * Sellers service.
    		 * 
    		 * Responses are loaded from local XML files. You can tweak XML files to
    		 * experiment with various outputs during development
    		 * 
    		 * XML files available under com/amazonservices/mws/mock tree
    		 * 
    		 ***********************************************************************/
    		 //MarketplaceWebServiceSellers service = new MarketplaceWebServiceSellersMock();
    
    		/************************************************************************
    		 * Instantiate Http Client Implementation of Marketplace Web Service
    		 * Sellers API
    		 ************************************************************************/
    
    		MarketplaceWebServiceSellers service = new MarketplaceWebServiceSellersClient(
    				SellersSampleConfig.accessKeyId,
    				SellersSampleConfig.secretAccessKey,
    				SellersSampleConfig.applicationName,
    				SellersSampleConfig.applicationVersion,
    				SellersSampleConfig.config);
    		
    		/************************************************************************
    		 * Setup request parameters and uncomment invoke to try out sample for
    		 * Get Service Status
    		 ***********************************************************************/
    		GetServiceStatusRequest request = new GetServiceStatusRequest();
    		// @TODO: set request parameters here
    		request.setSellerId(SellersSampleConfig.sellerId);
    
    		invokeGetServiceStatus(service, request);
    
    	}
    
    
    
                                    
        /**
         * Get Service Status  request sample
         * Returns the service status of a particular MWS API section. The operation
         * takes no input. All API sections within the API are required to implement this operation.
         *   
         * @param service instance of MarketplaceWebServiceSellers service
         * @param request Action to invoke
         */
        public static void invokeGetServiceStatus(MarketplaceWebServiceSellers service, GetServiceStatusRequest request) {
            try {
                
                GetServiceStatusResponse response = service.getServiceStatus(request);
    
                
                System.out.println ("GetServiceStatus Action Response");
                System.out.println ("=============================================================================");
                System.out.println ();
    
                System.out.println("    GetServiceStatusResponse");
                System.out.println();
                if (response.isSetGetServiceStatusResult()) {
                    System.out.println("        GetServiceStatusResult");
                    System.out.println();
                    GetServiceStatusResult  getServiceStatusResult = response.getGetServiceStatusResult();
                    if (getServiceStatusResult.isSetStatus()) {
                        System.out.println("            Status");
                        System.out.println();
                        System.out.println("                " + getServiceStatusResult.getStatus().value());
                        System.out.println();
                    }
                    if (getServiceStatusResult.isSetTimestamp()) {
                        System.out.println("            Timestamp");
                        System.out.println();
                        System.out.println("                " + getServiceStatusResult.getTimestamp());
                        System.out.println();
                    }
                    if (getServiceStatusResult.isSetMessageId()) {
                        System.out.println("            MessageId");
                        System.out.println();
                        System.out.println("                " + getServiceStatusResult.getMessageId());
                        System.out.println();
                    }
                    if (getServiceStatusResult.isSetMessages()) {
                        System.out.println("            Messages");
                        System.out.println();
                        MessageList  messages = getServiceStatusResult.getMessages();
                        java.util.List<Message> messageList = messages.getMessage();
                        for (Message message : messageList) {
                            System.out.println("                Message");
                            System.out.println();
                            if (message.isSetLocale()) {
                                System.out.println("                    Locale");
                                System.out.println();
                                System.out.println("                        " + message.getLocale());
                                System.out.println();
                            }
                            if (message.isSetText()) {
                                System.out.println("                    Text");
                                System.out.println();
                                System.out.println("                        " + message.getText());
                                System.out.println();
                            }
                        }
                    } 
                } 
                if (response.isSetResponseMetadata()) {
                    System.out.println("        ResponseMetadata");
                    System.out.println();
                    ResponseMetadata  responseMetadata = response.getResponseMetadata();
                    if (responseMetadata.isSetRequestId()) {
                        System.out.println("            RequestId");
                        System.out.println();
                        System.out.println("                " + responseMetadata.getRequestId());
                        System.out.println();
                    }
                } 
                System.out.println();
    
               
            } catch (MarketplaceWebServiceSellersException ex) {
                
                System.out.println("Caught Exception: " + ex.getMessage());
                System.out.println("Response Status Code: " + ex.getStatusCode());
                System.out.println("Error Code: " + ex.getErrorCode());
                System.out.println("Error Type: " + ex.getErrorType());
                System.out.println("Request ID: " + ex.getRequestId());
                System.out.print("XML: " + ex.getXML());
            }
        }
        
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: problem running compiled class file

    Did you compile the source code with no errors before trying to execute it with the java command? Where is the .class file?

    The code you posted is in a package. You must set the classpath to the folder that contains the folder that is the first name in the package path: com

    The classpath + the package path should point to the folder with the class file. No overlapping of the paths.

    The full package/class name should be used with the java command:
    java com.amazonservices.mws.sellers.samples.GetServiceS tatusSample
    Last edited by Norm; 04-13-2012 at 11:36 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Question Re: problem running compiled class file

    1) yes it compiled with no errors using the javac -cp command and the .class file is located at \com\amazonservices\mws\sellers\samples\

    the exact command i used to compile:

    Java Code:
    C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\
    new_workspace\Complete\com\amazonservices\mws\sellers\samples>javac -cp "C:\Documents and Settings\
    jason.s\Desktop\AMZ_Auto\new_workspace\Complete" GetServiceStatusSample.java
    no errors at time of compilation. the resulting .class file is located in the same directory that i ran my command from... so:

    Java Code:
    C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\Complete\com\amazonservices\mws\sellers\samples\
    2) i'm not sure i'm following you with your next bit.

    when i attempted to run the file using:

    Java Code:
    C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\Complete\com\amazonservices\mws\
    sellers\samples>java -classpath "C:\Documents and Settings\
    jason.s\Desktop\AMZ_Auto\new_workspace\Complete" GetServiceStatusSample
    my working directory looks like this:

    Java Code:
     Directory of C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\C
    omplete\com\amazonservices\mws\sellers\samples
    
    04/13/2012  12:23 PM    <DIR>          .
    04/13/2012  12:23 PM    <DIR>          ..
    04/12/2012  11:50 AM             5,346 GetServiceStatusAsyncSample.java
    04/13/2012  12:23 PM             5,016 GetServiceStatusSample.class
    04/12/2012  11:50 AM             7,664 GetServiceStatusSample.java
    04/12/2012  11:50 AM             5,856 ListMarketplaceParticipationsAsyncSample.java
    04/12/2012  11:50 AM             6,059 ListMarketplaceParticipationsByNextTokenAsyncSample.java
    04/12/2012  11:50 AM            12,054 ListMarketplaceParticipationsByNextTokenSample.java
    04/12/2012  11:50 AM            11,797 ListMarketplaceParticipationsSample.java
    04/12/2012  02:49 PM               917 SellersSampleConfig.class
    04/12/2012  02:48 PM             2,895 SellersSampleConfig.java
                   9 File(s)         57,604 bytes
                   2 Dir(s)   1,944,051,712 bytes free
    my classpath of
    Java Code:
    -classpath "C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\Complete"
    looks like this;

    Java Code:
     Directory of C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\C
    omplete
    
    04/13/2012  12:21 PM    <DIR>          .
    04/13/2012  12:21 PM    <DIR>          ..
    01/25/2007  11:22 AM    <DIR>          1.0
    04/12/2012  11:50 AM            54,829 activation.jar
    04/13/2012  12:17 PM    <DIR>          com
    04/12/2012  11:50 AM            46,725 commons-codec-1.3.jar
    04/12/2012  11:50 AM           279,781 commons-httpclient-3.0.1.jar
    04/12/2012  11:50 AM            52,915 commons-logging-1.1.jar
    04/13/2012  12:18 PM    <DIR>          javax
    04/12/2012  11:50 AM            78,850 jaxb-api.jar
    04/12/2012  11:50 AM           826,289 jaxb-impl.jar
    04/12/2012  11:50 AM         3,108,955 jaxb-xjc.jar
    04/12/2012  11:50 AM            46,047 jsr173_1.0_api.jar
    04/12/2012  11:50 AM           367,444 log4j-1.2.14.jar
    04/12/2012  11:50 AM               341 log4j.properties
    04/12/2012  11:50 AM            90,879 MaWSSellersJavaClientLibrary-1.0.jar
    04/13/2012  12:17 PM    <DIR>          org
                  11 File(s)      4,953,055 bytes
                   6 Dir(s)   1,944,039,424 bytes free
    as a side note, I depacked all the .jar files into their respective folders (com or org or javax or 1.0) --- all .jars had the same base
    structure of these as the top level directory, so i believed itw as safe to stick them together... for example... com looks like this:
    Java Code:
     Directory of C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\Complete\com
    
    04/13/2012  12:17 PM    <DIR>          .
    04/13/2012  12:17 PM    <DIR>          ..
    04/13/2012  12:13 PM    <DIR>          amazonservices
    04/13/2012  12:18 PM    <DIR>          sun
                   0 File(s)              0 bytes
                   4 Dir(s)   1,944,035,328 bytes free
    org like this:

    Java Code:
     Directory of C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\C
    omplete\org
    
    04/13/2012  12:17 PM    <DIR>          .
    04/13/2012  12:17 PM    <DIR>          ..
    04/13/2012  12:19 PM    <DIR>          apache
    12/07/2006  02:53 PM    <DIR>          kohsuke
    10/11/2001  05:15 PM    <DIR>          relaxng
                   0 File(s)              0 bytes
                   5 Dir(s)   1,944,035,328 bytes free

    3) I tried your suggestion of running the class file like:

    Java Code:
    C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\
    new_workspace\Complete>java com.amazonservices.mws.sellers.samples.GetServiceStatusSample
    and got another error:

    Java Code:
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at com.amazonservices.mws.sellers.MarketplaceWebServiceSellersClient.<clinit>(MarketplaceWebServiceSellersClient.java:111)
            at com.amazonservices.mws.sellers.samples.GetServiceStatusSample.main(GetServiceStatusSample.java:69)
    Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not 
    be instantiated: javax.xml.bind.JAXBException: "com.amazonservices.mws.sellers.model" doesnt contain ObjectFactory.class or jaxb.index
     - with linked exception:
    [javax.xml.bind.JAXBException: "com.amazonservices.mws.sellers.model" doesnt contain ObjectFactory.class or jaxb.index]
            at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
            at javax.xml.bind.ContextFinder.find(Unknown Source)
            at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
            at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
            at com.amazonservices.mws.sellers.MarketplaceWebServiceSellersClient.<clinit>(MarketplaceWebServiceSellersClient.java:107)
            ... 1 more
    Caused by: javax.xml.bind.JAXBException: "com.amazonservices.mws.sellers.model"doesnt contain ObjectFactory.class or jaxb.index
            at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
            ... 6 more
    sorry for the long post, wanted to make sure i was providing all the information possible.

    thanks a ton!


    EDIT: in case it helps, here's my
    Java Code:
    C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\C
    omplete\com\amazonservices\mws\sellers
    directory

    Java Code:
     Directory of C:\Documents and Settings\jason.s\Desktop\AMZ_Auto\new_workspace\C
    omplete\com\amazonservices\mws\sellers
    
    04/13/2012  12:23 PM    <DIR>          .
    04/13/2012  12:23 PM    <DIR>          ..
    04/13/2012  12:23 PM               867 MarketplaceWebServiceSellers.class
    04/12/2012  11:50 AM             3,098 MarketplaceWebServiceSellers.java
    04/12/2012  11:50 AM             2,926 MarketplaceWebServiceSellersAsync.java
    04/12/2012  11:50 AM            10,013 MarketplaceWebServiceSellersAsyncClient.j
    ava
    04/13/2012  12:23 PM               950 MarketplaceWebServiceSellersClient$1.clas
    s
    04/13/2012  12:23 PM             2,034 MarketplaceWebServiceSellersClient$2.clas
    s
    04/13/2012  12:23 PM            20,890 MarketplaceWebServiceSellersClient.class
    04/12/2012  11:50 AM            29,138 MarketplaceWebServiceSellersClient.java
    04/12/2012  02:49 PM             4,875 MarketplaceWebServiceSellersConfig.class
    04/12/2012  11:50 AM            12,737 MarketplaceWebServiceSellersConfig.java
    04/13/2012  12:23 PM             1,863 MarketplaceWebServiceSellersException.cla
    ss
    04/12/2012  11:50 AM             5,204 MarketplaceWebServiceSellersException.jav
    a
    04/13/2012  12:23 PM    <DIR>          mock
    04/13/2012  12:23 PM    <DIR>          model
    04/13/2012  12:23 PM    <DIR>          samples
                  12 File(s)         94,595 bytes
                   5 Dir(s)   1,943,859,200 bytes free
    Last edited by SnakeDoc; 04-14-2012 at 12:36 AM. Reason: added screenshot of \sellers\ directory

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: problem running compiled class file

    That looks like you are now executing your java class. Now you will have to find some one that knows how to configure and execute the program. It is using third party classes.
    Your problems are way beyond standard java problems.

    Good luck.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: problem running compiled class file

    does this mean in your opinion that the Java file is being executed (run) but that there may be a problem wtih one of the 3rd party packages? if so than this is progress for me, if not then i'm lost as ever.

    just a side note to anyone out there who cares: the Amazon MWS API is horrendously documented and extremely difficult to make sense of... they basically say, unpack the zip file, configure ur account credentials, then run the sample files. -- as if it works out of the box... I may be new to java, but this is crazy lol. lots of easy to find threads on other forums with people venting about the MWS api... people with a lot more java experience than myself lol. **rant done** ;-P

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: problem running compiled class file

    The error message you got was from the program as it was executing. I have No idea what the program is trying to do or what its problem is.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: problem running compiled class file

    ok thanks Norm for your assistance. so my .class file is running (yay!) but failing because of some 3rd party thing... i'll contiue to investigate.

    thanks!

Similar Threads

  1. Replies: 7
    Last Post: 12-18-2011, 04:13 AM
  2. Replies: 3
    Last Post: 07-01-2011, 04:54 PM
  3. Weird problem running a batch file
    By d3n1s in forum Advanced Java
    Replies: 7
    Last Post: 06-19-2011, 01:34 AM
  4. cannot find the class file when running the java command
    By kulangotski in forum New To Java
    Replies: 4
    Last Post: 01-18-2011, 11:34 AM
  5. Replies: 2
    Last Post: 10-01-2009, 11:02 AM

Posting Permissions

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