*
The moose likes IDEs, Version Control and other tools and the fly likes java run command in Eclipse 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 "java run command in Eclipse" Watch "java run command in Eclipse" New topic
Author

java run command in Eclipse

Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
Hello,

I need to run an application from 'outside' of eclipse. Until now I was allways starting it from 'run/run as/Java App' or a similar short-cut.

Since this app uses a lot of external jars, the command should be pretty long (java -cp blahblah.jar;asfd...).

If I could find out how Eclipse does it I would save a lot of time.
I was looking all over 'run/open run dialog...' but cannot find it there.

Any idea where I can find it, or make it visible?

Thanks!


I hate 'trial and error'<br />and I am doing it all the time
Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
I dont know why you are not able to see all the options in the run dialog.
Open Run dialog.
Create a new configuration for running your application. There will be different tabs for configuration. In classpath tab you can set classpath and in the arguments tab you can provide program and vm arguments.


Paras Jain
SCJP 5.0
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
Sounds as though you need a .jar file with your classpath in the Manifest file. Go through this part of the Java Tutorial, and find out how to create self-executing .jar files in Eclipse.
Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
I see I did a bad job explaining my problem

All is working fine with the code and with eclipse.

I only need now to take the class outside of eclipse to be started somewhere else (in this case by a batch file in win).

For that batch file I would like to use the same command line eclipse uses internally to call the main class. But I cannot find it anywhere. Or is there a flag somewhere to display that command in the console?

Many thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
On Windows? If you copy an executable .jar file to your desktop (or maybe even a link to it) you can usually start it by double-clicking. You might need to set up some file associations, however.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
You should find it easy enough to set up a batch file in Windows, but that will require the user to know the location of your executable .jar.
Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
Thanks, but it has to be a batch file.
and the main class uses jars but it is not within one.

Where can I find the complete command eclipse uses to start this main class?


When I was using JBuilder it was possible to see it somewhere. Eclipse should have it somewhere visible
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
Somebody else asked a similar question a few weeks ago: see whether this thread is any help.
Henning Mortensen
Greenhorn

Joined: Mar 12, 2009
Posts: 4
did you ever find it? I can not find it either, but need it too ;-)

I have seen it a while ago, so eclipse can certainly do it. It was a page showing "java -...." with all options, parameters and of course all the required jar files. Ready to paste into a command line window or a batch file.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

You can't use the "batch file in Eclipse" because there isn't one.

The Run subsystem keeps a "database" of profiles to run/debug. When you create one, its classpath consists of the classpath of the project in question (stored in the project's .classpath file) plus any run-specific overrides you put into the profile dialog. When you select Run off the Eclipse menu, Eclipse sets up a debugging JVM and supplies it with this composite classpath. Along with the VM and command-line parameters and other options.

You could probably extract most of what you need from the .classpath file. If you're really clever, you can even automate the process by doing XSLT on it.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just rightclick project and choose to export project as JAR file. The wizard which will show up is fairly self-explaining.

You can run JAR files in Windows by just doubleclicking it or using the java -jar command in the command console.
Henning Mortensen
Greenhorn

Joined: Mar 12, 2009
Posts: 4
I found it, a colleague of mine knew the answer :

You run the program from eclipse, then you to debug perspective, in the window where the tasks are, you can right click on the main task, and it shows you the command line as you would have to do, if you want to start the program from a command window or from a batch file.
So this is what you do, if you are really clever! And of course there is no batch file in eclipse. Nobody claimed that.
Of course you can get all the information from the run dialogue, but that is a lot of work if you have hundreds of jar files, command line options etc.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Henning Mortensen wrote:
And of course there is no batch file in eclipse. Nobody claimed that.

Javoso Torso wrote:Thanks, but it has to be a batch file.
and the main class uses jars but it is not within one.

Where can I find the complete command eclipse uses to start this main class?



Evidently we read this in 2 different ways.

However it sounds like you know something I don't, and I can't figure out how it works. Instead of generic instructions on how to generate a command line, could you enumerate them with their exact names? For example, I don't know what you mean when you say "in the window where the tasks are". I can't find anything in the Run Configurations dialog that does that, and the closest thing I have to a literal "tasks windows" is the Tasks View, which is a to-do list and (as far as I can see) doesn't have that capability.

If there's an easier way than what I've been doing, I certainly want to know!
Henning Mortensen
Greenhorn

Joined: Mar 12, 2009
Posts: 4
sorry, I am from those days where a task was a process, so I still tend to call a thread a task ;-). I mean in the window where the threads are shown. Sometimes there will only be the main thread. In my debug perspective window it is top-left. I have two tabs there, one says Debug, the other Servers. When I click on the Debug on, I see the Threads of the last run application. There I click on the "terminated", which then shows the java(w) command.



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

It had occurred to me, but I didn't see it. Here's how it works:

1. In the Debug view, select an application (running or otherwise)

2. Open up the tree view of this process and right-click on either the main class or the JVM

3. Select the Properties menu item.

4. This will display the Process Properties Dialog. One of the elements in it is the Command Line.

5. Using the usual clipboard copy-and-paste facility, select copy the command line text and paste it into your favorite text editor.

6. Add embellishments as desired and save as a script file.

Thanks! I never noticed this feature before.
Henning Mortensen
Greenhorn

Joined: Mar 12, 2009
Posts: 4
It is also a very well hidden feature! ;-)
sanjib kumar
Greenhorn

Joined: Apr 15, 2011
Posts: 1
Thank you all. Tricky & much informative.
In my project I need to launch Eclipse work-bench & start a Junit Master Suite in Eclipse UI. I do it by manually performing this action -- Right click on test suite -> Run As -> Junit Test.

I could start Eclipse from a batch file. Is there any way to run the test/program directly on Eclipse UI without manual intervention?
i.e. batch file would start Eclipse & start the TestSuite directly on Eclipse UI..

 
 
subject: java run command in Eclipse