1

i have some java files included in package com.das.dbmodule. when i run these java files using netbeans or eclipse they works well. But i get some errors when i try to run them using command prompt. i tried it using default package but same problem. i have put all java files in jdk bin folder. i am using mysql data base and mysql connector jar file. i get errors like

C:\Program Files\Java\jdk1.6.0\bin>cd..

C:\Program Files\Java\jdk1.6.0>cd..

C:\Program Files\Java>cd program files
The system cannot find the path specified.

C:\Program Files\Java>cd java
The system cannot find the path specified.

C:\Program Files\Java>cd jdk1.6.0

C:\Program Files\Java\jdk1.6.0>cd bin

C:\Program Files\Java\jdk1.6.0\bin>javac fileoperation.java
fileoperation.java:47: cannot find symbol
symbol  : class Dbconnection
location: class fileoperation
        Dbconnection dbconnection   = new Dbconnection();
        ^
fileoperation.java:47: cannot find symbol
symbol  : class Dbconnection
location: class fileoperation
        Dbconnection dbconnection   = new Dbconnection();
                                          ^
fileoperation.java:48: cannot find symbol
symbol  : class Filefinder1
location: class fileoperation
        Filefinder1  f              = new Filefinder1();    // call constructor
        ^
fileoperation.java:48: cannot find symbol
symbol  : class Filefinder1
location: class fileoperation
        Filefinder1  f              = new Filefinder1();    // call constructor
                                          ^
4 errors

C:\Program Files\Java\jdk1.6.0\bin>java fileoperation
Exception in thread "main" java.lang.NoClassDefFoundError: fileoperation

C:\Program Files\Java\jdk1.6.0\bin>Pause
Press any key to continue . . .

basically i am trying to create a batch file that will update my server after every 5 min. i am a student developing an web app. please guide me. i have my project demo day after tomorrow.

4 Answers 4

2

You need to read the manual entries for the java and javac commands and/or a tutorial on how to compile and run Java programs. The compilation errors are most likely a result of you not having the MySQL Connector JAR file on the classpath when compiling. Use the "-cp" option, as described in the manual entries.

There is no need to "cd" to the Java installation directory. Just make sure that

"C:\Program Files\Java\jdk1.6.0\bin"

is a component of the batch file's %PATH% environment, then you can simply run the commands as java and javac.


I'm also puzzled why a script to "update my server after every 5 min" should need to compile Java code.

Sign up to request clarification or add additional context in comments.

3 Comments

My java files are fileoperation.java Filefinder1.java dbconnection.java OnlyExt.java NewClass.java
i have set my class path to mysql connector
Maybe you've got the structure of your build directory wrong ... or are in the wrong directory when you run javac.
1

Looks like you have 2 problems:

  1. You need to set your JAVA_HOME environment variable and use it in your script: http://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows

  2. It looks like you aren't understanding how classpaths work in Java. You need to tell the Java compiler where all of the classes are so when compiling it can resolve any dependencies and/or references.

http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/javac.html

The best thing you can do is use a build tool like Ant to generate an executable jar of your source code and call that from your batch script.

Comments

0

It would appear that some batchfile is screwing up, in particular with

C:\Program Files\Java>cd program files

That should most likely be

C:\Program Files\Java>cd "program files"

where the " quotes force the Windows cmd.exe shell to treat the whole quoted phrase as a single directory. Without the quotes, it's attempting to cd into a directory named program, with an unknown second argument named files. With the quotes, it's looking for a directory named program files.

4 Comments

Thanx everyone for your help. But will you please explain me a bit more. i am not getting what is the problem and how to solve it as i am student.... please help me
i have placed my mysql connector into C:\Program Files\Java\jdk1.6.0\bin and all neccessary java in bin folder but still i gives me som error. i have set my class path to C:\Program Files\Java\jdk1.6.0\bin please anyone help me
i am getting errors like java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at Dbconnection.Dbconnect(Dbconnection.java:29) at fileoperation.parsefiles(fileoperation.java:63) at fileoperation.main(fileoperation.java:127)
0

You need to set environment Path variable with C:\Program Files\Java\jdk1.6.0\bin value. After setting Path you may compile and launch java program from within any folder. Error message describes that some classes are not resolved/found during the compilation. Use classpath switch with javac.exe and java.exe to specify the location of these classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.