Java Class.java doesn't work??

I've compiled my java file with javac. But then when I type: java ClassName : for example it gives me exception in thread "main" java.lang.NoClassFoundDefError:
I've already set the path, so I don't think that's the problem. Help please. Thanks in advance.

I got the problem all the sudden - it was ok before. even after I reinstalled jdk1.3 as well as jdk1.4, I still got the same error message. I've gotten all the java_home, Path and Classpath setup (worked for a quite long time). I was testing JNDI when I noticed that problem - before that I was testing J2ee stuff and it seems works fine...
any comment?
(error: java.lang.noClassDefFoundError)
thanks.

Similar Messages

  • Sort(java.util.LinkedList java.lang.Object ) doesn't work

    Why doesn't this work?
    LinkedList<Object> sysPropsKeys = new LinkedList<Object>(System.getProperties().keySet());
    Collections.sort(sysPropsKeys);
    cannot fnd symbol
    symbol : method sort(java.util.LinkedList<java.lang.Object>)
    location: class java.util.Collections

    I will admit to not having Java1.5 installed on my machine. Haven't yet had the chance to play with generics, but the above DOES work in 1.4, and SHOULD work in 1.5
    Maybe I'm naive but, System.getProperties() returns a Properties object right?
    According to the API: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html: Each key and its corresponding value in the property list is a string.
    All the keys SHOULD be strings.
    AFAIK string are comparable, and shouldn't throw class cast exceptions
    Thus the keys returned from getProperties SHOULD be comparable, and compatible for comparision.
    Ok, I can see your point in that some hackers abuse the Properties class by putting non string keys/values into the Properties Map. In that case the code would become more like your above. I'd probably still go with a TreeMap though, rather than a sorted list of keys. Most time you want the keys, you want the values as well. So if the intention is to print out a sorted list of system properties, and their values, keeping it in a map is best.
    Just my 2 cents,
    evnafets

  • I did software update, now java in Safari doesn't work.

    I ran software update, now Java in Safari and Firefox doesn't work. How do I fix it?

    I already tried that.
    I am running OS 10.6.8.
    I did a "normal" software update (under the Apple icon).. didn't update the OS to a higher level, it's still 10.6.8. But now certain websites tell me that Java is missing or not working. When I go to the Java site, they say that you can only download the newest Java for OS 7 or higher... that Java is automatically part of OS 6 and should have automatically updated when I do a Mac software update.
    Java used to work. Now that I've "updated" my Mac software, it doesn't work. And there's no way to download and install Java (according to them).
    It's a never ending circle with no solution.

  • How to get access to PageContext in a java class (.java file)?

    Hi all,
    I am trying to get access to PageContext from inside a java class, and it doesn't seem to work.
    I could get the PageContext from a jsp page, at the object instantiation, through the constructor, but my class is not called by a jsp page.
    Any ideas?
    Thanks,
    Paul

    Basically I do not need to change any attributes from pageContext. However I need the pageContext object because I am using a third party component that is initialized with the pageContext .
    I cannot change the implementation of that component: it is a black box to me, I simply need the pageContext in my java class that uses the component.
    Any thoughts based on this clarification?
    Thanks,
    Paul

  • Class unloading doesn't work as described in this forum !!!

    Hi,
    to the problem of dynamic class unloading many people in this forum wrote:
    - write your own class loader
    - load the class to be unloaded later
    - set all instances of your own class loader to null
    - if the work is done set all instances of the loaded classes to null
    - call the garbage collector and the classes will be removed
    I constructed a simple test for the problem:
    - the test class
    public class Impl {
    public String getVersion () {
    return "1";
    - instanciating the test class
    - printing the value of getVersion() to the screen
    - changing the return value of getVersion() and recompiling it (the test application is still runnig)
    - unload try (see below)
    - instanciating the test class
    - printing the value of getVersion() to the screen
    Back to the tipps above. Why doing this? The theory says a class loader stores every loaded class for
    suppressing unnecessary reloads. In reality the classes are NOT stored in the own class loader but in
    the parent of it. If no parameter is given to a class loader's constructor the parent of a class loader
    is the system classloader.
    Let's have a look at the source code of java.lang.ClassLoader.loadClass(...):
    protected synchronized Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
    // First, check if the class has already been loaded
    Class c = findLoadedClass(name);
    if (c == null) {
    try {
    if (parent != null) {
    ### here the loadClass() of the parent is called and the
    ### loaded class is stored within the parent
    c = parent.loadClass(name, false);
    } else {
    c = findBootstrapClass(name);
    } catch (ClassNotFoundException e) {
    // If still not found, then call findClass in order
    // to find the class.
    c = findClass(name);
    if (resolve) {
    resolveClass(c);
    return c;
    My Idea was: Give a null to the class loader's constructor so the classes cannot be stored within a parent.
    Here my test class loader (it is build as it is described within javadoc of java.lang.ClassLoader
    except the constructor):
    import java.io.*;
    public class MyClassLoader extends ClassLoader {
    public MyClassLoader () {
    super ( null );
    public Class findClass ( String name ) {
    byte[] b = loadClassData ( name );
    return defineClass ( name, b, 0, b.length );
    private byte[] loadClassData ( String name ) {
    byte[] ret = null;
    try {
    InputStream in = new FileInputStream ( name + ".class" );
    ret = new byte[in.available ()];
    in.read ( ret );
    } catch ( Exception e ) {
    e.printStackTrace ();
    return ret;
    The loading of the class works fine
    ClassLoader cl = new MyClassLoader ();
    Class c = cl.loadClass ( "Impl" );
    Object i = c.newInstance ();
    Impl impl = (Impl)i;
    The class "Impl" was found and instanciated. But the cast "Impl impl = (Impl)i;" causes a
    "java.lang.ClassCastException: Impl"
    May second idea was deleting all instances of the class to unload from the class loader via reflection.
    A strange way I know but if this is the only way I will do it. But this doesn't work too.
    After deleting the class from the class loader and all its parents the class is still anywhere in the depth
    of the VM.
    Can anybody help me with this problem?
    Thanks in advance,
    Axel.

    <pre>
    I made a similar and simpler program and it worked:
    import java.net.URLClassLoader;
    import java.net.URL;
    public class DynamicExtension {
         public static void main(String args[]) throws Exception {
              URL[] ua = new URL[] {  new URL("file://c:\\TEMP\\") };
              URLClassLoader ucl = new URLClassLoader(ua);
              MyLoadable l =
                   (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
              l.printVersion();
              Thread.currentThread().sleep(10000);
    //you have ten seconds to replace the old version of the LoadableObject.class file
    //so yo?d better had compiled the new one before executing this
              ucl = new URLClassLoader(ua);
              l = (MyLoadable) ucl.loadClass("LoadableObject").newInstance();
              l.printVersion();
              ucl = null;
              l = null;
              System.gc();
    public class LoadableObject implements MyLoadable {
         public void printVersion() {
              System.out.println("version 1");
         protected void finalize() {
              System.out.println("finalizing " + this);
    public interface MyLoadable {     void printVersion();  }
    C:\Java\TIJ2\Test>java DynamicExtension
    version 1
    version 2
    finalizing LoadableObject@1bd03e
    finalizing LoadableObject@4abc9
    The ClassCastException was due to the fact that one class was loaded by the system class loader, the one that appers as Impl impl = (Impl), and the other by MyClassLoader. That mean that they are different for the VM because they are in different namespaces: The namespace for MyClassLoader is the set of classes loaded by itself and those returned to it by his parent class loader as a result of a request to MyClassLoader?s parent class loader to load a class.
    Setting null for the parent of MyClassLoader was in fact the cause of the problem, because that caused a call to a native method called findBoostrapClass. I guess this method looks for the classes in the bootstrap classpath where MyClassLoader shouldn?t be. This causes MyClassLoader loaded the class itself. If MyClassLoader had had the system class loader as its parent the result had been that only one classloader would have loaded the class. This is what happens in the example above so no ClassCastException is thrown.
    In the source code for ClassLoader
    there is the following:
    * The classes loaded by this class loader. The only purpose of this
    * table is to keep the classes from being GC'ed until the loader
    * is GC'ed.
    private Vector classes = new Vector(); /*
    and:
    * Called by the VM to record every loaded class with this loader.
    void addClass(Class c) {
    classes.addElement(c);
    I would like to have seen findLoadedClass checking the already loaded classes in this Vector, but this method is native. Anyway, as the code for loadClass shows, the parent or bootstrap classloader is checked if findLoadedClass doesn?t find the class; Can we guess that findLoadedClass only checks the clases loaded by the classloader, not its parent?
    By the way, could an example like this be made in c++?
    </pre>

  • Priority class command doesn't work with a certain program

    Hello folks,
    I'm trying to automatize the priority class setting of a program named FreeTrack through a command written in the shortcut. Hence in its "target" I've written this (I'm using Windows 7 x64):
    C:\Windows\System32\cmd.exe /c start /REALTIME /AFFINITY 8 "" "E:\Program Files (x86)\FreeTrack\FreeTrack.exe"
    As you can see I also wanted the affinity mask of the program to be set automatically upon launch, and it works fine. The issue is that the priority class remains unchanged to normal.
    I've tried removing the "affinity" command but it didn't work.
    The priority command does its job on another program (for the attempt I used Firefox).
    Is there any explanation for this anomalous behaviour? And, most importantly, is there a solution (which preferably doesn't involve installing additional programs) ?
    Thank you and regards

    All right, I've found a solution; I'll post it for anyone in need. It's not particularly elegant but still functional.
    First of all I've created a .cmd file in the folder where is located the executable of my interest.
    In it, using notepad, I've written as following:
    start /affinity 8 FreeTrack.exe
    ping 1.1.1.1 -n 1 -w 2000 > nul
    wmic process where name="FreeTrack.exe" CALL setpriority 256
    Note that the /affinity command is optional and not required (however, I needed it). Replace "FreeTrack.exe" with the name of your executable.
    The ping part pings a fake IP once and then waits 2000 milliseconds (set a higher waiting time if this one doesn't work).
    The third line changes the priority for all the processes under the name of "FreeTrack.exe" to, in my case, realtime.
    Priority legend:
    Low: 64 Below Normal: 16384 Normal: 32 Above Normal: 32768 High: 128 Realtime: 256
    Since the command prompt window appears for 2 seconds and I don't like that, I've created a .vbs file in the same folder of the .cmd file and executable. This hides the cmd window.
    I've put the following into the .vbs file (edited with notepad):
    Set WshShell = CreateObject("WScript.Shell" )
    WshShell.Run chr(34) & "FreeTrack.cmd" & Chr(34), 0
    Set WshShell = Nothing
    Replace "FreeTrack.cmd" with your .cmd file name.
    I've then created a shortcut on the desktop to the .vbs file and changed the icon to the one of the executable.
    Surely this solution won't work if the program keeps reverting back its priority while running.

  • Java.util.Hashmap doesn't work for a custom object

    Hi,
    i have created a class named ID. I am trying to test it on a Hashmap, but the the "containsKey" and "get" operations do not work. Every operation of the main method returns as if the ID objects have not been inserted. Ideas?
    package swarm.sys.id;
    import java.util.*;
    import java.io.*;
    import swarm.sys.common.*;
    import swarm.sys.interfaces.*;
    public class ID implements IDInterface, Cloneable, Serializable
        String type;
        int body;
        String id;
        private static int idCounter=0;
        public ID(String type, int body)
          this.type=type;
          this.body=body;
          id=type+Ids.padWithZeroes(body);
        public String getType()
          return type;
        }//getType
        public String getBody()
          return Ids.padWithZeroes(body);
        }//getBody
        public int getIntBody()
          return body;
        }//getIntBody
        public boolean equals(Object o)
          if (!(o instanceof ID))
            return false;
          else
              ID id=(ID)o;   
              return (this.getType().equals(id.getType()) && 
                      this.getIntBody()==id.getIntBody());        
        }//equals
        /* factory method, which produces new IDs and afterwards
         * increments the body part
        public static ID newID(String type)
            return new ID(type,idCounter++);
        }//newID
        //implements deep cloning
        public Object clone()
            return new ID(new String(this.type),this.body);
        }//clone
        public String toString()
          return id.trim();
        }//toString
        public static void main(String[] args)
            Hashtable<IDInterface,String> table=new Hashtable<IDInterface,String>();
            table.put(new ID("PEER_",1),"x1");
            table.put(new ID("PEER_",2),"x1");
            table.put(new ID("PEER_",3),"x2");
            table.put(new ID("PEER_",4),"x3");
            table.put(new ID("PEER_",5),"x3");
            ID id1=new ID("PEER_",1);
            ID id14=new ID("PEER_",14);       
            System.out.println("table.containsKey(new ID(PEER_,1)): "+table.containsKey(id1)); //should be true
            System.out.println("table.containsKey(new ID(PEER_,14)): "+table.containsKey(id14)); //should be false
            System.out.println("table.get(new ID(PEER_,1))"+table.get(id1)); //should be x1
    }

    You need to override the hashCode() method.
    http://www.javapractices.com/Topic28.cjp

  • Java Mail Madness - Doesn't Work but shows no errors ?

    What's up folks. I am trying to implement the java mail library. Unfortunately, I have a problem and I don't know how to track it down. Here is the code that I run in the Netbeans IDE.
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendApp {
    public static void send(String smtpHost, int smtpPort,
    String from, String to,
    String subject, String content)
    throws AddressException, MessagingException {
    // Create a mail session
    java.util.Properties props = new java.util.Properties();
    props.put("mail.smtp.host", smtpHost);
    props.put("mail.smtp.port", ""+smtpPort);
    Session session = Session.getDefaultInstance(props, null);
    // Construct the message
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    msg.setSubject(subject);
    msg.setText(content);
    // Send the message
    Transport.send(msg);
    public static void main(String[] args) throws Exception {
    // Send a test message
    send("kernel", 25, "jd@kernel", "[email protected]",
    "re: dinner", "How about at 7?");
    Where kernel is the domain name of my computer. However, when I check my email at [email protected] (fake address) I don't see anything and the program exits with success. I don't know if this is cause of a problem with my Netbeans, my code, or my postfix smtp system. Any help is greatly appreciated !
    SIncerely,
    Justin Dallas

    Hi,
    Did you checked the log for any errors
    catch (Exception e) {
         System.out.println("Exception while sending mail" + e.getMessage());
         e.printStackTrace();
    Or else add the following line in your exception handler and check whether their is any error or not.
    wdComponentAPI.getMessageManager().reportException(e.getMessage());
    Regards
    Ayyapparaj

  • After updating the Java plugin, it doesn't work!

    I uninstalled later versions of Java then installed the new update, It is enabled. Though when in " Start private browsing" mode Java works! Can you supply me with an answer?

    Hi,
    Please check if this happens in [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode].
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [http://support.mozilla.com/en-US/kb/Uninstalling+add-ons Uninstalling Add-ons]
    [http://kb.mozillazine.org/Uninstalling_toolbars Uninstalling Toolbars]
    Safe mode disables the installed '''Extensions''', and themes ('''Appearance''') in '''Tools''' ('''Alt''' + '''T''') > '''Add-ons'''. Hardware acceleration is also temporarily disabled - the manual setting is '''Tools''' > '''Options''' > '''Advanced''' > '''General''' > '''Use hardware acceleration when available'''. [https://support.mozilla.org/en-US/kb/Options%20window%20-%20Advanced%20panel?as=u Options > Advanced]. All these settings/add-ons can also be individually or collectively disabled/enabled/changed in Firefox normal mode to check if an extension, theme or hardware acceleration is causing issues.
    [https://support.mozilla.org/en-US/kb/Options%20window Options]

  • Why this Java Thread program doesn't work as expected?

    Hello all:
    I have a java code as follows:
    My question is why tryThreadB which is set as deamon thread still run
    after the main program return?
    the output of this program looks like:
    HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn Ending main()
    HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn
    However, I think the correct output should be:
    HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn HopalongMarilyn Ending main()
    Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong Hopalong
    ====================================
    <pre>
    import java.io.*;
    public class TryThread extends Thread {
    private String firstName;
    public TryThread(String firstName) {
    this.firstName = firstName;
    public static void main(String[] args) {
    TryThread tryThreadA = new TryThread("Hopalong");
    TryThread tryThreadB = new TryThread("Marilyn ");
    // user thread
    tryThreadA.setDaemon(false);
    // daemon thread
    tryThreadB.setDaemon(true);
    tryThreadA.start();
    tryThreadB.start();
    try {
    sleep(5000);
    catch (InterruptedException ex) {
    System.out.println("Ending main()");
    return;
    public void run() {
    try {
    while(true) {
    System.out.print(firstName);
    sleep(1000);
    catch (InterruptedException ex) {
    System.out.println(ex);
    </pre>
    ====================================
    thank you very much

    Hi,
    From the Thread documentation:
    When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls
    the method named main of some designated class). The Java Virtual Machine continues to execute
    threads until either of the following occurs:
        * The exit method of class Runtime has been called and the security manager has permitted the exit
    operation to take place.
        * All threads that are not daemon threads have died, either by returning from the call to the run method
    or by throwing an exception that propagates beyond the run method.A daemon thread will not stop after the main method returns. It will stop when there are only daemon threads executing.
    So, in your case, thread B will continue to execute as long as thread A (or any other non-daemon thread) is alive.
    /Kaj

  • Unable to increase display size in Yahoo Games Java applet; zoom doesn't work.

    My father is vision impaired. He play texas hold em in Yahoo Games. Once the game java applet launches, he needs to make the card display larger. I can't find any way to do this. he's using a PC with Windows 7.
    == This happened ==
    Every time Firefox opened
    == always ==
    == User Agent ==
    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4

    It's unclear if the problems discussed happen after OJC compiles, or Javac compiles, or both. We have uncovered a bug in the compilation of jspx files using OJC. There is a chance that this bug fix will fix the problems mentioned. Email me at keimpe.bronkhorst AT oracle.com if you want to try out a patched OJC. This is not an OJVM fix, so if you compile with Javac, I can't help you at this time.
    Keimpe Bronkhorst
    JDev team

  • Java for Safari doesn't work correctly at YouTube

    We are trying to use the Advanced Upload Tool at YouTube, but it does not show us all of our hard drives. Only the Macintosh HD - and we have two other drives we've mounted into one 4 TB drive and that is where we store our videos. I haven't been able to find anywhere to change this.

    HI,
    Try repairing disk permissions...
    Launch Disk Utility. (Applications/Utilities) Select MacintoshHD in the panel on the left, select the FirstAid tab. Click: Repair Disk Permissions. When it's finished from the Menu Bar, Quit Disk Utility and restart your Mac. If you see a long list of "messages" in the permissions window, it's ok. That can be ignored. As long as you see, "Permissions Repair Complete" when it's finished... you're done. Quit Disk Utility and restart your Mac.
    Also, from the Safari Menu Bar click Safari/Empty Cache. Relaunch Safari. See if that makes a difference.

  • {@inheritDoc} not working for Java Classes

    Hello,
    i am using {@inheritDoc} for inherting super class's JavaDoc for a perticular function..
    It is working, if super class is my own class. i am able to see all JavaDoc in child class.
    But when i use {@inheritDoc} for extending JavaDoc of java class it is not working.
    i.e. if i am writing {@inheritDoc} in public void actionPerformed(ActionEvent e) method..
    It wont show any javadoc..
    How to add it? Do i need to give source of java classes too???
    And if it is Yes, then where to specifiy. and where to find source of Java classes, do they come with JDK? or NetBeans?? (If yes then where it is in JDK or Netbeans???)
    Thanks,
    Nachiket.

    Yes, you need to have the Java source, with the -sourcepath option, as described here:
    Inheriting Comments from J2SE - Your code can also automatically inherit comments from interfaces and classes in the J2SE. You can do this by unzipping the src.zip file that ships with the SDK (it does not contain all source files, however), and add its path to -sourcepath. When javadoc runs on your code, it will load the doc comments from those source files as needed. For example, if a class in your code implements java.lang.Comparable, the compareTo(Object) method you implement will inherit the doc comment from java.lang.Comparable.
    http://java.sun.com/j2se/javadoc/faq/#incrementalbuild
    If you want the full Java source get it from here:
    http://www.sun.com/software/communitysource/j2se/java2/index.xml
    http://java.sun.com/j2se/javadoc/faq/#sourcecode
    -Doug

  • Why "start abc.doc" doesn't work in my java code

    Hi there:
    I used Runtime.getRuntime().exec("start abc.doc") to view the file in my java code, it doesn't work, but it works when I type in this at command line, could anybody help me out, super thanks in advance.
    Regards

    Hi there:
    The exception is
    java.io.IOException: CreateProcess: start "c:/temp/desktop/bob/data/abc.doc" error=2
         at java.lang.Win32Process.create(Native Method)
         at java.lang.Win32Process.<init>(Unknown Source)
         at java.lang.Runtime.execInternal(Native Method)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at desktop_v1_f.novell.io.IOManager.showFile(IOManager.java:42)
         at desktop_v1_f.novell.core.MainDesktopManager.showFile(MainDesktopManager.java:74)
         at desktop_v1_f.novell.gui.Surfboard.openF(Surfboard.java:267)
         at desktop_v1_f.novell.gui.Surfboard.detailsTable_mouseClicked(Surfboard.java:283)
         at desktop_v1_f.novell.gui.Surfboard_detailsTable_mouseAdapter.mouseClicked(Surfboard.java:320)
         at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

  • How can i run a java class file from shell?

    Hi all,
    I've a .class file named "File" that contains Main method, it is in the package "File2".
    How can I run it by shell command?
    PS: "java -cp . file" doesn't work it launch->
    Exception in thread "main" java.lang.NoClassDefFoundError: File2/File (wrong name: File2/File)
    Thanks in advance.

    Just to understand: is File2 ar jar archive or not? If it is a jar archive, have you tried open File2.jar? If File2 is a directory within the current directory, have you tried java -cp . File2/File? I just tested with a set of classes and it works... Let me be precise:
    * Let us imagine you are working in a directory whole path is PathToDir/
    * in this directory you have the classes put in a directory called File2
    * in order to launch File.class then you would have to invoke :
    cd PathToDir/ (just to be sure)
    java -cp . File2/File
    *if you were to do the following then you would have the problem you describe
    cd PathToDir/File2/
    java -cp . File

Maybe you are looking for