Make eclipse debug my android PROJECT - java

I am writing an Android application using Eclipse. When I click on the project in the left tree view and then click debug, the IDE builds an APK and installs in the emulator / device as expected.
However, if I'm editing a file and forget to first click on the project before attempting to debug, the IDE thinks I want to debug that specific Java file. This is NOT what I want to do, I would like it to build and emulate / install on device as usual.
Is there any way to change this behavior in Eclipse?

In eclipse, you can set in workspace preferences / run-debug / launching to always launch the previously launched application (until you explicitly choose an other application: then it will be the last that will be launched).
This way, no matter where you press (ctrl)F11 or click the debug/run button, the launch configuration you used the last time will be called again.
You will still be able to launch different applications of course, by explicitly calling their launchers (the way you debug now).

The procedure you are using (clicking on the project and selecting Debug as => Android Application is OK, for the first debug session (resp. Run as, non debug).
If you want to debug the app again (regardless of what is selected in the left hand side navigator), you should just click on the Green Run circular icon (or rather on the small > sign on its right side if you want to select a different run configuration) or the little bug on its left (for debug).
If you click on one of the > you will select on of the 8 last run/debugged app. If you are sure that the last one is the one you want to run again, then just press one of these two icons (bug for debug, green arrow for run) instead of the arrows.
When you click on the project and select Debug as what you actually do is configure a default run configuration for this app or class that can be later tweaked through the Run/debug Configurations... to better suit your customisation needs. If you click again, eclipse will detect that it has already generated a default configuration (and will not create a new identical one). Alternately you can directly create your new Run/Debug config directly through the Run/debug Configurations... sub menu.
Since the ADT plugin shipped by Google does not include a Run as... Android Application submenu when you click a java class under an android project, the default launch configuration is the java application or the server application (static main method absent).
Update
To clarify things a bit. What you ask (running your android app whilst having the java class selected in the package explorer is possible). What happens when you press the 'small bug' icon does not depend on what is selected in any navigator.
The "default launch configuration" is poorly phrased.
Let me describe what happens in more detail. When you right-click on a java class say in the package explorer (or the project explorer for Java EE version) eclipse (the navigator) calls all contributions (plugins) having registered a handler for that event and lists possible candidates in a sub menu.
In a standard Java EE eclipse installation you will see at least the run on server option and if the class has a main static method with string array arguments, you will also have a the runs as ... java application option. In both cases, eclipse will generate for you a "launch configuration". These launch configurations (both debug and non debug) are all available in the launcher dialog boxes (accessible via the icons described above). They have a lot of different configuration options depending on their nature (for instance whether you debug on a server or a simple java app or an applet). What I termed the "default configuration" is that for each of this launch configuration categories, eclipse will leave these options empty.
So the first time, you will select the Android project and select the run as... Android application option. This will create a default configuration. In ADT's case, the default configuration will also probably select a default ADV and launch it (if it's not already launched). And on subsequent occasions, it will be enough to press the run or debug icon to redeploy your app back to your ADV and this will happen regardless of what is selected in the navigator.

Related

Eclipse default when multiple ways to run exist [duplicate]

Whenever I hit Debug or Run in Eclipse, I get a dialog asking me what configuration I want to use.
How do I set a default configuration and bind a keyboard shortcut?
Maybe this article from Eclipse One Tips will help you:
How to run the last launched application
The answer lies in a preference hidden on the Run/Debug page:
Go to Window > Preferences > Run/Debug > Launching.
Select the option Always launch the previously launched application. It’s located at the bottom of the dialog.
The preference should look something like this:
Now you’re free to press
F11, Ctrl+F11 or click the Run/Debug
icons on the toolbar with confidence, knowing it’s going to run what
you expect it to run.
One question arises: How do you quickly run a class as a specific
application (eg. a JUnit test) if you can’t press F11 to
run it? You have some options available:
The fastest way is to use keyboard shortcuts. Eclipse allows you to launch classes using a keystroke, including JUnit tests, Java
applications, etc using Alt+Shift+X.
Alternatively, right-click on the class and select Run As. The submenu will show available options for launching the class.
Lastly, you could click the pulldown arrow on the run/debug icons in the toolbar and select Run As. The submenu once again shows
available options for launching the class.
Eclipse plug-ins that add new project types may contribute 'Launch Configurations' to control how Eclipse executes the application. For example, J2EE based projects need to publish content and start the application server. Contrast this with simply starting a JVM for a regular Java application.
When you select a configuration, Eclipse records this for future use. You can access these by selecting the 'Run/Run Configurations' menu item or selecting 'Run Configurations' from the little drop down menu next to the run and debug toolbar buttons. You can also add new launch configurations through the Run/Debug Configurations dialog that opens. In this dialog, you should see one or more configurations that you previously launched. Selecting one reveals all the info Eclipse uses to launch your application. One tab called 'Common' contains options for controlling the your favorites menu. Checking the box next to Run or Debug will add this launch configuration to the top of its corresponding menu.
If you only have a single configuration in your menu then Eclipse will launch it when you click the associated button. If you have more than one then Eclipse launches (sometimes) the most recently used. I say sometimes because, occasionally, one launch configuration causes another to launch, which cause the last used configuration to be the second one when you would expect it to be the first one. Usually this happens to me when I launch an application, which needs to be built and the build launches a tool. When this happens, just select the correct launch configuration from the drop down menu.
You can bind a keystroke combination to the Run and Debug commands through the 'Windows/Preferences' menu item. Then select 'General/Keys' in the tree control on the left.

Eclipse maven launch "has encoutered a problem" No selected resource

Developing a Maven project in Eclipse, when I click the launch button, the launch will often fail with the error:
'Launching project_name' has encountered a problem.
No selected resource
This is because I have not selected a Java class file in the editor before clicking the Launch button (little green play icon).
Usually, I have the maven console, or Git staging view in focus at the time I press the button, so I understand why it is happening, just not how to prevent it.
Surely the play button knows which project to select. Why should it care which view has focus when I press the button? The launch configuration refers to the project via a value like ${project_loc:project_name} in the Base directory field.
Is there a way I can tell Eclipse to just run the maven build, regardless of what focus the IDE has?
I am running Eclipse IDE for Enterprise Java Developers.
Version: 2018-12 (4.10.0) on Ubuntu.
In Window > Preferences: Run/Debug > Launching choose Always launch the previously launched application as Launch Operation.
Make also sure not to use selection based variables like ${git_branch} without an argument.
To make git_branch independent of the selection, specify the resource (file or folder) from which you want to have the current branch name. For example, ${git_branch:/my_project}.

Can you force eclipse to run/debug another project when a particular one is ran/debugged?

I'm working with Ligdx, an API for cross plattaform game development that by default generates at least 2 projects:
The core project: This is the one you are supposed to work on, where all the classes and logic should be placed.
The desktop project: This one is automatically generated from the core project.
The core doesn't have any class to start it because it's supposed to be started from the desktop (or other platforms) project.
It is also always selected -because its what you are working on- so pressing the "run" or "debug" buttons will attempt to run the core project and not the desktop one and immediately fail thus forcing you to select the desktop project before hitting run/debug. This can get extremely annoying, especially when debugging.
So is there a way to force Eclipse to always run the desktop project?
Rekaszeru's answer to this question shows how to set up Eclipse in order to always launch the previously launched application.
You simply have to go to preferences / run-debug / launching and check the "Always launch previously launched application" box as he shown in the picture he used to illustrate his answer:
This will not force one of the projects to always be launched but it would pretty much solve the problem unless you are working on multiple projects at the same time or you alternate between Web/Android/Desktop.
If Your asking how to start a Core project from already existing project present in the eclipse then all you need to do is Right Click on desktop folder of the project and go over Run As and select Java Application
But if that is not what you have posted for I can only understand that you need to understand how a LibGDX project is deployed.... From Desktop project "In xyzMain.java" file you will have a method call to the core project saying:
new LwjglApplication(new Sample(), cfg);
This is where you'r Sample Class from the core project is called over.
But from the title I get a diff feeling that you wish to add another project to your already existing project...
You can do that by changing the build Path of the project....by including Other proj to the one you wish to compile and run.
Hope this helped you out..
I´m not aware of doing exactly what you have described, but I´d suggest using the Launch Configurations menus and dialgos to do what you want in a similar quick way.
Note that you can configure your launch configurations doing: Run -> Run Configurations... (also Run -> Debug configurations...)
Option 1).
Once you have run your Desktop Project, simply use the Run Drop-down button, which contain your launch configurations:
Option 2).
Save a launch configuration file in your Core project (or wherever you want) using the last "common" tab of the launch configuration dialog:
Then you can simply right-click on your that file to launch your Desktop Project:
P.S: I´d also suggest reading a little bit about run configurations in lars tutorial

Stanford CS106a: some java applet errors that do not allow to run the programs

Wasnt able to solve the problems in this screen.
http://s8.postimage.org/n5osf76ed/qestions.jpg
All the code worked a month ago.
What have I changed: I have a different version of eclipse (now: Eclipse IDE for Java Developers 1.5.1.20120920-0737, don't know what the previous one was).
Messed with environment variable. Since this does not effect the ot
Please help.
Try this solution mentioned in this discussion.
I just ran into this problem using standard (not Stanford) Eclipse.
By now this is probably moot for you, but I'll post my solution for
future travelers.
The launch configurations for Assignment 1 default to Applet, so the
containing Karel application isn't launched. To solve this, create
and use new Application launch configurations for each file.
If you already tried to run some of the files, delete the Applet
configs created so you can reuse the names:
Open the project properties (e.g. right click on Assignment 1 and select Properties).
Select Run/Debug Configurations.
Select and Delete each configuration.
Click OK.
May the Force be with you.
Create Application configs:
Right click on java file (e.g. CollectNewspaperKarel.java) and select Run As > Run Configurations...
Select Java Application in the left pane.
Click New Launch Configuration (the icon of a document with a +).
Type a name for the configuration and set its Main class to the associated file (e.g. CollectNewspaperKarel).
Click Apply then Run. (This should run correctly and create a useful entry in the Run History.)
Eclipse will still try to default to Applet, so you will henceforth
need to launch these configurations from the Run History (either from
the Run menu or the pull down on the run button). If you accidentally
launch as default, it will add a useless Applet configuration to the
Run History (e.g. CollectNewspaperKarel (1) ). You can delete this
from the Run Configurations dialog to keep the Run History tidy.
The eclipse used in CS106A is customized for stanford and for "karel the robot" :)
Just download and install it again and things should work just fine.

Preferred way of developing web applications with m2eclipse

When developing Maven web applications I usually resort the the jetty-maven-plugin to quickly launch my application for local testing and debugging. Using the launch with m2eclipse has the drawback of not properly including all sources for debugging, even though they are downloaded by Maven ( see Source lookup does not seem to work ).
What is the preferred way to debug Maven web applications in Eclipse? I'd especially appreciate configurations which work with the gwt-maven-plugin.
My preferred way to develop web applications with m2eclipse is to... not use it. Instead, I use the approach described in Debugging with the Maven Jetty Plugin in Eclipse that I'm quoting below:
Step 1
Go to the Run/External Tools/External
Tools ..." menu item on the "Run" menu
bar. Select "Program" and click the
"New" button. On the "Main" tab, fill
in the "Location:" as the full path to
your "mvn" executable. For the
"Working Directory:" select the
workspace that matches your webapp.
For "Arguments:" add jetty:run.
Move to the "Environment" tab and
click the "New" button to add a new
variable named MAVEN_OPTS with the
value:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y
If you supply suspend=n instead of
suspend=y you can start immediately
without running the debugger and
launch the debugger at anytime you
really wish to debug.
Step 2
Then, pull up the "Run/Debug/Debug
..." menu item and select "Remote Java
Application" and click the "New"
button. Fill in the dialog by
selecting your webapp project for the
"Project:" field, and ensure you are
using the same port number as you
specified in the address= property
above.
Now all you need to do is to
Run/External Tools and select the name
of the maven tool setup you created in
step 1 to start the plugin and then
Run/Debug and select the name of the
debug setup you setup in step2.
From instructions provided by
Rolf Strijdhorst on the Maven mailing
list
Stopping Jetty
In order to stop the jetty server the
"Allow termination of remote VM"
should be checked in debug dialog in
Step 2. When you have the jetty server
running and the debugger connected you
can switch to the debug perspective.
In the debug view, right click on the
Java HotSpot(TM) Client
VM[localhost:4000] and chose
terminate. This will stop the debugger
and the jetty server.
Try to avoid writing code which needs a container of some kind to debug. Always write code that can run independently and wrap it in a very thin layer for deployment (thin layer -> few lines of code -> few bugs).
If you really must, try MockRunner to emulate the app server.
Other than that, you can manually add the sources in the project properties.

Categories

Resources