aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How can I build a console application in Eclipse when Eclipse doesn't support it properly? (afaik) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How can I build a console application in Eclipse when Eclipse doesn Watch "How can I build a console application in Eclipse when Eclipse doesn New topic
Author

How can I build a console application in Eclipse when Eclipse doesn't support it properly? (afaik)

Nick Singh
Greenhorn

Joined: Jan 08, 2012
Posts: 11
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18889
    
    8

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: 6109
    
    6

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).
Nick Singh
Greenhorn

Joined: Jan 08, 2012
Posts: 11

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).
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Then you must set your class path correctly.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
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.


Joanne
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

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:

java -classpath ..\..\.. com.nicholaskolatsis.testproject.BuildChapter

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.


JBoss In Action
Nick Singh
Greenhorn

Joined: Jan 08, 2012
Posts: 11
Peter Johnson wrote:
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:

java -classpath ..\..\.. com.nicholaskolatsis.testproject.BuildChapter

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I build a console application in Eclipse when Eclipse doesn't support it properly? (afaik)