943,957 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3367
  • Java RSS
Feb 21st, 2006
0

Stupid question about java.exe

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ilikerps is offline Offline
45 posts
since Dec 2005
Feb 21st, 2006
0

Re: Stupid question about java.exe

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.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Feb 21st, 2006
0

Re: Stupid question about java.exe

Hmm.... I don't need any jar files for this program, so I just used:

set cp = "<location here>"
java -cp %cp% TEditor

but I got the same error as before.
Reputation Points: 10
Solved Threads: 0
Light Poster
ilikerps is offline Offline
45 posts
since Dec 2005
Feb 21st, 2006
0

Re: Stupid question about java.exe

did you actually type <location here>? Or did you use something like C:/code/src?
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Feb 22nd, 2006
0

Re: Stupid question about java.exe

Yes, I actually typed <location here>. No, just kidding; I am not quite that dumb. Its just that the folder was in my documents, which has some personal information in the name.
Reputation Points: 10
Solved Threads: 0
Light Poster
ilikerps is offline Offline
45 posts
since Dec 2005
Feb 22nd, 2006
0

Re: Stupid question about java.exe

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.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Feb 22nd, 2006
0

Re: Stupid question about java.exe

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)
Reputation Points: 10
Solved Threads: 0
Light Poster
ilikerps is offline Offline
45 posts
since Dec 2005
Feb 22nd, 2006
0

Re: Stupid question about java.exe

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...

Java Syntax (Toggle Plain Text)
  1. // Notice no package info...
  2. public class Test
  3. {
  4. public static void main(String[] args)
  5. {
  6. System.out.println("test");
  7. }
  8. }


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)
  1. set cp=C:\java\src\examples\examples
  2.  
  3. 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)
  1. set cp=C:\java\src\examples\examples\test.jar
  2.  
  3. java -cp %cp% Test


I then re-ran the test.bat file and recieved the following output:

test
[/edit]
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Feb 22nd, 2006
0

Re: Stupid question about java.exe

Thanks, the package thing did finally get it to work. Well, at first it didn't until I put the files into a folder with the same name as the package.
Reputation Points: 10
Solved Threads: 0
Light Poster
ilikerps is offline Offline
45 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Java Coursework Assessment
Next Thread in Java Forum Timeline: Simple question about using JDBC to access DB2





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC