PATH VARIABLES AND RUNNING CLASS FILES

People:
I'm a complete Java neophyte and (slowly) learning. Rather than using the NetBeans IDE I have installed, I'm taking the text editor approach to type my source code.
After I type code into my text editor, does it necessarily matter where I save my text files? For my first application, I created HelloWorldApp.java in Notepad, originally saving the file to the same folder where my J2SE 5.0 installation is stored, which is:
C:\Program Files\Java
My javac (Java compiler) is located in:
C:\Program Files\Java\jdk1.5.0_01\bin
When I was first trying to compile HelloWorldApp.java, I received errors saying the Java compiler couldn't be found; I was told to create a path environment variable so the javac could be found to compile my code. When I went to the control panel to set an appropriate path variable, I deleted a (wacky!) Roxio path (don't even know how that got there), entering in its place:
C:\Program Files\Java
as the new path name, although, again, my Java compiler is located in
C:\Program Files\Java\jdk1.5.0_01\bin
After restarting my computer to implement the new path variable into the operating system, I tried compiling my program, but still got error messages. However, when I moved my HelloWorldApp.java text file from the location where I originally saved it, which was:
C:\Program Files\Java
to
C:\Program Files\Java\jdk1.5.0_01\bin
my HelloWorldApp.java finally compiled to a class file, which I finally ran! Did my program run because I moved the HelloWorldApp text file from C:\Program Files\Java into the C:\Program Files\Java\jdk1.5.0_01\bin folder where the javac is located?
Or did my C:\Program Files\Java path variable allow for the Java compiler to be found, although it's located in C:\Program Files\Java\jdk1.5.0_01\bin ? (This is why I asked above if it matters where you save your text document source code.)
In using a text editor to type source code, where should I save my Java text files next time?
Any help would be much appreciated! Thanks!

Add the following directories to the PATH variable.
C:\Program Files\Java\jdk1.5.0_01\bin
I agree with this part.
and add the following to the CLASSPATH variable
C:\Program Files\Java\jdk1.5.0_01\lib;C:\Program
Files\Java\jdk1.5.0_01\jre\lib;.
Where is this insanity coming from?
You do not need to set your classpath unless you are using a third party library or you have different parts of your program stored under different paths.
OP: You can store your source files anywhere you want to. You should put them somewhere that is easy for you to access. Most people have a common directory for all of their projects, with subdirectories for each project.
The only real restriction on where you put your source files is that the directory struction they are in must match the package statement at the top of the source file.
So, if your file has:
package chat.client.events;
at the top, then the source file must be in a directory named chat/client/events relative to where you keep your source files.

Similar Messages

  • How to run .class file and .jar file in jdev9i

    I want to run .class file and .jar file in jdev9i,what should I do?
    Also,I want to generate .class file and .jar file in jdev9i,what should i do?

    Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
    Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
    Michel

  • 9.0.3 "Bug" report regarding paths, compiling, and running

    I don't know if this is a bug or some kind of strange feature but it caused me to lose about an hour and a half of work before I figured out what was going on.
    BACKGROUND:
    I have a project UVDebug.jpr. It's full pathname is :
    C:\My Documents\OracleJDev\Visia\UVDebug\UVDebug.jpr
    Now this project has one file in it: UVDebug.java, however, this java source code file doesn't live in a subfolder of the folder containing the project. Shouldn't be a problem. It's path is
    C:\My Documents\OracleJDev\Visia\VisiaProject\src\debug\visia\UVDebug.java
    As far as I know now, the files you add to a project can live anywhere.
    The output path (where the class files get created/saved) IS a subfolder of the project folder. It's path is
    C:\My Documents\OracleJDev\Visia\UVDebug\classes
    THIS WORKS:
    If I FIRST click the rebuild project button, the class gets created in the correct folder:
    C:\My Documents\OracleJDev\Visia\UVDebug\classes\debug\visia\UVDebug.class
    If I then click the red bug button to run the project in debug mode, it works fine.
    THIS DOES NOT WORK, BUT IT SHOULD:
    If I DO NOT first click the rebuild project button, but instead, just go directly to clicking the red bug button to run it, then it is supposed to compile the source into a class and then run the class. However, the class does not get created and when it goes to run, it throws a class not found exception.
    If the source code UVDebug.java DOES live in a sub folder of the folder containing the project, then clicking the red bug button WILL compile it and run it. I.e. the source code lives in
    C:\My Documents\OracleJDev\Visia\UVDebug instead of
    C:\My Documents\OracleJDev\Visia\VisiaProject\src\debug\visia
    However if the source code does not live in a subfolder of the folder containing the project, you must first compile the project as a separate step before you click the red bug button to run it.
    I don't know why the situation that didn't work didn't work -- it should have worked as far as I understand. Am I wrong here? Do all source code files and output class files have to be in subfolders of the project if you want to click only red bug instead of rebuild all and red bug?
    Mark Hayworth
    Cincinnati Ohio

    I really don't know exactly what happened as what you have described should all work.
    Try those following steps:
    - Completely clean out your output path
    including any .cdi files you might have
    at the root of your output path
    - Go back in jdev and make sure the runner
    option is to make the application before
    running
    - Run (and/or) debug and it should work, does it?
    Michel

  • Setting up the class root directory and choosing class files.

    I made a simple test application as it is proposed at the J2EE 1.4 Tutorial and all worked.
    (Chapter 24 Getting started with Enterprise Beans)
    Than I deleted the ear file to try out the deploy mechanism again.
    And after generating the new application with File-> New application which worked well I also
    tried to use the EJB Wizard feature of the J2EE deployment tool. After I had selected the appropriate EJB classes to add to my jar, I clicked NEXT and I got the following message:
    The class (converter.Converter) could not be loaded:
    Please consult online help for assistance in setting up the class root directory and choosing class files.
    The online helps isnt very usefull for this type of problem.
    Do you have a hint what to do ?

    Hi san-deepu,
    I couldn't reproduce the error you are having when I followed Ch. 24 tutorial in packaging the ear. Is there anymore information in deploytool's logfile? This is in <user_home>/.deploytool/logfile, or you can run in verbose mode: <as_install>/bin/deploytool -v
    When you say you deleted the ear file, did you also close the ear file in deploytool first? You may also want to exit deploytool () , and try deleting the temporary files. Deploytool usually cleans up the temp files automatically upon exit - maybe there are some left behind that it couldn't delete. On windows the temporary files are located by default in C:\Documents and Settings\Administrator\Local Settings\Temp\sun-dt-Administrator. In deploytool go to Edit --> Preferences --> General to find what the temporary directory is set to.
    Which version of the appserver are you using? jdk version? operating system?
    J

  • Deploying the JSPs, Servlets and Java class files

    Hello All,
    I'm very new to the Oracle 9i AS. We are using Version 1.0.2.2.
    How do we deploy the JSPs, Servlets, and Java class files (simple class files, not EJBs)?
    plese give us the procedure and stpes how to deply or the links for the same.
    Thanks,
    Santhosh.

    Hi
    I guess u r running apache-jserv as servlet engine for your jsp and servlets. If its so, jsp files can be run without any additonal configuration by putting the jsp file under document root or any subdirectory and for running servlets u have to add classpath entries for your servlet in jserv.properties file.
    To make sure that your servlet engine is working, try
    http://servername:port/servlet/IsItWorking, if u get success msg that means servlet engine is working fine.
    Hope this will help
    Regards
    Kumaran

  • 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

  • Running class files from the windows command line...

    Hello Everyone,
    My instructor showed us a way to run class files from the windows command line. However every time I try to run the class file from the command line using a command like: java CruiseHelper.class
    I get an error that states "Exception in thread "main" java.lang.NoClassDefFoundError: CruiseHelper/class"

    Hello Everyone,
    My instructor showed us a way to run class files from
    the windows command line. However every time I try
    to run the class file from the command line using a
    command like: java CruiseHelper.class
    I get an error that states "Exception in thread
    "main" java.lang.NoClassDefFoundError:
    CruiseHelper/class"Classes are not file names. You don't have a class named "CruiseHelper.class", that's a file name. The class name is just CruiseHelper (if you have no package statement in it).
    So,
    java -classpath . CruiseHelper

  • How can i run a program outside of Forte? (Forte and java/class files)

    im making a program with forte... and i have a bunch of class files, i form file and a java file... how can i put these in one file so poeple without forte can run it...
    thanks

    jmburns wrote:
    I am trying to do a silent install of a program I built using LabVIEW 8.5.  I also need to call an exe after the installation, so I am using the "run executable after installation" option on the Advanced tab of the installer.  I then pass the following command lines to the setup.exe:
    /qb /acceptlicenses yes /r
    This installs the LabVIEW program successfully, but does not then run the additional exe afterward.  If I run the setup.exe normally (with no command line parameters), the additional exe gets run.
    Thanks,
    Jason
    This problem is fixed in a future release of LabVIEW. Here's the CAR ID 67549 for tracking purposes.
    Message Edited by Bob P on 07-10-2008 09:10 AM

  • Running .CLASS file in Java JDK1.3.1_19

    Hello
    i am an old java programmer. but stopped for a while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc and did everything as they asked for in the installation but i get an error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main' java.lang.NoClassDefFoundError: C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im kinda confused abt... how do i set that? and wat do i set it as?...
    Thanx for the help in advance!

    i am an old java programmer. but stopped for a
    while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc Why did you install an old version instead of the latest version?
    and did everything
    as they asked for in the installation but i get an
    error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main'
    java.lang.NoClassDefFoundError:
    C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im
    kinda confused abt... how do i set that? and wat do i
    set it as?...Do not set or use the CLASSPATH environment variable. Instead use the -classpath option when compiling or running your programs. Otherwise, you'll never figure out what's going on.
    When asking about compiling problems, you need to post:
    1) The path to all the files used in your program
    2) The prompt where you entered the commmand
    3) The actual command you entered

  • Cannot run .class file.  What's wrong, please?

    Hi,
    I have installed J2SDK1.4.2_03 in D: drive in folder JavaApplications.
    Have appended the path: ;D:\JavaApplications\bin in System Variable.
    Written a simple program named WhatIsYourName.java and saved in D:\JavaPractices
    At D:\JavaPractices> compile the program using javac WhatIsYourName.java and it is OK
    At D:\JavaPractices> checked directory and the WhatIsYourName.class file is there.
    When typed: java WhatIsYourName
    Error message appears:
    Error: could not open C:\Program Files\Java\j2re1.4.2_03\lib\i386\jvm.cfg
    Reinstalled J2SDK1.4.2_03 in D: drive in folder JavaApplications again, same error.
    When I checked the C:\Program Files, there is a bin and lib folders residing in a 1.3.1_07 folder in the JRE folder. The JRE folder is found in a folder called JavaSoft. Is it because of this that the error occurred?
    Could not understand why?
    Please help.
    Thank you very much.
    Theophilus

    Hi ChuckBing,
    You are right. The older version is being found first. After removing the older version I can run the .class file.
    Need to ask you about checking the full path when invoking java which you suggested. At D:\JavaPractices directory am I supposed to type \JavaApplications\bin\java WhatIsYourName ? I don't quite get what you mean.
    Thank you very much.
    Theophilus Mah

  • I can compile java, but I cannot run class file.

    Exception in thread "main" java.lang.NoClassDefFoundError: Demonstrate
    That is the error I get when I type: java Demonstrate
    I have "C:\j2sdk1.4.0\bin" in the path for the Environment Variables in windows xp. I've even tried to insert that into a CLASSPATH several ways and it does not change the error.
    javac Demonstrate.java works fine. That compiled file can work on other computers. Because of that, I do not think it's a setting error. Any ideas ? Thanks for any help.

    Microsoft problem? I like nothing better than bashing M$, but this sounds like a CLASSPATH problem to me.
    I'll assume that your Demonstrate.java does NOT have a package statement in it and has a main method that you'd like to run. If so, you compile like this:
    javac Demonstrate.javaThe result is a Demonstrate.class file in the same directory as Demonstrate.java.
    Now, type this in the command shell right in the directory where Demonstrate.class lives to run it:
    java -classpath . DemonstrateYou won't get that ClassNotFoundException.
    Whenever you see that exception, it means you don't have your CLASSPATH set properly. - MOD
    You won't get ta

  • List of variables and their classes from working script?

    I have a working script that has many variables containing finder references and file path descriptions as strings or Unicode text. It is not easy to remember what these variables refer to. Is it possible to get a listing of all of a scripts variables and their respective class?

    The only way I've seen to do this is with Script Debugger, an alternative script editor that has significant debugging tools such as breakpoints, stepping, variable inspection and more.

  • How can I hide constant variable value in class file?

    hi,everybody.
    I am having a problem with constant variable which define connectted with database(URL,username,password).
    when I used UltraEdit to open class file, I can see constant variable value.
    Thanks!

    OK, let's see. Firstly, if I may correct your terminology, the phrase "constant variable" is a paradox (I think that is the right word). You have either one of the other. You declaration is either 'constant' or 'variable' (ie: it can change at run-time or it doesn't). People often use the term 'variable' and 'declaration' interchangably which is where the confusion lies.
    Anyway, onto the real problem. It seems that you want to protect your connection details (in particular the password, I would guess). Unfortunately, Java compiles not to machine-code, but byte-code which is semi-human-readable. So people, if they are inquisitive enough, will always be able to see it if they try hard enough.
    You can do one of two things:
    (1) Get an 'obfusticator'. An obfusticator is something that you run over Java source files and it completely messes it up (without modifying functionality). You then compile and the original source is such gibberish that the byte-code is very difficult to understand. However, the password will still be in there somewhere.
    (2) Don't put sensitive information into your source. Have this kind of info in external files (encrypted) and allow your class to read this file, decrypt, and use it.
    Hope that helps.
    Ben

  • Running Class file

    Hello,
    I am a beginner.
    I got a problem which is every time I run a class file after compiling *.java. I have to type the whole path
    java -classpath C: (foldername) (filename)
    to run the program.
    It is suppose to be no problem once I can run the command "javac" successfully. Now everytime I have to type
    javac (filename)
    Also the setting still got something wrong which it cannot generate the path to /Lib/tools.jar as well
    Could anyone help me on this?
    Thank you very much
    My operating system is Window 98 SE
    Here is my autoexec.bat setting:
    SET PATH=c:\windows;c:\windows\COMMAND;C:\PROGRA~1\SYMANTEC\PCANYW~1
    @SET CLASSPATH=C:\PROGRA~1\PHOTOD~1\ADOBEC~1
    SET PATH=%PATH%;C:\PROGRA~1\COMMON~1\AUTODE~1
    SET PATH=%PATH%;c:\PROGRA~1\COMMON~1\AUTODE~1
    PATH C:\WINDOWS;C:\WINDOWS\COMMAND
    SET PATH=%PATH%;C:\JAVA\BIN
    set CLASSPATH=.:C:\JAVA\lib\tools.jar
    PATH c:\windows;c:\windows\COMMAND;C:\WINDOWS/DESKTOP
    SET CLASSPATH=C:\WINDOWS\COMMAND;C:\WINDOWS/DESKTOP

    Your batch file overrides the value of CLASSPATH several times. Try putting the paths of everything you require into the last instance of the "SET CLASSPATH" line and then eliminate all other instances of it for purposes of readability.
    By the way, this kind of question should probably not be posted in the "Java Virtual Machine" forum. No offense, but the "New to Java Technology" forum would be more appropriate.

  • How to run class files in a jar independently.

    Hello all
    I have a java file which use an API.jar file which is an API file of some other application of mine.This file form a sought of client for that application.Now i want to run this file from command line which is giving NoClassDefFoundError exception.This exception is because of the dependency over API.jar.I dont want to pack this single file into a jar and then run that jar since it only makes a simple task complicated and makes a simple class look like a big application.Can anybody tell me the solution to it?
    Regards,
    Mansi

    MansiSachar wrote:
    I am working on WindowsXP and the command u just sent is again giving the same exception.The exception is :
    Exception in thread "main" java.lang.NoClassDefFoundError: ûcp
    Caused by: java.lang.ClassNotFoundException: ûcp
    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 think the problem can also be the placement of the dependant jars.do i need to keep them in "bin" folder?I am assuming that in the error message, it says "-cp" not "ûcp" Can you confirm that you entered the command as posted? Because it looks like java.exe sees the -cp as the class to execute instead of the classpath option.
    Try using -classpath instead of -cp. What version of java are you using? (java -version should give you the version).
    If the jars are in the current directory, the placement of the jar files is correct.

Maybe you are looking for

  • Can I watch Blu-ray movies on my MacBook Pro 17-inch?

    If this is possible at all, I think there are two or three issues to be addressed. First, I understand that to display Blu-ray movies, the display must be HDCP compliant. All I know is that mine has adequate resolution (1920 x 1200). I called AppleCa

  • How can i purchase apps using credit card

    i cannot purchase apps from store using credit card "your payment metod is declined" this message appears what shoul i do

  • Special Scenarios for spl screening A1, A2, B1, B2, c1, C2 and C3

    Hi Experts, Can any one explain about the special senarios for SPL screening like A1, A2, B1, B2, and C1, C2, and C3. I have little bit confuse when we use these scenarios can any one explain in details if possible. Thanks in advance for who explain

  • Filr-1.1.653 - Problem installing Filr-1.1.0.655.HP.zip

    Hi there, in a small deployment I tried to install the HP655 with "Field Patch Installation" like described in the readme file. I always get an error "An unknown error has occurred while attempting to install a patch. Please verify that the patch is

  • ITunes syncs ALL episodes of a podcast

    I am subscribed to the CarTalk podcast which is a subscription through audible.com For some reason, even though I have it set to only sync the latest 3 episodes, it syncs all of them, taking up a large space. I've even un-checked the older ones and s