| | |
Stupid question about java.exe
Thread Solved |
•
•
Join Date: Dec 2005
Posts: 45
Reputation:
Solved Threads: 0
Hello, I know this question is stupid, but I cannot find an exact answer to it.
I am using Eclipse, and have written some classes to be used as a small database editor for XML. It compiles and runs fine in Eclipse.
However, I made it so that it can be used by people who are not programmers, and therefore probably don't have Eclipse. So I thought it'd be easier just to run 'java TEditor' (as it is named) in command prompt.
When I try to run the program using java.exe, though, it says 'Exception in thread "main" java.lang.NoClassDefFoundError: TEditor'.
A couple more things:
1) I am absolutely sure my class has a main method.
2) My classes have already been compiled, unless Windows is lying to me and TEditor.class is not really there, or if I am just delusional and think its there.
3) I tried manually compiling another, smaller class with javac.exe. Then I tried running it with java.exe, and got the same error.
It may be a problem with my CLASSPATH and PATH settings. I tried setting my CLASSPATH to the location of my lib\tools.jar location, as someone else had written, and my PATH includes bin\ in my Java directory.
It has been (obviously) a long time since I have used javac.exe to compile and java.exe to run a program, but I don't think that my CLASSPATH variable is correct.
Sorry for my dumb question
I am using Eclipse, and have written some classes to be used as a small database editor for XML. It compiles and runs fine in Eclipse.
However, I made it so that it can be used by people who are not programmers, and therefore probably don't have Eclipse. So I thought it'd be easier just to run 'java TEditor' (as it is named) in command prompt.
When I try to run the program using java.exe, though, it says 'Exception in thread "main" java.lang.NoClassDefFoundError: TEditor'.
A couple more things:
1) I am absolutely sure my class has a main method.
2) My classes have already been compiled, unless Windows is lying to me and TEditor.class is not really there, or if I am just delusional and think its there.
3) I tried manually compiling another, smaller class with javac.exe. Then I tried running it with java.exe, and got the same error.
It may be a problem with my CLASSPATH and PATH settings. I tried setting my CLASSPATH to the location of my lib\tools.jar location, as someone else had written, and my PATH includes bin\ in my Java directory.
It has been (obviously) a long time since I have used javac.exe to compile and java.exe to run a program, but I don't think that my CLASSPATH variable is correct.
Sorry for my dumb question
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
You are most likely correct that you're having a classpath issue.
My guess is you're on a windows machine.
Create a file called database.bat (the real name doesn't matter, but the .bat part does)>
then add the following code into your bat file...
# cp stand for cp here...
set cp = <one of your required jar files>
set cp = %cp%;<another one of your required jar files>
...
set cp = %cp%;<directory to your compiled code. you usually only have to state the base directory and all the class files will be brought in.>
java -cp %cp% TEditor
Then you should be good. Of course you're going to have to play with it a little bit, but the above bat file should work for you.
My guess is you're on a windows machine.
Create a file called database.bat (the real name doesn't matter, but the .bat part does)>
then add the following code into your bat file...
# cp stand for cp here...
set cp = <one of your required jar files>
set cp = %cp%;<another one of your required jar files>
...
set cp = %cp%;<directory to your compiled code. you usually only have to state the base directory and all the class files will be brought in.>
java -cp %cp% TEditor
Then you should be good. Of course you're going to have to play with it a little bit, but the above bat file should work for you.
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
Hmmm.
I would recommend trying to jar up your application and then pointing your classpath toward your jar file. I'm not exactly sure how to get individual classes into the classpath. I think you just point to their base directory. But i'm not positive.
Are you using packages? That could be part of the issue if you're not.
To jar up your application. in a command prompt window go to your applications directory and type: jar -cvf <your jar name>.jar /<the first folder of your package name> and your should get a new jar file in your directory named <your jar name>.jar. Then place this jar file in your classpath.
I would recommend trying to jar up your application and then pointing your classpath toward your jar file. I'm not exactly sure how to get individual classes into the classpath. I think you just point to their base directory. But i'm not positive.
Are you using packages? That could be part of the issue if you're not.
To jar up your application. in a command prompt window go to your applications directory and type: jar -cvf <your jar name>.jar /<the first folder of your package name> and your should get a new jar file in your directory named <your jar name>.jar. Then place this jar file in your classpath.
•
•
Join Date: Dec 2005
Posts: 45
Reputation:
Solved Threads: 0
I made my classes into a jar file. The folder it now is in is C:\jarme\
and the jar filename is
myjar.jar
I tried something to the effect of:
set cp=C:\jarme\myjar.jar;C:\jarme\
java -cp %cp% myjar.jar
Which did not work, nor did I really expect to, so I tried
java -cp %cp% TEditor
Which did not work either, but gave a longer error message about the native methods. So I tried
java -jar C:\jarme\myjar.jar
And that gives the error "Failed to load Main-Class manifest attribute from\nC:\jarme\myjar.jar" (except the \n is a new line)
and the jar filename is
myjar.jar
I tried something to the effect of:
set cp=C:\jarme\myjar.jar;C:\jarme\
java -cp %cp% myjar.jar
Which did not work, nor did I really expect to, so I tried
java -cp %cp% TEditor
Which did not work either, but gave a longer error message about the native methods. So I tried
java -jar C:\jarme\myjar.jar
And that gives the error "Failed to load Main-Class manifest attribute from\nC:\jarme\myjar.jar" (except the \n is a new line)
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
Are you using packages in your java classes? If you're using packages you need to go <your>.<package>.<extension>.<here>.TEditor
Here is an example without packages that works.
I created a java file called Test.java in my C:/java/src/examples/examples directory...
I then opened a command prompt window and navigated to the C:/java/src/examples/examples directory and ran the following command:
javac -verbose -cp . Test.java
I recieved the following output:
[parsing started Test.java]
[parsing completed 31ms]
[search path for source files: [.]]
[search path for class files: [C:\jdk1.5\jre\lib\rt.jar, C:\jdk1.5\jre\lib\jsse.jar, Z:\jdk1.5\jre\lib\jce.jar, C:\jdk1.5\jre\lib\charsets.jar, C:\jdk1.5\jre\lib\ext\dnsns.jar, C:\jdk1.5\jre\lib\ext\localedata.jar, C:\jdk1.5\jre\lib\ext\sunjce_provider.jar, C:\jdk1.5\jre\lib\ext\sunpkcs11.jar, .]]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/String.class)]
[checking Test]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/OutputStream.class)]
[wrote Test.class]
[total 313ms]
I then created a new .bat file in C:/java/src/examples called test.bat...
Finally in my command prompt window i navigated to C:/java/src/examples and then ran the following command:
test.bat
I recieved the following output:
test
[edit]
I also just tried this example with creating a jar file... And it still works. (Luckly for me.)
So, to use a jar file...
Create the jar file by being in the C:/java/src/examples/examples directory in a command prompt window and run the following command:
jar -cfv test.jar Test.class
I recieved the following output:
added manifest
adding: Test.class(in = 406) (out= 277)(deflated 31%)
Then i changed the test.bat file to:
I then re-ran the test.bat file and recieved the following output:
test
[/edit]
Here is an example without packages that works.
I created a java file called Test.java in my C:/java/src/examples/examples directory...
Java Syntax (Toggle Plain Text)
// Notice no package info... public class Test { public static void main(String[] args) { System.out.println("test"); } }
I then opened a command prompt window and navigated to the C:/java/src/examples/examples directory and ran the following command:
javac -verbose -cp . Test.java
I recieved the following output:
[parsing started Test.java]
[parsing completed 31ms]
[search path for source files: [.]]
[search path for class files: [C:\jdk1.5\jre\lib\rt.jar, C:\jdk1.5\jre\lib\jsse.jar, Z:\jdk1.5\jre\lib\jce.jar, C:\jdk1.5\jre\lib\charsets.jar, C:\jdk1.5\jre\lib\ext\dnsns.jar, C:\jdk1.5\jre\lib\ext\localedata.jar, C:\jdk1.5\jre\lib\ext\sunjce_provider.jar, C:\jdk1.5\jre\lib\ext\sunpkcs11.jar, .]]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/Object.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/String.class)]
[checking Test]
[loading C:\jdk1.5\jre\lib\rt.jar(java/lang/System.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading C:\jdk1.5\jre\lib\rt.jar(java/io/OutputStream.class)]
[wrote Test.class]
[total 313ms]
I then created a new .bat file in C:/java/src/examples called test.bat...
Java Syntax (Toggle Plain Text)
set cp=C:\java\src\examples\examples java -cp %cp% Test
Finally in my command prompt window i navigated to C:/java/src/examples and then ran the following command:
test.bat
I recieved the following output:
test
[edit]
I also just tried this example with creating a jar file... And it still works. (Luckly for me.)
So, to use a jar file...
Create the jar file by being in the C:/java/src/examples/examples directory in a command prompt window and run the following command:
jar -cfv test.jar Test.class
I recieved the following output:
added manifest
adding: Test.class(in = 406) (out= 277)(deflated 31%)
Then i changed the test.bat file to:
Java Syntax (Toggle Plain Text)
set cp=C:\java\src\examples\examples\test.jar java -cp %cp% Test
I then re-ran the test.bat file and recieved the following output:
test
[/edit]
![]() |
Similar Threads
- Quick Question: Is J# the same thing as Java? (Java)
- Java.exe and High CPU Usage (Windows NT / 2000 / XP)
- Java Executable? (Java)
- This may be a stupid question.... (C++)
- Stupid Newbie Question (C)
Other Threads in the Java Forum
- Previous Thread: Java Coursework Assessment
- Next Thread: Simple question about using JDBC to access DB2
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows





