Compile and execute java

Hello
is it possible to execute a .class file which is n an other directory without changing directory ?
E:\FAC\PROJET\Demo>javac HelloWord.java
E:\FAC\PROJET\Demo>java HelloWord
Hello Word
E:\FAC\PROJET\Demo>cd..
E:\FAC\PROJET>java E:\FAC\PROJET\Demo\HelloWord
Exception in thread "main" java.lang.NoClassDefFoundError: E:\FAC\PROJET\Demo\HelloWord
E:\FAC\PROJET>How should I do ?
In fact my problem is that I have made a simple Java editor which can compile en run java code. When I open a java file which is situated somewhere on the drive, and I try to compile it works:
javac /somwhere/on/the/direve/myFile.javaBut it seems it is not possible to execute n this way.
My app is of course using runtime.exec(command); class to run the command.
do you have any ideas ?
Thank you !

Try java -classpath %CLASSPATH%;.
HelloWord
For executing the class with the absolute path, use
java -classpath %CLASSPATH%;C:\Foo\Bar HelloWordwhere C:\Foo\Bar contains the class file. :)

Similar Messages

  • Is there such thing as a "compile and execute statement" in Java?

    I wanted to know if there's any way to compile and execute a program "within" another program.

    Yes, but the classes to do so aren't officially supported by Sun as far as I know.
    And you must be able to assume a thing or two about the stuff you compile, such as existing constructors or factory methods etc, otherwise it gets hairy.
    Here's some example code (haven't tried it, so excuse any spelling errors etc) to compile the source code in a file called MyClass.java:
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new sun.tools.javac.Main(baos,null).compile("MyClass.java");
    String theMsg = baos.toString();
    if (theMsg.length() > 0)
        // NiftyErrorHandlingHere
    }After that, you can load it with a simple ClassLoader.loadClass() call and create instances of it.
    It must be compiled with the tools.jar file in the classpath, to find the sun.tools.javac.Main class.
    However, for any such dynamically compiled class to be of any use to you, you must be able to assume something about it, such as implementing interfaces or whatever, otherwise it's a kind of pointless exercise.
    HTH,
    F

  • How to compile and execute lex,yac,c and java programs

    its the 3rd day on my New MacBook pro..
    as i just migrated from windows to mac i love to work on this..
    The main problem  is i DON't know .......
    how to compile and execute
    1) lex and yac programs
    2) c program
    3) java program
    so please help me
    THIS is the error i got   a1.l is a program
    i got the same error when i used  gcc
    $ lex a1.l
    $ cc lex.yy.c                                 
    Undefined symbols:
      "_yywrap", referenced from:
          _yylex in cc8QDQjW.o
          _input in cc8QDQjW.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Is the problem that you don't know how to compile and execute these programs on a Mac, or just that you don't know how to compile and execute them?
    Mac OS X is really just a version of BSD Unix, as far as programs like like bison, flex and gcc are concerned...and even when Apple specific versions are provided in the Developer Tools, there are symlinks in the usual places in the Unix file hierarchy.
    For problems with lex and yacc, I suggest you start with their own references, for example, here.
    Or you could just use %option noyywrap, if you only have one file to scan.
    Or you could link to libfl.a using -lfl and use the default version from that library.
    But you really should (as Keith Barkley was subtly hinting at) learn how these tools work and why they work that way.

  • How to compile and execute programing languages

    its the 3rd day on my New MacBook pro..
    as i just migrated from windows to mac i love to work on this..
    but i my main problems is i DON't know .......
    how to compile and execute
    1) lex and yac programs
    2) c program
    3) java program
    so please help me
    THIS is the error i got   a1.l is a program
    i got the same error when i used  gcc
    $ lex a1.l
    $ cc lex.yy.c                                  
    Undefined symbols:
      "_yywrap", referenced from:
          _yylex in cc8QDQjW.o
          _input in cc8QDQjW.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    You're trying to build something that depends on a library you don't have, or haven't referenced. This sort of question belongs in the Developer forums.
    Developer Forums: Apple Support Communities

  • Help on How to compile and execute awt programs

    can any1 say how to compile and execute awt programs
    Edited by: 863765 on Jul 18, 2011 3:29 AM

    EJP wrote:
    The answer is the same for anycode.Oh, but it's not. If he starts with MyClass.java, and we tell him
    javac MyClass.java
    java -cp . MyClassthen that advice won't work when he creates MyClass2. The poor guy will be left lost and alone, with no clue how to proceed! {noformat};-){noformat}

  • How to Set up the  variables and others to compile and Run Java Programs

    Hello,
    I have just downloaded the jdk1.6.0_07 and jre1.6.0_07 and installed it in C:\Program files\Java in my Windows XP ,So please tell me how to sett up the enviroment variables etc to compile and run Java Programs from Command Prompt.
    thanks

    To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:
    1. Click Start > Control Panel > System on Windows XP or Start > Settings > Control Panel > System on Windows 2000.
    2. Click Advanced > Environment Variables.
    3. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
    C:\Program Files\Java\jdk1.6.0_<version>\bin

  • How to compile and run java files on a mac using command line?

    can someone tell me or link me to some article on how to compile and run java files from command line on a mac? I have mac OS X leopard

    What do you mean by "where to put them" ? What do you want to put anywhere ?
    Have you read Peter's comment in brackets ? Perhaps you have a classpath problem ?
    Edited by: Michael_Knight on Aug 31, 2008 4:23 AM

  • Compile and run java programs in different directroy

    Hi,
    I often encounter many problems when I run java programs in the different directories. Like
    javac -d dir_name a.java
    java -cp dir_name a
    Something wired often happens, such as, there is not a.java file in some directory, but javac -d dir_name a.java can still work or "java -cp dir_name a" often doesn't work. Moreover, file_name.jar is also a tough problem and solving compiling problems is often time-consuming.
    So I hope to read something about how to compile and run java programs in different directory properly.
    Could you pleae give me a detailed description for that or recommend a book or website?
    Thanks a lot.

    Can you post a small amount of code that does not work, including the directory structure, and the error messages? Some one here can likely explain the problem.

  • How to compile and execute a Pro*C program on Unix?

    Hello Gurus,
    I am new to Pro*C. I just wrote a sample Pro*C program 'first.pc' to read some information from some tables and print it on screen.
    I am not sure how to compile it and execute it to see the output of my very first program.
    After searching a lot I tried following ..
    -- Step 1 compile the program into .c program
    $->ls -lrt first.pc
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    $->proc first.pc
    Pro*C/C++: Release 8.1.7.0.0 - Production on Sat Oct 31 05:43:35 2009
    (c) Copyright 2000 Oracle Corporation.  All rights reserved.
    System default option values taken from: /oracle/app/oracle/product/8.1.7/precomp/admin/pcscfg.cfg
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    $->
    -- Step 2 Generate the .o file
    $->cc -I${ORACLE_HOME}/precomp/public -c first.c
    first.c: In function 'main':
    first.c:154: warning: return type of 'main' is not 'int'
    $->
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    -rw-r--r--    1 sqloper4 staff          3709 Oct 31 05:45 first.o
    $->
    -- Step 3 After that link the .o to libraries and produce the exe
    $->cc -o exe_name -L $ORACLE_HOME/lib -lclntsh
    ld: 0711-317 ERROR: Undefined symbol: .main
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    $->
    $->ls -lrt first*
    -rwxrwxrwx    1 sqloper4 staff          1069 Oct 31 03:39 first.pc
    -rw-r--r--    1 sqloper4 staff             0 Oct 31 05:43 first.lis
    -rw-r--r--    1 sqloper4 staff          6648 Oct 31 05:43 first.c
    -rw-r--r--    1 sqloper4 staff          3709 Oct 31 05:45 first.o
    $->After all above still I am not sure how to proceed and 'execute' the program.
    Could you please help me with the steps to 'Compile and execute' a Pro*C program ?
    Oracle DB Version : Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    OS : Unix
    Thanks in advance!

    Hi All,
    After reading Pro*C Question thread I have tried below steps to compile my .C program, but failed with the given errors
    $->cc -I$ORACLE_HOME/precomp/public -L$ORACLE_HOME/lib first.c -o sample
    ld: 0711-317 ERROR: Undefined symbol: .sqlcxt
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit statusAfter receiving above error I tried below command as an alternative
    $->cc -I$ORACLE_HOME/precomp/public -L$ORACLE_HOME/lib first.c -o first -lclntsh -lsql10
    collect2: library libsql10 not foundCould you please help in resolving above error? Whats missing exactly?

  • How to compile and execute procedure from hr to scott

    Hi all ,
    I am trying to compile and execute a stored procedure from hr user to scott user.
    first i gave grant command to hr.
    By using:- grant create any procedure to hr;
    After i compile a procedure from hr to scott.
    create or replace procedure scott.sp_hr
    is
    begin
    dbms_output.put_line('run by scott user');
    end;
    but it says :-
    ORA-01031: insufficient privileges
    01031. 00000 - "insufficient privileges"
    any one help me.

    it works for me
    20:29:29 SQL> 20:29:29 SQL> connect / as sysdba
    Connected.
    20:47:41 SQL> grant create any procedure to hr;
    Grant succeeded.
    20:48:01 SQL> connect hr/hr
    Connected.
    20:48:07 SQL> create or replace procedure scott.sp_hr
    is
    begin
    dbms_output.put_line('run by scott user');
    end;
    20:48:21   2  20:48:21   3  20:48:21   4  20:48:21   5  20:48:21   6 
    20:48:23   7  /
    Procedure created.
    20:48:25 SQL>

  • Help:Compiling and running Java Midlets?

    Hello,
    I am a fresh learner in Java.I am finding it very difficult to compile and run Java Midlets on the Computer system.Also,i will like to tranfer the Sourcecodes to a PDA i.e install it on the PDA and have the application walking well.Please help.Thank you.

    You will get all the detailed steps ( have a look at the ff link) to configure the sun wireless toolkit on a PC , midlet compiling, running , uploading to the Palm PDA and testing it on the device. As for the connection, you can use the hot synch cable or a bluetooth hot synch.
    http://developers.sun.com/techtopics/mobility/midp/articles/palm
    Cheers!,
    Birhanu

  • Compiling and executing with differente Java version

    Hello,
    I'd like to know what problems might cause compiling with a versión (1.4.2) and executing the program with a different version of Java (1.5 for example).
    Or where can I find tha information
    thanks!

    sabre150 wrote:
    da.futt wrote:
    Care to elaborate?I have enough trouble remembering my own name never mind stuff over two years old. There's a name for that, you know? Though I seem to have forgotten what it was.
    I do remember having to re-write all the bespoke renderers and to have to change the layout approach due to changes in default Font sizes.Ooh, nasty! Must have quite a quagmire, that code.
    On the other hand and getting back to the OP's question, that's more of a difference in the platform than the interpreter, isn't it? I suppose you could run into the same trouble "porting" a Java GUI to, say, *nix, when it had been tailored to peculiarities of the Windoze L&F.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Compiling and putting java classes in database schema

    hi..good evening to all...
    I have total 7 java classes which i have to compile and put in the database schema. those 7 classes are interdependent on each other thats why there is a particular order of execution.
    i want to compile and put them in the schema thorugh the command line.
    i have tried doing this one by one by executing the following command in cmd...
    D:\>loadjava -u username/password@sid -v -resolve javaclassname.java
    then its working fine..
    But i have to do this in one time i.e i have to compile and put all the 7 classes in schema by a single command.
    Thats why i have put all the 7 classes one by one in the required order...save the file as 'java_sources.java' and then run the following command...
    D:\>loadjava -u username/password@sid -v -resolve java_sources.java
    but it is not working... :(
    please help...thanks in advance

    Hi,
    It is not required to load one by one class files into the schema. Can create a jar file for all the class files and load the jar file using the '-o' option in loadjava
    eg:
    loadjava -u username/password@sid -v -r -o jar_file_name.jarI hope you might use any IDE to develop the java class files. All the IDE have option to develop jar file if not get oracle JDeveloper for easy option.
    Check the version of jdk used in your oracle server and use appropiate version of Jdeveloepr and compile the classes.
    If your class files use any builtin library jar files those also need to be loaded.
    As thomaso said if pasted with errors can resovle easier
    NB:
    http://download.oracle.com/docs/cd/B10500_01/java.920/a96659/02_load.htm

  • How to compile and run java program at command console

    hi there
    can anyone tell me how to compile and run a java program at command console? I have installed JRE 1.3.1, and also have installed JBuilder 5 if it helps.

    try this
    System.out.println("Enter your Name : ");
    BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) );
    String s = console.readLine();
    System.out.println("Hello : "+ s+" !" );

  • How do I compile and run Java programs on a Mac?

    To clarify my earlier post, I know that you can write java in any text editor but with the PC you compile and run everything through the MS DOS prompt, what is the Mac equivalent?

    See this question :-)
    http://forum.java.sun.com/thread.jsp?forum=54&thread=289574

Maybe you are looking for

  • N97 v2.0 firmware issues/bugs

    installed n97 v 2.0 nam version installed great.. didnt even delete all apps or loose most settings.. some issues 1. the fm transmitter app seems to be gone.. although in settings you can set the channel etc. and you can enable it from the music play

  • Moving music from new Macbook to iPhone4

    I recently bought a new Macbook, which replaced an old PC laptop. I also have an iPhone4 which I prefer to hold most of my music. I moved all my music libraries from my old laptop to my new Macbook and all my songs appear in my new iTunes, with check

  • Dynamic RFC call

    Hi, In a general scenario, all RFC destinations are defined in SM59, and programs call other system, by using the following method. Call function 'ABC' destination dest. I want to try and make a dynamic call, to another system, without making an SM59

  • Using the Airport with an Xbox 360 and such

    Hey guys I'm thinking of buying a new Airport Extreme N for my home since my linksys router is being stubborn. I have an xbox 360 and i was wondering if it worked well with it. What i mean is it faster with the Extreme and is it very reliable. Thanks

  • Cannot Load Hierarchy and Description

    Hi All, Sorry repeat this question. I am facing the follow problem: after I export .csv , I check the description and the hierarchy in the file .cvs and its ok, but when i execute the package to load master data, this 2 fields donu2019t load. My mapp