How to run a java class from its package directory

Hi,
I hope someone can help me on the following ....
Let say I have a Test.java class with the package definition: "package com.ams.eai.mq.fileAdapter;". I compiled the class into the directory c:\myJava\client\com\ams\eai\mq\fileAdapter. I have c:\myJava\client specified in my classPath and Path. Why is it when I go to the mentioned directory and enter at the prompt >java Test, I get java.lang.NoClassDefFoundError: test (wrong name: com/ams/eai/mq/fileAdapter/test).
What directory am I supposed to be in to run my Test class ? Is there some other path that I need to specify but didn't ?
Thanks for any help.

You have to type out the fully qualified class name:
java com.ams.eai.mq.fileAdapter.Test
Even if you had the entire dir structure, "c:\myJava\client\com\ams\eai\mq\fileAdapter" in your classpath you'd still have to fully qualify the name of the "Test" class. What if there was another class named "Test" in a different package in your CP? The VM would have no way of knowing which "Test.class" you'd want to run.

Similar Messages

  • URGENT: How to run a Java program from a different directory?

    Hi.
    How do I run a Java program from a directory that the file is not located in? So lets say im in c:\Java. But the file is in c:\Java\abc\efg\.
    What would be the command to run the Java file from c:\Java.
    I can't remember it and I need it asap.
    Cheers.

    If the class you are trying to run is MyApp.class, try
    c:\Java\>java -cp abc\efg MyAppThe actual classpath you specify will depend on whether or not MyApp.class is in a package (I've assumed it isn't) and whether or not any 3rd party jars are involbed (I've assumed not).
    Edited by: pbrockway2 on Apr 1, 2008 6:42 PM
    The command arguments read as "Run the MyApp class using as a classpath abc\efg relative to here (c:\Java)".

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • How to run a java prog from c prog

    hello all
    I wanted to run a java class from a c prog,
    can any body suggest the way in which this can be done, links or tutorials in this regard is highly appreciable,
    thanks in advance
    Message was edited by:
    mahima_vyas

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • How to call a Java class from another java class ??

    Hi ..... can somebody plz tell me
    How to call a Java Class from another Java Class assuming both in the same Package??
    I want to call the entire Java Class  (not any specific method only........I want all the functionalities of that class)
    Please provide me some slotuions!!
    Waiting for some fast replies!!
    Regards
    Smita Mohanty

    Hi Smita,
    you just need to create an object of that class,thats it. Then you will be able to execute each and every method.
    e.g.
    you have developed A.java and B.java, both are in same package.
    in implementaion of B.java
    class B
                A obj = new A();
                 //to access A's methods
                 A.method();
                // to access A's variable
                //either
               A.variable= value.
               //or
               A.setvariable() or A.getvariable()

  • How can I compile and run other java classes from within an application?

    Hello there everyone! I really hope that someone can help me. I am writing a program that must be able to compile and run other java classes that are in different files, much like development environments like Kawa or Forte allow you to do.
    There has to be a way of doing this ( I hope!! ), but i can't seem to find it!!
    I have tried using this command to compile:
    Runtime.getRuntime().exec ("c:\\programs\\javac className.java");
    ...and this one to run:
    Runtime.getRuntime().exec ("c:\\programs\\java className");
    ...but neither works!!! I can compile and run classes that are in the same file as my application, but I can't get it to work at all for files in different directories or files.
    PLEASE, PLEASE, PLEASE help me - i've run out of ideas, and i need this to be working in 3 days!!!
    Thank you very much for any help anyone can give me, I really appreciate it!! Thanks again!!
    Adrian ( ...in distress!! )

    public class JavaCompiler{
       public static void main(String[] args)throws Exception{ //sorry bout the laziness
          if(args == null || args.length != 1){
             System.out.println("Usage: java JavaCompiler MyClass.java");
             System.exit(0);
          String className = args[0];
          Runtime rt = Runtime.getRuntime();
          Process p = rt.exec("javac " + className); //consider setting cpath for this
          p.waitFor();
          //now try to run after it is done.
          p = rt.exec("java " + className.substring(0, (className.length() - ".java".length()));
          p.waitFor();
          //do some other stuff
    }This should get you going. You may consider looking into the System.getProperty() method in order to determine the type of OS it is running on in order to findo out what command to run. I know that the sun tool listed above is nice, but by my understanding the sun tools provided are not guaranteed to stay the same. I'm no expert on this matter, but that is one of the reasons there is no API documentation for those tools. Also, I don't believe those tools come packaged with the JRE. (Of course if you are making an IDE it will be expected that the user has an sdk installed. Good luck with figuring this thing out.

  • Getting an error msg while trying to run the java class from CMC

    Hi All,
    I am getting an error, while trying to run the java .class file, that which is imoported into CMC.
    Error msg:
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
         at java.lang.ClassLoader.defineClass1(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
         at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         at com.crystaldecisions.sdk.plugin.desktop.program.internal.ProgramWrapper.main(ProgramWrapper.java:49)
    I have imported .class file into CMC and trying to invoke the .class file by another java program from eclipse..When i tried to invoke the .class in cmc, i am getting an error msg, mentioned above. I thought there might be version conflict. So i changed the java complier version to 1.5 in my Eclipse. After that is done again i am facing the same problem.
    Can anyone help me to resolve this issue?
    Thanks in Advance.

    i have installed BO SDK 3.1 , Service pack 3. It comes woth JDK 1.5 version. i have not done any chnages to it. I impoprted all the jar files related to BO into eclipse.
    1)  Actually, i am writing java code on eclipse. When i run code from the eclipse, it creates a session to cmc and creates folder structure what i need.
    2)  But the thing is, that code needs to run, when i import the .class file into cmc. The process how i imported the .class file to cmc.
    Manage> Add> Program File-->Java (Check Box). In this way i added java class file from the eclipse workspace (class file from the bin directory).
    3) So when i run the .class file externally by another java program or also when i log in to CMC and run that .class file, the instance shows sucess, but when i see the logfile i am getting an exception that which i mentioned above.
    If my method is worng can you please let me know the stepts how to run java program in cmc.
    Thanks in Advance

  • How to: Calling a java class from asp?

    Hello all i have a problem to call a Java class from a asp
    Here what I do:
    [JavaSays.java]
    package JavaCom;
    public class JavaSays
    public String Hello()
    return "Hello world" ;
    then
    javareg /register /class:JavaCom.JavaSays /progid:JavaCom.JavaSays
    md c:\winnt\Java\TrustLib\JavaCom
    copy JavaSays.class c:\winnt\Java\TrustLib\JavaCom
    --Asp
    --TestJavaCom.asp
    <html>
    <body>
    <h1>Simple Test</h1>
    <% Set ObjPrueba = Server.CreateObject("JavaCom.JavaSays") %>
    <%= ObjPrueba.SimpleFn(5) %>
    <hr>
    </body>
    </html>
    when i try to run my asp
    it tell me that:
    Error type : Server Objetc, ASP 0177 (0x80040111)
    ClassFactory can not find the class
    any idea???
    thanks.

    I think the OP wants to use a class file as a COM object. I've never done that, but this URL:
    http://support.microsoft.com/default.aspx?scid=KB;EN-US;q167941&
    seems to indicate that you should have placed the class file into the c:\winnt\Java\TrustLib\ sub directory before you ran the JAvaReg bat file - I would re-run JavaReg and bounce IIS and associated services and see if that works out.
    Good Luck
    Lee

  • How to run the java program from another directory?

    Hi
    Assumption:
    data.java is in a package suncertify.db and place in a directory c:/code/suncertify/db/ directory
    data.class file: is in c:/code/suncertify/db/ directory
    current directory: c:/
    How can execute the data.class directly in c:/ directory without changing directory to c:/code/ ?
    Thanks in advance,
    Adrian

    Yes. You can use the -classpath and -sourcepath options to specify where to look for source files, and the -d option to specify where to generate the class files. Look up the usage of those options in the javac documentation:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html

  • How to download a java class from database to file system

    Hi All,
    We have one invalid java class in database. We need to verify what is the functionality of this class. So we planned to download this class to file system. Then we need decompile it to source. But we are not able to identify the right command to download the java class from database.
    Please suggest me if any possible ways to acheive this.
    Thanks in advance....

    http://www.sql.ru/forum/actualthread.aspx?tid=747308
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14187/appendixa.htm
    PROCEDURE export_source(name VARCHAR2, schema VARCHAR2, blob BLOB)
    PROCEDURE export_class(name VARCHAR2, schema VARCHAR2, blob BLOB)
    PROCEDURE export_resource(name VARCHAR2, schema VARCHAR2, blob BLOB)
    create table scott.t (id number, b blob);
    declare      
        b blob;
        begin
           dbms_lob.createTemporary(b, true, dbms_lob.CALL);
           dbms_java.export_class('sun/net/www/ParseUtil', user, b);
          dbms_output.put_line('length(b): '||length(b));
          insert into "SCOTT"."T" values(1,b);
        end;

  • Import java class from model package

    I have a java class in model package.I create a managed bean in the view package and I want to import the first java class with "import model.class1" but this error "import model.class1 not found" is shown.What should I do?

    Hi,
    Why are you importing the Model classes to your backing bean? You should not be doing that. Instead, expose the method in model as client interface (whichever you want to call in the backing bean), create the method binding in your pagedef. Then, from the backing bean, you can execute the method programatically.
    -Arun

  • Running a java class from a windows shortcut?

    I am currently running a program I have written from a batch file for which I have created a shortcut. I have recently however modified my shortcut to include a variable that i pass to the main method in the program through the batch file - all this works fine.
    It did however get me thinking - why can't I do away with the batch file??
    Below is the batch file code that loads my software:
    Echo Off
    CLS
    SET CLASSPATH=.;"C:\Program Files\Java\j2re1.4.2_03\bin"
    SET Path="C:\Program Files\Java\j2re1.4.2_03\bin"
    C:
    CD\
    CD "Program Files\My App"
    start "My App" javaw My_App %1
    And the two shortcut strings that call the batch file:
    "C:\Program Files\My App\My_App.bat" var1
    "C:\Program Files\My App\My_App.bat" var2
    What I have been trying to do however, is do all of the above from the shortcut
    I have added the following code to a shortcut:
    Target:
    C:\WINDOWS\system32\cmd.exe /c SET CLASSPATH=.;"C:\Program Files\Java\j2re1.4.2_03\bin" && SET Path="C:\Program Files\Java\j2re1.4.2_03\bin" && start javaw "My App" My_App
    Start In:
    "C:\Program Files\My App"
    All of the relevant paths are set correctly, and it calls the main java class file from the directory from where it resides, but I get a popup error message stating:
    Java Virtual Machine
    Error: Could not fing Java 2 Runtime Environment.
    Has anybody got any ideas on how to fix this please??

    Either I'm misunderstanding, or ?
    You don't need to set classpath if all you need for a classpath is the directory that contains the classfile - the Start in combined with -cp . // that's -cp followed by a periodsets the classpath to that value, and Windows will create a fully qualified path to javaw.
    You entries in the shortcut shouldn't have to be any more than what I typed.

  • How to run standalone java file from weblogic server on Solaris

    Hi,
    We have a requirement to run a java file at a scheduled time in a day using cron scheduler on our linux server.
    We need to fetch data from the database & perform some business logic in this standalone JAVA file.
    Our application has an EAR which is deployed on Weblogic 10.3 server & in our application, we are utilizing the datasource created in that domain.
    Now, we have created a standealone Java file & used exisitng datasource (without Hibernate) of the domain with the help of below forums,
    Use DataSource of weblogic in a standalone Java file
    able to achieve the same.
    I've bundled this JAVA in application WAR & depoyed on the same domain where datasource is created.
    Now, how can I execute this file from anywhere on the server using weblogic classpath.
    Please help on the same in implementation.
    Thanks,
    Uttam

    If the Java application must be stand-alone you must not deploy it on WebLogic, then WebLogic will manage its lifecycle.
    In this case you can use the CommonJ API and use the timermanager if it must run on a certain time. More information
    of how to do this can be found here: http://middlewaremagic.com/weblogic/?p=5569
    If you keep the Java application stand-only and want to use a cron job you can follow the example presented here: http://middlewaremagic.com/weblogic/?p=7065
    Note that the example runs a WLST script, but you can follow the same steps to run your Java application.

  • How to run executable Java app from command line: No Main( ) method

    This is the opposite question from what most users ask. I have the Java source code and a running Java executable version of the program in a windows environment. I don't want to run it in the normal way by double-clicking on it or using the executable. I need to be able to run the same application from the command line. If I can do this, I can then compile and run the code on my Mac, too, which is what I am ultimately trying to accomplish.
    Normally, this would be easy. I would look for a Main method, normally public static void main (String[] args ) or some variation. I cannot find a main() anything, anywhere when searching the files. There must be some windows executable that links to the Java classes. It's very clever, no doubt, but that's not helping me.
    I am trying to run what I can determine as the Main class, with a standard command line call, but that is not working either.
    It is a Java graphics program, so mostly Swing container stuff.
    I am not finding a manifest.txt file, telling me where a main method is, nor anything about the Main Class. There is no readme file for the program.
    Any insight that would point me in the right direction? What should I be looking for?
    Thanks in advance, Bloozman

    It's possible there's a clever Windows executable that runs the class. But if it's a plain old Java class then there's a good chance there's a constructor. Look for that; it's possible you may be able to start by writing another Java class that creates an instance of your mystery class.
    When you have that done, try running it. It's possible that just creating an instance might be sufficient to run it. Swing programs are sometimes written like that. If not, then start looking for methods with names like "run" or "go" or "start" that your little controller program can call.

  • How to access a Java class from view controller?

    Hi All,
    I have created a Test.java class file from Navigator view under
    Src --> Packages --> com.sap.MyProject.
    When I try to access the Test class from view controller,
    I getting this error "Test cannot be resolved or is not a type".
    How do I fix this?
    Thanks
    Sundar

    Hi,
    I have created a Test.java class file from Navigator view under
    Src --> Packages --> com.sap.MyProject.
    After this you can goto the context of your View and define the VA goto the type of VA and click on the right side button and go to java native type and type your java file name click you name .
    that means the jave file s assigned to VA.
    U can utilize thrut that VA.
    Thanks,
    Lohi.

Maybe you are looking for

  • How can I create software start and stop trigger in LabView using 6023E series DAQ card? I don't want to use the external trigger.

    I am using 6023E DAQ card to collect the signals, such as AE, Force, Torque from the machine. I want to collect only some part of signal for example between start triger and stop trigger. I'd like to know how I can creat those triggers in LabView fro

  • Decimal notation in report output

    Hi Experts, My requirement is want to display values in report with out decimal notations( , .). Eg: 2,008.00 Output should be 2008 I know one solution , by maintaining user profiles we can achieve this .But this solution is user specific. I need a s

  • Sign in failed notifications

    I keep getting ''sign in failed'' notifications...several a day.The message says ''server password has been changed.''I can sign into my account fine.I can access my emails and can use the email address normally,so WHY do I keep getting these notific

  • Adept Distributor Auth?

    Hi, I'm developing a .net solution to send and store files to ACS4 and using the Upload Test program as a starting point I'm getting the following error back - if anybody has any idea how to resolve this I'd be very grateful... The error is: E_ADEPT_

  • IMovie '06 will not open - says a Quicktime update is required

    iMovie '06 will not open for me. I get a message saying that, "QuickTime update required - iMovie requires QuickTime version 7.5.0 or later, which can be downloaded from www.apple.com/quicktime." And the only button displayed is "Quit". The problem i