Java and javac fullpath

For a class I'm in we're creating a program that lets you compile a java program. It uses the full path name. ie
javac <pathname>/file.java
This works but when I change it to run it
java <pathname>/file
It doesn't like it and I get a Exception in thread "main" java.lang.NoClassDefFoundError:. I know it exists because when I remove the pathname it works and I know I'm not making a mistake like putting .java or .class at the end.
Is there some option that would allow the java command to accept full path name (I tried this on my personal computer, which is linux, and connected to my school's unix system with both the same result). Or is there some way to get the program to point to the right directory so all I have to do is put java file. If I figure out a solution to the problem I'll type it here but I'm not sure if I will.
Thanks

Either
1) Make sure that there is no permanent CLASSPATH environment variable set and execute the java command from the directory that contains the .class file, or
2) Use the command java -cp . <yourClass> from the directory that contains your .class file.
(be sure to type the period and spaces), or
3) Set a permanent CLASSPATH
Read these topics to understand classpath and prevent further problems of this kind:
Setting the Classpath, and
How Classes are Found
on http://java.sun.com/j2se/1.4.2/docs/tooldocs/tools.html

Similar Messages

  • Running java and javac

    Is there something I can do so I don't have to be in the same directory as the java.exe and javac.exe in order to use to run and compile?

    Go to the page you downloaded Java from, and read the JDK's Installation Instructions, paying particular attention to #5..

  • Classpath for java and javac

    Hi,
    I'm a bit confused as to when include the "current" path to java/javac's "-classpath". For instance, if the project has the following structure:
    test
      |___foo (package "foo")
             |___B.java (extends foo.A)
             |___A.javaand the "current" directory is at "test/", then a simple "javac foo/B.java" or "java foo.B" works. However, if the structure of the project is altered to the following:
    test
      |___foo  (package "foo")
      |      |___B.java (extends foo.A and imports boo.C)
      |      |___A.java
      |
      |___myapp (just a directory)
              |____boo (package "boo")
                    |____C.javathen in order to compile or run foo.B when the current directory is at "test/", I have to explicitly specify the "current" directory (or "."), i.e.
    javac -classpath myapp/:. foo/B.java or java -cp myapp/:. foo.B
    Why is it that in the first example, the current directory need not to be specified (".") but in the second example, it must? Is it because as soon as "-classpath/-cp" option is included in the command line, java ignores the default current path ("./")?
    Sincerely,

    If nothing is specified via -cp and no CLASSPATH is set, then the default classpath contains one entry, which is the current directory (a.k.a the classpath is ".").
    If you set the classpath, then the classpath is exactly what you set it to and doesn't include any default.
    That's the only reasonable way to model such things, because if you included the current directory in all cases, then that would produce many unexpected side effects.

  • Java and javac ????

    What do i need to use these commands in command prompt?
    when i type java all i get is :
    'java' is not a reconized as a internal or exernal command, operable program or patch file.
    This is version j2re1.4.2_09
    Im new to all this, any help would be welcomed.
    Cant even edit

    Osmith, follow one of the following instructions:
    Microsoft Windows, UNIX/Linux or Mac OS.
    They will tell you all you need to know how to get started (compiling and running Java code, setting up your PATH variable, CLASSPATH, etc.)
    Good luck.

  • Using Runtime exec() to open and close process like java or javac

    Hi, I m a student who is learning IT and is wondering if
    Runtime exec() can run and stop commands like java and javac?
    Can someone post the code to do so here?Thank you

    Well, Here is my complete code:
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    public void run()
    try
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ( (line = br.readLine()) != null)
    System.out.println(type + ">" + line);
    } catch (IOException ioe)
    ioe.printStackTrace();
    class Program implements Runnable
         Process proc;
    String args[];
         String[] cmd = new String[4];
         boolean isGone=false;
         public Program(String args[])
              this.args=args;
         public void run()
              if (isGone==true)
                   try
                        Runtime.getRuntime().exec(cmd).destroy();
                   catch(IOException e)
                        System.out.println("Error: "+e.toString());
                   System.out.println("User abort");
         public void start(String args[])
              if (args.length < 1)
    System.out.println("USAGE: java GoodWindowsExec <cmd>");
    System.exit(1);
    try
    String osName = System.getProperty("os.name" );
    if( osName.equals( "Windows NT" ) )
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[3] = args[0];
    else if( osName.equals( "Windows 95" ) ||osName.equals( "Windows 98" ))
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
                        cmd[3]=args[1];
    Runtime rt = Runtime.getRuntime();
    // System.out.println("Execing " + cmd[0] + " " + cmd[1]
    // + " " + cmd[2]+" "+args[1]);                                    
    proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    // int exitVal = proc.waitFor();
    //System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
         public void destroy()
              isGone=true;
    class test1 implements ActionListener
         String s[]={"c:\\jdk1.3\\bin\\java.exe","ContactProcessor1"};
         GUI g=new GUI();
              Program p=new Program(s);
         public test1()
              //didnt work
              g.getStart().addActionListener(this);
              g.getStop().addActionListener(this);
              g.show();
         public void actionPerformed(ActionEvent e)
              if (e.getSource()==g.getStart())
                   p.start(s);
                   p.run();
              if (e.getSource()==g.getStop())
                   p.destroy();
                   p.run();
         public static void main(String args[])
              test1 t = new test1();
    class GUI extends JFrame
         JButton start;
         JButton stop;
         public GUI()
              super();
              getContentPane().setLayout(new FlowLayout());
              start=new JButton("start");
              stop=new JButton("stop");
              getContentPane().add(start);
              getContentPane().add(stop);
              setSize(100,100);
         public JButton getStart()
              return start;
         public JButton getStop()
              return stop;
    }

  • Java versus javac classpath

    hi everyone:
    this is a bit embarassing, as I have been using java for some time, but I recently came across a classpath conceptual difficulty.
    My understanding was that 'javac' uses classpath to find the path to any classes referenced in a target for compilation. However, I couldn't come up with any concrete rationale for using an additional classpath for 'java', the JVM command, when developing your own applications (I can see its importance for third party classes).
    Doesn't javac encode the classpath passed to it in the compiled class file itself? (I figured this because even if I do not specify a classpath to the 'java', the program still executes fine). If this is true, then the only way I see the 'java' classpath being useful is if you were to change around the location of the class files after compilation.
    Any thoughts would be greatly appreciated.

    Btw, there is no distiction between java and javac
    classpaths. They're both the classpath.only difference i see there could be, is that, for
    javac you tell the path to your .java file that
    need's to be compiled, and for java you tell the name
    of class whose main() method it should run (or you
    tell which .jar file to execute)That's not relevant here. Classpath is used the same way for both of them. Classpath has nothing to do with finding a .java file to compile.
    The only difference, I think, is that I think by default, the directory holding the package root of any .java file given as an arg to javac is implicitly added to the classpath. I'm not sure about that though.
    >
    so in some cases you would need to include "." in
    your classpath for execution, but would not need to
    include it for compilation.
    just my 2 cents

  • I'm new to Java and can't get javac command working

    Ok first of all hello ( i'm new to the forum ), second i'm reading a book about Java and im trying to compile a sample code from the book, but javac command gained life and it's against me. So the book i'm reading is Sams Teach Yourself Java in 21 Days (YAY), and the code i want to compile is an application that works with another bit of code that mimics what a robot could do inside a volcano. So the Volcano program code is the following ( i'll post the robot code at the end of the post):
    1: class VolcanoApp {
    2: public static void main(String[] arguments) {
    3: VolcanoRobot dante = new VolcanoRobot();
    4: dante.status = ?exploring?;
    5: dante.speed = 2;
    6: dante.temperature = 510;
    7:
    8: dante.showAttributes();
    9: System.out.println(?Increasing speed to 3.?);
    10: dante.speed = 3;
    11: dante.showAttributes();
    12: System.out.println(?Changing temperature to 670.?);
    13: dante.temperature = 670;
    14: dante.showAttributes();
    15: System.out.println(?Checking the temperature.?);
    16: dante.checkTemperature();
    17: dante.showAttributes();
    18: }
    19: }
    Ignore the numbers they are used for explaining stuff in the book, and i din't copy the indentation.
    So what i do is that i creat a file with notepad ( no fancy stuff only plain old notepad ) and i copy this code, remove the numbers and make the indents.
    After that i save as .txt file with the apropriate name ( i know it's case sensitive ). After that i open command prompt and write:
    javac VolcanoApp.java
    And it tells me that "javac is not recognized as an internal or external command operable program or batch file".
    I managed to solve that by going to the control panel and by adding to the system variables for my user in the path variable this :
    ;C:\JAVAJDK\bin
    ( C:\JAVAJDK is where JDK is installed)
    And then i modified the system variables like this:
    In the CLASSPATH i entered this .;%JAVA_HOME%\lib\tools.jar
    In JAVA_HOME i entered this C:\JAVAJDK
    Setting the variables like this made the javac error go away but now when i write in command line
    javac VolcanoApp.java
    It gives me this error
    javac: file not found : VolcanoApp.java
    Usage: javac options source files
    use -help for a list of possible options
    And then i read that i can drop my java file directly in the javac file. So i did.
    When i drop my VolcanoApp.java in the javac file it open a command line window and writes a bunch of stuff in like a milisecond and shuts down. And no file is created.
    I wanted to know what was writen in that window so i did it again and took a print screen and pasted it on paint ( it writed so much text that i only got a little bit but enough to see what hapend)
    I read it and in the print screen it said it had 15 errors ( so far ) and then it point the errors with little arrows and there were characters that weren't present in the original code.
    What hapend the compiler added wierd letters?
    SO, my real question is, how the heck do i get javac working and compiling stuff properly?
    Plz help i'm getting mad at this! ; (
    And the code for the "robot":
    1: class VolcanoRobot {
    2: String status;
    3: int speed;
    4: float temperature;
    5:
    6: void checkTemperature() {
    7: if (temperature > 660) {
    8: status = ?returning home?;
    9: speed = 5;
    10: }
    11: }
    12:
    13: void showAttributes() {
    14: System.out.println(?Status: ? + status);
    15: System.out.println(?Speed: ? + speed);
    16: System.out.println(?Temperature: ? + temperature);
    17: }
    18: }
    Again no indents and ignore the numbers. In the book it only said to compile the VolcanoApp.java , and not the VolcanoRobot.java
    Edit:
    I'm using Windows Vista Home Premium 32 bit.
    Edited by: BBlop on Dec 13, 2009 11:29 AM

    guess what it says java file. So yes i'm sure. Sarcasm. Not the best way to encourage a total stranger to help you. Then there's
    Sorry if i wasn't more clear but was that response needed?No it wasn't needed, but I'm not the one asking for help so I have the luxury of not worrying too much about it. It's extremely frustrating trying to drag relevant information out of someone, and makes one less inclined to bother.
    Anyways, there's still nothing in this thread that actually explicitly says "there is a file called VolcanoApp.java in the directory where I'm running javac from" and I really can't be bothered banging my head against the wall any longer. You've made a silly mistake, or a false assumption. We all do it from time to time. My advice is, take a break, go for a walk and re-visit this in a while. You'll probably spot the mistake right away.

  • Java works, but jar and javac don't

    java at the command line works, but jar and javac don't
    could it be the CLASSPATH
    I'm running Windows if that helps. If you need more info ask away
    Thanks
    CINC

    Definitely sounds like the classpath problem. From the sounds of the error message, you are using win95/98/ME, and so the best way to get around this is to set the classpath in your autoexec.bat file. I think the problem is because you have to set 2 variables in your path, one for the running of the java (JRE) and one for the tools to process the uncompiled files (SDK);
    rightclick on your autoexec.bat and select Edit
    here is my path, change yours accordingly so the paths lead to your windows, command and bin directories accordingly.
    PATH=D:\WINDOWS;D:\WINDOWS\COMMAND;D:\PROGRAM FILES\JAVASOFT\J2SDK1.4\BIN
    SET CLASSPATH=.;D:\PROGRAM FILES\JAVASOFT\J2SDK1.4\BIN\TOOLS.JAR
    Theres a section on setting classpath in This site at :
    java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
    and if that doesn't work, then i recommend you download and IDE which sorts ou most of these problems for you, and makes programming much easier also :)
    anything from:
    Suns Forte
    Jcreator
    Jbuilder
    to a real heavyweight which i use and find indispensible called Visual Age for Java, which is so powerful, but not for the faint hearted or weak-computered. :P
    Good Luck
    Benji

  • Java and oracle in linux

    hello frnds...i have installed oracle 10g in ubuntu 11.04....now i want to make database connection between java and oracle...so how can i do it??i know the java code..but the main problem is database driver..how can i give the classpath for specific jdbc dirver...pls tell me the steps to set classpath for jdbc driver...
    thnx in advance..

    884540 wrote:
    hello frnds...i have installed oracle 10g in ubuntu 11.04....now i want to make database connection between java and oracle...so how can i do it??i know the java code..but the main problem is database driver..how can i give the classpath for specific jdbc dirver...pls tell me the steps to set classpath for jdbc driver...
    thnx in advance..You can mention the classpath using the javac and java options:
    javac -cp .;<path> <ClassName>.java
    and
    java -cp .;<path> <ClassName>
    Or refer the below link to avoid mentioning classpath everytime you run/ compile the program
    http://www.linuxquestions.org/questions/linux-software-2/j2sdk-install-174483/#post898715

  • CLASSPATH and javac

    Hi all,
    I forgot a lot about Java, and need to relearn a few things. I had a JRE (5.0_06) already installed, and installed the JDK (1.5.0). It seems to me I do not need to use the "old" JRE. Comments? But first things first, I use XP Home SP 2.
    I am now doing a Wireless Development Tutorial where I had to install Tomcat. In the tutorial it says I need to set my classpath. It now points to the JRE (.;D:\Program Files\Java\jre1.5.0_06\lib\ext\QTJava.zip). Where should I point it to if I want to use the JDK instead of the JRE? To .;D:\Program Files\Java\jdk1.5.0\lib\ ?
    Next, I should be able to compile a simple program. But when I type javac, I get "'javac' is not recognized as an internal or external command". How come?
    I sat my JAVA_HOME in the System Properties (Advanced tab, Environmental Variables). I should think that would be enough to let the system find the javac program. The system does not agree with me, so who can enlighten me?
    Macamba

    Hi all,
    I forgot a lot about Java, and need to relearn a few
    things. I had a JRE (5.0_06) already installed, and
    installed the JDK (1.5.0). It seems to me I do not
    need to use the "old" JRE. Comments? But first things
    first, I use XP Home SP 2.
    I am now doing a Wireless Development Tutorial where
    I had to install Tomcat. In the tutorial it says I
    need to set my classpath. It now points to the JRE
    (.;D:\Program
    Files\Java\jre1.5.0_06\lib\ext\QTJava.zip). Where
    should I point it to if I want to use the JDK instead
    of the JRE? To .;D:\Program Files\Java\jdk1.5.0\lib\
    I, personally, do not set the CLASSPATH environment variable. I use the -cp option with the command line tools.
    Next, I should be able to compile a simple program.
    But when I type javac, I get "'javac' is not
    recognized as an internal or external command". How
    come?The is a PATH issue. In you system path, you need an entry that points to your <JDK INSTALL DIR>\bin folder.
    Also, with the JDK, the JRE is bundled under the <JDK Install Dir>\jre folder.
    I sat my JAVA_HOME in the System Properties (Advanced
    tab, Environmental Variables). I should think that
    would be enough to let the system find the javac
    program. The system does not agree with me, so who
    can enlighten me?Again, javac has to be on your system PATH.
    >
    MacambaThe JAVA_HOME environment variable should point to the <JDK INSTALL DIR>
    The CATALINE_HOME should point to the <Tomcat Install Dir>
    For Windows:
    Configuring the JDK
    Configuring Tomcat

  • Compiling error (netbeans and javac)

    Hi,
    I have created a project with netbeans. It has two files Main.java and Methods.java. I can compile and run it using netbeans without any errors. But if I go to the directory where that files are located and try "javac Main.java", I get the error like this:
    Main.java:26: cannot find symbol
    symbol : class Methods
    location : class projectname.Main
    Methods met = new Methods();
    I get this error 2 times.

    cd ..
    javac projectname/Main.java

  • New to Java and already have difficulties

    Alright, I'm running under NetBeans IDE 4.0. I'm taking it through the quick start guide and am now having problems. I am down to the LibClass.java and Main.java. LibClass.java is done without problems that I can see. Main.java is telling me theres a problem in one of my lines.
    The Guide asked me to type in "String result = Li" and then hit "ctrl + space" to bring up code completion and look for LibClass which I cannot find, so I chose to finish the code myself and just typed "String result = LibClass and went on, but its telling me that the line is incorrect. Could anyone help me figure out why its telling me this?

    You know what? Don't touch Netbeans. Delete it and
    get UltraEdit or Textpad or whatever. And then read
    these and the following tutorials:
    http://java.sun.com/docs/books/tutorial/getStarted/cup
    ojava/index.htmlWhat Ceci is suggesting is that you are trying to learn the java language, but by using NetBeans (or any other IDE), you are facing two learning curves .... one for Java, and one for the IDE. This can be very confusing. Instead, use any text editor you are comfortable with, and compile using the command line compiler (javac). The tutorial for your operating system (most likely windows) will help you get started. That way, you are only struggling with learning Java.
    Rene, I hope I have interpreted your post into noobSpeak acceptably.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • ABAP , JAVA And XSLT Mapping Doc's

    Hi,
    I am new to SAP XI Any body please send me the Doc's Related to ABAP, JAVA And XSLT Mappings. Thanks in Advance.
    Regards
    Kiran.B

    Hi
    Refer to
    ABAP mapping:
    How to Use ABAP Mapping in XI 3.0
    JAVA mapping:
    http://help.sap.com/saphelp_nw04/helpdata/en/bd/c91241c738f423e10000000a155106/frameset.htm (Java mapping)
    XSLT mapping:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/01a57f0b-0501-0010-3ca9-d2ea3bb983c1
    /people/prasadbabu.nemalikanti3/blog/2006/03/30/xpath-functions-in-xslt-mapping
    /people/sreekanth.babu2/blog/2005/01/05/design-time-value-mappings-in-xslt
    /people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping
    XSLT Mapping with java enhancement
    /people/pooja.pandey/blog/2005/06/27/xslt-mapping-with-java-enhancement-for-beginners
    XSLT - /people/dirk.roeckmann/blog/2006/07/26/grouping-xml-with-xslt--from-muenchian-method-to-xslt-20
    Regards,
    Kumar.
    Reward points if helpful!!

  • BI Java and BI ABAP -RSPLAN issue

    Hi All
    We are working with BI system ,using BI 7.0 Java and BI ABAP as separate systems on same host.
    Already run the template intaller for BI Java and ABAP integration.
    But facing some issue ,when going ot BI ABAP and RSPLAN and clicking the Start Mideller
    it is opening a browser as http://host:8000/sap/public/myssocntl?sap-client-XXX
    Since this is not correct and it should open BI Java portal instead of ABAP stack page.
    Instead this should open a Url like this http://host:5XX00/webdynpro/dispatcher/sap.com/biplanworkbench1/Modeler?
    I check on BI ABAP system under SAP Reference IMG -> SAP Customizing Implementation Guide-> SAP NetWeaver _> Business Intelligence-> BI Integrated Planning -> Settings for Starting the Planning Modeler.
    There the default Url is BEx Portal Server and the url is        
    http://host:5XX00/webdynpro/dispatcher/sap.com/biplanworkbench1/Modeler
    Can anybody let me know why this is going to ABAP server instead it should go to Java.
    Regards
    Ajay
    Edited by: Ajay Sandal on Mar 10, 2009 2:31 PM

    Hi Ajay ..
    Good news that ur issue is resolved ..
    I have somewhat similar issue .. Hopu u can put some light ..
    I have Bi 7.o with Add on java  ,
    In RSPLAN from ABAP system , modular page is not coming . if i click on start moduler button in RSPLAN ..portal page is coming up and i have to give logging details .
    Please suggest .
    Thanks

  • How to get return value from java and read by other application?

    i want to read return value from java and the other application read it.
    for example:
    public class test_return {
        test_return(){
        public int check(){
            return 1;
        public static void main(String args[]){
           new test_return().check();
    }from that class i make as jar file. How to read the return value (1) by other application?
    thx..

    If your installer is requiring some process it invokes to return a particular value on failure, then the installer is seriously broken. There are a bazillion commands your installer could invoke, and any of them could fail, which in turn could invalidate the entire install process, and any of them could return any value on failure. The only value that's consistent (in my experience) is that zero means success and non-zero means failure, with specific non-zero values being different in different programs.
    About the only control you have over the JVM's exit code is that if your main method completes without throwing an exception, the JVM will have an exit code of 0, and if main throws an exception (either explicitly or by not catching one thrown from below), it will be non-zero. I'm not even sure if that's guaranteed, but I would guess that's the case.
    EDIT: I'm kind of full of crap here. If you're writing the Java code, you can call System.exit(whatever). But nonetheless, if your installer requires certain exit codes from any app--java or otherwise--you have a problem.
    Edited by: jverd on Oct 29, 2009 1:27 AM

Maybe you are looking for