I just get "No console." when I run that (NB5.5 JDK 1.6). If I try to run it from the command line prompt, it raises a NoClassDefFoundError for "regextester", which is the name of the project/jar, but not the name of my main class, which is "Main".
Why would System.console() return null? And why is it trying to load a class named "regextester" at the command line? My jar should only have one class inside it named "Main", correct?
Are you running it from inside NetBeans in the first case? NetBeans probably runs it in such a way that it is not running with a command prompt window. I'm not a NetBeans user so I don't know how you could change this.
How did you build your JAR file, and how are you exactly running it (what is the command you type in to run it)?
Note that you don't necessarily need to create a JAR file to run a Java application. You can try copy-and-pasting the class RegexTestHarness on the tutorial page and saving it in a file RegexTestHarness.java. Then compile and run it on the command line like this:
Hi Jesper, thankyou for the swift reply. I was running it from inside NB in the first case. Does anybody here know how one can make apps that utilise System.Console run from inside NB?
I built the JAR file by compiling the project inside NB. Then at the command line, I used java -jar regextester.jar This raised NoClassDefFoundError for the class "Main", which is odd. I know this exception means the class was there at compile time, but can no longer be found.
I *thought* my classes were all bundled into the jar file, and you just ran that file. However, I have to go to build\classes and use java regextester.Main, to run build\classes\regextester\Main.class - which works as expected.
So it seems I now stray into "how do I redistribute my Java apps" FAQ territory. =)
I'm close enough to a newbie to identify - I still have some NoClassDefFoundError nightmares. Yes, you do have to take account of packaging when running a java app - you got that right - take special note - java won't find your app and you'll get NoClassDefFoundError if you don't tell it where to look or give it the wrong name. Also happens quite frequently with relatively simple applications if you don't run with -cp . ('.' isn't a period at the end of my sentence; it's setting classpath to current directory.
Note that I found no class named Main in the tutorial, so you should not be trying to compile or run Main. You should have no file named Main.anything. There is a main method in class RegexTestHarness. The main method executes automatically when RegexTestHarness is run. The main method is required for stand-alone applications.
As Jesper mentions above, the tutorial example does not require a jar file or any additional complexities. It's not defined as being in a package, so if you just copy RegexTestHarness to a file and save it as RegexTestHarness.java, you can compile and run very simply; just as he explained.
if you are indeed new to java, i would suggest ditching Eclipse, NetBeans or any other IDE for doing much more than simple editing. learn how to compile and run your code from a command line FIRST. Once you understand the fundamentals, you can move over to the IDE world.
One of the reasons is that right now, you are struggling to learn BOTH the IDE and Java, so it's hard to separate out where the real issue is. A second reason is that the IDE can hide a lot of the issues from you, so you don't get the solid grounding you need.
just one developers 2-cents.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
For some reason, "Vamshi". the private messages aren't working, so I shall have to tell you it is about the naming policy: we require you display first name-space-last name; please go to "my profile" "update profile" and correct your displayed name to comply.
And Roger Gay, please don't hijack somebody's thread by posting an unrelated question. YOu ought to have started a new thread.
Joined: Oct 13, 2005
And Roger, I seem to have misunderstood your reply. I thought you were hijacking; now on reading the thread again I think I was mistaken.