How can I build a console application in Eclipse when Eclipse doesn't support it properly? (afaik)
Nicholas Kolatsis
Greenhorn
Joined: Jan 08, 2012
Posts: 11
posted
0
I've made a command line script that downloads images from a certain website (useful for me since I have no internet at home). It is my first non-book (Head First Java) app I've made so I'm very happy with it as it is. Now that I've done the script, I want to make it a console based app instead. The big problem is that Eclipse does not seem to support it that well. Take this code for example:
The output is 'No console.' in Eclipse. That pretty much stops me in my tracks from making a console app with Eclipse. Is there a workaround?
One solution I've got playing in the back of my mind is to just roll my own gui console that allows me to pass arguments during runtime. I have no idea how hard that'd be or if it's even realistic so I'd prefer some other solution that'll allow Eclipse to function how I want.
Bonus Eclipse question:
When I try to run compiled code I've exported from Eclipse, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: BuildChapter <wrong Name: com/nicholaskolatsis/testproject/BuildChapter>
When I try to compile the .java file, it throws up a bunch of "error: cannot find symbol" errors for the other classes in the script.
I'm guessing both are because of some kind of package problem. I have the entire project under com.nicholaskolatsis.testproject so I'm not sure what's happening.
People have been writing console applications by reading from System.in and writing to System.out for decades now. Admittedly it isn't as nice as the new Console class, but it's still a possibility.
As for a GUI console... yes, that would be a complicated thing to write, but I'm sure what you want to do could be done with an ordinary GUI application. For example "passing parameters" would be replaced by ordinary input fields.
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3143
posted
1
Nicholas Kolatsis wrote:I've made a command line script that downloads images from a certain website (useful for me since I have no internet at home). It is my first non-book (Head First Java) app I've made so I'm very happy with it as it is. Now that I've done the script, I want to make it a console based app instead. The big problem is that Eclipse does not seem to support it that well. Take this code for example:
The output is 'No console.' in Eclipse.
So don't run it in Eclipse. Apps are typically only run in an IDE for testing during development, and for many non-trivial apps, it's simply not practical to run it in the IDE.
That pretty much stops me in my tracks from making a console app with Eclipse.
No, it only stops you from running it in Eclipse. HUGE difference.
Is there a workaround?
There's no workaround necessary. You just need to learn to run Java programs from the command line (which, frankly, you should have done before ever touching an IDE such as Eclipse).
Nicholas Kolatsis
Greenhorn
Joined: Jan 08, 2012
Posts: 11
posted
0
There's no workaround necessary. You just need to learn to run Java programs from the command line (which, frankly, you should have done before ever touching an IDE such as Eclipse).
I know how to compile from the command line lol but I do have a problem with compiling any code I've made in eclipse (see the bonus question).
Nicholas Kolatsis wrote:I know how to compile from the command line lol but I do have a problem with compiling any code I've made in eclipse (see the bonus question).
The second part of your statement would suggest the first part is not completely true. Assuming your command line JDK is the same or a later version as the Eclipse JDK then you will be able to compile the code on the command line as long as you use the correct command line parameters.
If you post the errors you are getting then someone should be able to guide you.
Exception in thread "main" java.lang.NoClassDefFoundError: BuildChapter <wrong Name: com/nicholaskolatsis/testproject/BuildChapter>
Sounds like you are being tripped up regarding package naming and directory structure. I would assume that you working in the com/nicholaskolatsis/testproject directory, both for compile and to run the app and that when you run you do something like "java -classpath . BuildChapter". That is incorrect because you don't have a BuildChapter class, you have a com.nicholaskolatsis.testproject.BuildChaptyer class. You could either run this:
cd ..\..\..
java -classpath . com.nicholaskolatsis.testproject.BuildChapter
The above code will take you to the root directory for your project and then invoke the class with the correct name. The other possibility is to stay where are and run:
This will set the classpath to the project's root directory, then Java will find the class properly.
Correctly understanding the relationship between package names and directory names is one of the hurdles you face when learning Java. I recall it well, assuming I knew what that relationship was until I hit a similar situation to what you are facing when I have to straighten out my thinking. After that, lots of stuff suddenly starts making sense.
Exception in thread "main" java.lang.NoClassDefFoundError: BuildChapter <wrong Name: com/nicholaskolatsis/testproject/BuildChapter>
Sounds like you are being tripped up regarding package naming and directory structure. I would assume that you working in the com/nicholaskolatsis/testproject directory, both for compile and to run the app and that when you run you do something like "java -classpath . BuildChapter". That is incorrect because you don't have a BuildChapter class, you have a com.nicholaskolatsis.testproject.BuildChaptyer class. You could either run this:
cd ..\..\..
java -classpath . com.nicholaskolatsis.testproject.BuildChapter
The above code will take you to the root directory for your project and then invoke the class with the correct name. The other possibility is to stay where are and run:
This will set the classpath to the project's root directory, then Java will find the class properly.
Correctly understanding the relationship between package names and directory names is one of the hurdles you face when learning Java. I recall it well, assuming I knew what that relationship was until I hit a similar situation to what you are facing when I have to straighten out my thinking. After that, lots of stuff suddenly starts making sense.
Thanks, this is the reply I needed. +1
subject: How can I build a console application in Eclipse when Eclipse doesn't support it properly? (afaik)