Compiling Java Programs in to diff location

Hi all,
I need know how to generate the class files to different location... if i have a structure of /directory/Sample.java
the usual way of compiling will generate class file under /directory/Sample.class
i wuld like to have it the custom directroy structure... how to do it...

You can always write a batch file or shell script. It doesn't make sense to modify the behaviour of java with user config files or the like because you're likely to use it on serveral projects with different class directories.
But most people, once they have a signficant project, either use an IDE or the (free) ant utility. Either way you can automate the rebuilding of the project after source changes.

Similar Messages

  • How to compile java programs in j2EE 1.4 SDK

    hi,
    i HAVE JUST INSTALLED NEW J2EE 1.4 SDK , IT HAS BEED INSTALLED SUCCESFULLY BUT I AM UNABLE TO COMPILE JAVA PROGRAMS WHICH I USED TO RUN IN SDK 1.4 ,OR EVEN NEW WRITTEN EXAMPLES. CAN ANYONE PLZ HELP ME.

    J2EE by itself is not capable of compiling Java. It requires that a J2SDK be installed first - this is what compiles and runs Java programs. Did you install the combination J2SDK and J2EE, or just the J2EE?
    If both are installed, then you should be able to compile and run as you used to..

  • Compiling Java Program thro EXEC

    hi..
    I want to compile java programs programatically. I am using exec for that. The problem is there is a error in the i am no getting any message from that Process .will u help me how to solve this
    URGENT
    pyari
    Code Snippet
              try
                                  String command = "cmd /c javac -classpath c:\\j2ee\\home\\ejb.jar -d "+
                                  "c:\\javapr~1\\WeblogicEJBComplier\\tempBuild "+
                                  "C:\\j2ee\\home\\demo\\ejb\\cart\\CartClient.java";
         System.out.println(command);
         Runtime rnt = Runtime.getRuntime();
                                  Process prs = rnt.exec(command);
                                  BufferedReader bfr = new BufferedReader(new InputStreamReader(prs.getInputStream()));
                                  String str = bfr.readLine();
                                  System.out.println(str);
                                  while(str!=null)
                                       System.out.println(str) ;
                                       str = bfr.readLine();
              }catch(Exception eo)
                   System.err.println(eo);

    javac writes the errors in stderr, not in stdout.
    So replace getInputStream() with getErrorStream()...

  • HELP for Compile java programe !

    Hello All,
    i want to make java programe by which i can compile java programes
    and when i compile java programe from my programe then
    i shoul get compiled status means programe compile successfuly
    or not compile.
    if any example i m thanksfull.
    onlyforjava.

    how about if compile fail?
    the process obj seems return value 0 as it run successful.
    I haven't try this, but I have experienced the process obj returns 0 if the executed command has some routine to handle error cases, in which, error will not halt the system.
    So, I recommand the following scenario.
    1. let say, if your java is test.java. check the existence of file test.class.
    If, it exists, get its modified time.
    2. compile the java code with
    Procress p = Runtime.exec(new String[]{"javac", "test.java"});
    3. get the error string if any.
    InputStream in = new BufferedInputStream(p.getInputStream());int read;while ((read = in.read()) != -1){  System.out.println((char)read);}
    4. handle error with the exitValue
    if (p.exitValue() != 0){  System.out.println("warning.");}
    5. check again the file test.class if it is a newly created file.
    6. if it is newly created, compile success. Else, failed.

  • Not able to compile java program

    Hi
       I a using Netweaver to deelope the java code.I have written a javaprogram .But when choose the option Run as
    a javaApplication it giving the following error
    Source locator  doesnot Exist:org.eclipse.jdt.debug.ui.javaSourceLocator

    Hi,
    I am able to compile and run perfectly Java programs. The steps goes as:
    1. File --> New --> Project --> Java --> Java Project --> give a <project name> --> Finish
    2. File --> New --> Class --> give a classname, and package name.
    3. Put main method and give a System.out.println("Hello");
    Source code:
    package com.i3l.trg;
    public class HelloWorld {
         public static void main(String[] args)      {
              System.out.println("Hello");          
    4.Goto Run --> Run As --> 2 Java Application.
    5. You will get a output as "Hello" in java console.
    Cheers!!!
    Sukanta Rudra
    PS: Liberally donate points.
    The full source code is

  • Exception when running a compiled java program in DOS

    I'm new to programming in general and java in specific. I am using the jGrasp programming software, and successfully compile my program, but when I try to run it out of DOS (which I undesrtand is the purpose of java to begin with, unless I'm mistaken), I get an exception that looks exactly like this.....
    Exception in thread "main" java.lang.NoClassDefFoundError: keyboard/java
    Caused by: java.lang.ClassNotFoundException: keyboard.java
    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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I realize I may just be missing something simple, as I've not been in the class for very long, but the book doesn't seem to have the answer. It is "Starting out with Java: Early Objects, Third Edition, by Tony Gaddis. Any help will be apprecieated. The program is below, it's really short.
    The program is a simple one to teach myself scanner input and an 'if' statement:
    *     basic input program
    import java.util.Scanner;
    public class keyboard
         public static void main(String[] args)
              String Class;
              int age;
              String race;
              char sex;
              String gender;
              Scanner keyboard = new Scanner(System.in);
              System.out.print("What class do you wish to be? ");
              Class = keyboard.nextLine();
              System.out.print("How old is your character? ");
              age = keyboard.nextInt();
              keyboard.nextLine();
              System.out.print("What sex is your character? M/F? ");
              gender = keyboard.nextLine();
              sex = gender.charAt(0);
              System.out.print("What race is your character? ");
              race = keyboard.nextLine();
              if (sex == 'M')
                   System.out.println("Today you will be playing a " + race + " " + Class +
                                                           " who is " + age + " years old at the start " +
                                                           "of his adventuring career!");
              if (sex == 'F')
                   System.out.println("Today you will be playing a " + race + " " + Class +
                                                           " who is " + age + " years old at the start " +
                                                           "of her adventuring career!");                                   
    }

    Childofheinlein wrote:
    I'm new to programming in general and java in specific. I am using the jGrasp programming software, and successfully compile my program, but when I try to run it out of DOS (which I undesrtand is the purpose of java to begin with, unless I'm mistaken), I get an exception that looks exactly like this.....
    So summerizing some of what was said before and some of that wasn't.
    jGrasp is a simplistic IDE. When you pop a dos window from it it sets up the windows correctly to run your program. When you open a regular command window you must do the same yourself.
    >
    Exception in thread "main" java.lang.NoClassDefFoundError: keyboard/javaJava runs "classes". The command that you typed above meant that you were trying to run a "file". Specifically the file "keyboard.java". The two are not the same. There is however a relationship. When the source code, in this case inside of "keyboard.java" is compiled it produces a file called "keyboard.class". Insided of the file there is a "class" called "keyboard". Notice that the name of the class does not have either .java nor .class on the end of it.
    The VM (the 'java' command) finds a "class" using the class path to search files of various types for the class (again keep in mind that files contain classes but they are not themselves classes.)
    You can add to the classpath using the Sun VM using either command line options or environment variables. As noted in some of the previous messages those are "-cp" and "CLASSPATH". It is important to note that that does NOT fully specify the class path. But for your purposes it is sufficient to think of it as doing so.
    The 'default' setting for the part of the class path that you normally set (like via '-cp') is the current directory which is specified by the ".". So normally the following are equivalent.
    java -cp . keyboard
    java keyboard
    The reason the VM could not find your class when you opened the dos window yourself is because you were in the wrong directory. If you had been in the directory with the file "keyboard.class" then it would have worked (if you have not messed with the environment variable "CLASSPATH".)
    So if your class file has the following location: c:\myapps\java\keyboard.class then you can do the following.
    1. Open a console window
    2. Type "cd c:\myapps\java"
    3. Type "java keyboard"
    If the above does not work then you are in the wrong directory or the env variable CLASSPATH has been set to something.

  • How to compile java programs? There is no javac for me!

    Hi, I'm starting to learn java and downloaded the java 1.4.0.1 standard edition from this website. However, after I installed the program, there is no javac to be found while there is a java.exe. I need javac to compile my program before I can interpret it but it is nowhere to be found!
    Did I download the wrong SDK version? I thank anyone in advance who can help me in the right direction!

    You must have the SDK to create programs. The Jre is a component of the SDK that can be downloaded separately if you only want to run programs.
    SDK downloads from here, use the row "Windows (all languages, including English)" and be sure to select the SDK COLUMN, not the JRE:
    http://java.sun.com/j2se/1.4/download.html

  • 32 bit compiled Java Program not connecting to 64 bit Oracle 11g

    Hi,
    I am using one java program to connect to Oracle 11g (64 bit version) using Oracle10g 32 bit client libraries using OCI calls. Below is the program. If I compile it using 64 bit Oracle 10g libraries ($ORACLE_HOME/lib and $ORACLE_HOME/rdbms/lib) , it perfectly connects to Oracle11g but when i compile it using $ORACLE_HOME/lib32 and $ORACLE_HOME/rdbms/lib32, it hangs and keeps trying and takes 100% cpu usage. it does nothing. Please suggest what is going wrong in the environment.
    ============================
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws Exception
    Class.forName ("oracle.jdbc.OracleDriver");
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@lvfd", "fde", "fde");
    // or oci7 @TNSNames_Entry, userid, password
    try {
    Statement stmt = conn.createStatement();
    try {
    ResultSet rset = stmt.executeQuery("select * from tab");
    try {
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    } finally {
    try { rset.close(); } catch (Exception ignore) {}
    } finally {
    try { stmt.close(); } catch (Exception ignore) {}
    } finally {
    try { conn.close(); } catch (Exception ignore) {}
    ================================================

    >
    I am compiling like when LD_LIBRARY_PATH set to $ORACLE_HOME/lib32:$ORACLE_HOME/rdbms/lib32.
    javac -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess.java
    as my program resides in current directory. I run it like :
    java -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess
    Output: it hangs forever.
    I am compiling like when LD_LIBRARY_PATH set to $ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
    javac -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess.java
    as my program resides in current directory. I run it like :
    java -cp .:$ORACLE_HOME/jdbc/lib/ojdbc14.jar dbAccess
    Output: It gets connected and list all the tables as output.
    >
    The ojdbc14.jar file is for use with Java 1.4 VMs.
    Are you still using Java 1.4? If so, why?
    For Oracle 11g you should be using the latest JDBC jar file (ojdbc6.jar) and the latest version of Java 1.6.
    You are not only using an old JDBC driver and Java version but are also trying to mix 32 bit and 64 bit operations.
    I suggest you start using recommended practices and update your Java and JDBC versions and select EITHER 32 bit or 64 bit operations.
    See the Official JDBC FAQ for the details on the support available for various combinations of Oracle DB, Java and the JDBC drivers:
    http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html

  • Code to compile java program

    hello,
    i am studying msc(information systems) 2 years course.
    this is my first semister.i am doing prof\ject in java.
    TITLE:Designing editor for java in java.
    I want to know how to compile a program written in the editor.i will feel very much happy,if u could tell me the suggestion.And alse running the class file.
    thanking you...

    Hi rajesh!
    First you need a java development kit (jdk).
    If you didn't get it yet you can download the actual version on this page (just search for "download").
    If you've installed the jdk make sure that the path where you installed your jdk is set to your systems path value (windows)
    you can put it in by editing your autoexec bat or by giving the following order to your dos box:
    1.) PATH (returns the actual path settings)
    2.) SET PATH old values, [...]\jdk\bin
    After having done this you should reboot your system.
    Now you can change the directory to your programs path and call:
    JAVAC yourfile.java
    this compiles your program
    JAVA yourfile
    (without any file extension!!) runs your program
    It might be useful to download the API Documentation, where the jdk tools are all descripted!!
    hope it helps,
    Thof

  • Error compiling Java Program

    I am new to java programming.
    I recently took a java class. In the lab we created a simple program.
    The program was split up in two separate files.
    //Vehicle.java
    public class Vehicle {
         private double load;
         private double maxLoad;
              public Vehicle(double max_Load) {
                   load = 0.0;     
                   maxLoad = max_Load;
              public double getLoad(){
                   return load;
              public double getMaxLoad(){
                   return maxLoad;
              boolean addBox(double weight) {
                   if ((weight + load) > maxLoad)
                        return false;
                   else
                        load=weight+load;     
                        return true;
    }//end of class Vehicle
    on a complete separate file
    public class TestVehicle {
    public static void main(String[] args) {
    // Create a vehicle that can handle 10,000 kilograms weight
    System.out.println("Creating a vehicle with a 10,000kg maximum load.");
    Vehicle vehicle = new Vehicle(10000.0);
    // Add a few boxes
    System.out.println("Add box #1 (500kg) : " + vehicle.addBox(500.0));
    System.out.println("Add box #2 (250kg) : " + vehicle.addBox(250.0));
    System.out.println("Add box #3 (5000kg) : " + vehicle.addBox(5000.0));
    System.out.println("Add box #4 (4000kg) : " + vehicle.addBox(4000.0));
    System.out.println("Add box #5 (300kg) : " + vehicle.addBox(300.0));
    // Print out the final vehicle load
    System.out.println("Vehicle load is " + vehicle.getLoad() + " kg");
    when we complied the program we ONLY compiled TestVechile.java
    ( javac TestVechile.java) and BOTH the class compiled successfully. When I tried to compile the TestVehicle class at home I got an error at line 6 in TestVehicle.java.
    Please any help would be greatly appreciated.
    - Alex

    To compile TestVehicle.java, you need either Vehicle.java or Vehicle.class -- with neither of them, the compiler doesn't know whether "new Vehicle(10000.0)" is legal or not.

  • Compiling Java program from other java program

    Hi,
    How can I compile and capture the compilation result from another java program?
    Thanks

    As if I had seen somewhere a hint about being able to
    programatically compile with the help of the class
    sun/tools/javac/Main found in the tools.jar.I saw that article, too, but when I took a look at the JDK's source code, it became apparent that none of the classes in tools.jar are supported. Your program could break with any new version of the JDK.
    If you're still interested, here's the URL:
    http://java.sun.com/developer/JDCTechTips/2003/tt0722.html

  • Problem compiling java programs

    when i run javc in command prompt it runs fine but when i try to compile any program through command prompt it gives following error:
    javac: file not found
    usage: java <options> <source file>
    use -help for list of attributes
    what shouls i do plz help

    yogiis wrote:
    when i run javc in command prompt it runs fine but when i try to compile any program through command prompt it gives following error:
    javac: file not found
    usage: java <options> <source file>
    use -help for list of attributes
    what shouls i do plz helpuse set path="path of java/jdk/bin folder with double quotes" then press enter
    otherwise if you are ussing windows system goto to my computer properties and use advanced tab then use environment variables, there use user/system variables and check is there any exisiting path named variable is there or not if there click on edit and use ; and paste the complete path there. press ok, apply. Then use the command.

  • Compiling java programs

    Hi,
    Does it matter whether you compile your java program (to be run as applets) using jdk 1.5 or 1.4 or 1.3? Am I right to say that as long as it's compiled successfully, it will run from any browser?
    Thanks :)

    No, but the compatibility isn't with the browser but with the "plugin" that the browser uses to run Java.
    Each new major released of Java introduces new features and extensions to the class library which won't be there if the version of the plugin is older than the compiling environment.
    Class files actually contain the release number of the compiler that generated them and the JVM checks that it can handle the release in question.
    In a production environment you don't use applet tags but more complex HTML which specifies the release of the plugin required and directs the user to download the appropriate one if it's not already installed.
    (Annoyingly Windows Internet Explorer doesn't handle this properly if the person running the browser isn't allowed to install software).

  • Cannot compile java Programs

    hi everyone,
    when i tried to compile a java Program i had created.I got the following Error.
    Error occoured during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object
    I reinstalled the entire thing from the system and when i tried to compile the java Program again it gives like a 1000 errors even on the programs i know that work fine and even the very basic 5 or 10 line Programs.Can someone tell me what is happening??

    Having Deleted a file in the folder that i was executing the javac seem to have fixed the problem.It was called String.java
    and the content of the file were as mentioned under:Any help on why it happened or what the file was doing would be really appreciated.
    The content of the file:-
    ""Java String Examples
    The String class implements immutable character strings, which are read-only once the string object has been created and initialized. All string literals in Java programs, are implemented as instances of String class.
    The easiest way to create a Java String object is using a string literal:
    1.
    String str1 = "I can't be changed once created!";
    A Java string literal is a reference to a String object. Since a String literal is a reference, it can be manipulated like any other String reference. i.e. it can be used to invoke methods of String class.
    For example,
    1.
    int myLenght = "Hello world".length();
    The Java language provides special support for the string concatenation operator (+), which has been overloaded for Java Strings objects. String concatenation is implemented through the StringBuffer class and its append method.
    For example,
    1.
    String finalString = "Hello" + "World";
    Would be executed as
    1.
    String finalString = new StringBuffer().append("Hello").append("World").toString();
    The Java compiler optimizes handling of string literals. Only one String object is shared by all strings having same character sequence. Such strings are said to be interned, meaning that they share a unique String object. The Java String class maintains a private pool where such strings are interned.
    For example,
    1.
    String str1="Hello";
    2.
    String str2="Hello";
    3.
    If(str1 == str2)
    4.
    System.out.println("Equal");
    Would print Equal when executed.
    Since the Java String objects are immutable, any operation performed on one String reference will never have any effect on other references denoting the same object.
    String Constructors
    String class provides various types of constructors to create String objects. Some of them are,
    String()
    Creates a new String object whose content is empty i.e. "".
    String(String s)
    Creates a new String object whose content is same as the String object passed as an argument.
    Note: Invoking String constructor creates a new string object, means it does not intern the String. Interned String object reference can be obtained by using intern() method of the String class.
    String also provides constructors that take byte and char array as an argument and returns String object.
    String equality - Compare Java String
    String class overrides the equals() method of the Object class. It compares the content of the two string object and returns the boolean value accordingly.
    For example,
    1.
    String str1="Hello";
    2.
    String str2="Hello";
    3.
    String str3=new String("Hello") //Using constructor.
    4.
    5.
    If(str1 == str2)
    6.
    System.out.println("Equal 1");
    7.
    Else
    8.
    System.out.println("Not Equal 1");
    9.
    10.
    If(str1 == str3)
    11.
    System.out.println("Equal 2");
    12.
    Else
    13.
    System.out.println("I am constructed using constructor, hence not interned");
    14.
    15.
    If( str1.equals(str3) )
    16.
    System.out.println("Equal 3");
    17.
    Else
    18.
    System.out.println("Not Equal 3");
    The output would be,
    Equal 1
    Not Equal 2
    Equal 3
    Note that == compares the references not the actual contents of the String object; Where as equals method compares actual contents of two String objects.
    String class also provides another method equalsIgnoreCase() which ignores the case of contents while comparing.
    Apart from these methods String class also provides compareTo methods.
    int compareTo(String str2)
    This method compares two Strings and returns an int value. It returns
    - value 0, if this string is equal to the string argument
    - a value less than 0, if this string is less than the string argument
    - a value greater than 0, if this string is greater than the string argument
    int compareTo(Object object)
    This method behaves exactly like the first method if the argument object is actually a String object; otherwise, it throws a ClassCastException."""
    Edited by: Gold_y on Oct 30, 2009 4:59 AM

  • Compiling java program from cygwin

    I have to compile a java code fromcygwin...how to do that
    JAVA cmd workd but for javac its tells command not found

    Moreover this has absolutly nothing to do with Socket Programming -> Compiling

Maybe you are looking for

  • Monitoring using oracle10g enterprise manager

    hi i am working as dba. i want to moniotor the data entry operators that they are entering their data regularly. and also, i want to check regularly that how many records are entered by each user daily. i want to use oracle10g enterprise manager for

  • What is the "variable" field in the timer.swf widget for?

    I have captivate 7, and would like to know what the variable field is for in the timer widget and how to use it... Thank you!

  • Error 405 resource not allowed!!

    i trying build web services with: --netbeans 4.1 beta --sun java application server 8 --jwsdp 1.5 --os: windows xp pro i try a simple web services hellows...when i build the web services is successfuly....but when i open in internet explorer is error

  • Toshiba recycling program

    Hi, i've noticed at the bottom of the notebook page of toshiba's website there is an ad that says "how much is your old laptop worth?" Neat toshiba has some sort of a notebook recycling program.  Now, here's my question, Can you send them two compute

  • Experiencing massive Lag in Illustrator CS6

    Hello All, I'm experiencing a huge amount of lag on my computer when running CS6 Illustrator, on my Windows 7 PC which can regularly run large 3D files, and render and animate them with relative ease.  My copy of Photoshop, Indesign, and all other ad