I have an assignment for school where I need to download files from github, edit code, and run and test them. I downloaded the files into a general project folder in eclipse, but can't seem to figure out how to run the java files within eclipse. So far I've been getting by with just using the command line, but it would be much faster and more efficient to do everything within eclipse.
There are multiple java files each with a main class. They are all under the same project and I don't want to have to make individual projects for each. Most of my googling has had the answer "right click -> run as -> java project", but I am using eclipse neon and do not see that option. When I try to set up a run configuration, the project does not show up for the project field and if I manually enter it it says that the project does not exist. Any ideas on how to get this working? Thank you.
Edit- The way that I got the files from github was by clicking "File -> Import -> Projects from Git -> Clone URL -> Master (Next) -> Next ->
The simplest way to launch a Java program is to run it using a Java Application launch configuration. This launch configuration type uses information derived from the workbench preferences and your program's Java project to launch the program.
In the Package Explorer, select the Java compilation unit or class file with the main method you want to launch.
Press the Run [ The Run button ] button in the workbench toolbar or select Run > Run from the workbench menu bar. Alternatively, select Run As > Java Application in the Package Explorer pop-up menu, or select Run > Run As > Java Application in the workbench menu bar, or select Run As > Java Application in the drop-down menu on the Run tool bar button.
Your program is now launched, and text output is shown in the Console View.
I downloaded the files into a general project folder in eclipse
This is your problem - to launch java classes you want a java project
OK. It appears that I may have figured this out and have things the way that I want them. Thanks to #markspace for this link that describes a similar problem. The simple solution was to create a new java project that had the same name as the github folder that I was downloading from, then change the source from default to the local git folder where the files are located. I could then use the other recommended solutions to right click, then run as java application to run everything within eclipse. Thank you everyone for your help.
Related
I am working on one simulator with netbeans IDE. I downloaded one simulator from their official website and it's install an running correctly in cmd.
I import existing project of one simulator into netbeans IDE and included all three libraries, so it have no error. But when i click on run icon, it gives me the following error.
So, as you see on the console tab(text with red marker), that's the error in which i need help. Thanks in advance...
Reason is you working directory in not correctly set in Eclipse for this project.
I was having same problem so I changed it.
Here is screenshot of my working directory. This Might help someone.
During the configuration of One with eclipse make sure that your run configuration path must be in synchronization with the arguments otherwise it will throws an error like you posted.
Steps:
Go to Run -> Run Configurations
After setting the proper configuration of one eclipse, Click on DTNSim present in core
Open Run Configuration Window
Click on Java Application-> Open Drag bar-> Click on DTNSim
Go To Arguments
Check Default and Others path:
It must be like the picture attached here!
One Simulator Working Window
I am new to java. I have just got Eclipse working (somehow) lol. well my programs are running fine until-
I save a program, close out of eclipse, and re-open the program. when I try to run it the same way that works for all the other programs, I am getting a message asking to "run with ant build". for some reason eclipse will not run any of my programs that have been closed out and re-opened, but will run new programs just fine.
does anyone know how to fix this???
thanks
EDIT- i would post an image, but I do not have at least 10 reputation.. what is happening is I go to open file => C:\Documents and Settings\xxxxxx\workspace\t\src\t (t is the program's name) and then I open it, and run it. When I run it (either F11 or the run button) it pops up a window saying "select what to run as", and the only options are 2 ant build icons. Running as ant build does not work, because this isn't an antbuild file. I created a new program just to test, (from scratch) and everything compiles and runs fine...
everything is compiling and running fine on NEW programs, but I just tried opening a program I created yesterday, and it is giving me the error mentioned above.. it was running perfectly fine yesterday. also, I have JDK installed at home, and I am getting this same exact problem.. JDK isn't the source.
EDIT- i have 10 rep now. Here's an image of what was happening before the fix
" what is happening is I go to open file.."
You don't want to open the file. You want to open the project
Click on File menu
Click on import
Click on General
Select on Existing Projects into Workspace. CLlick Next
Click Browse to search from your project
Select the Project, Click OK
Click Finish
The project should now show in your package explorer and you can then run it.
To run program JRE is enough.
If you want to build project you need JDK.
Eclipse is a Java application and it works without JDK,but it needs JDK to build a project.
Eclipse is not compiler or something like that, it's only an IDE.
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
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.
This may well prove to be a simple config change, but I can't seem to find an obvious setting to solve the following problem:
I have a Vaadin project in Eclipse, which is configured to be debugged with Tomcat v6. If I select the top of the project in the project explorer and hit debug, the eclipse browser launches and my web app opens with the following url:
http://localhost:8080/MyVaadinProject/ THIS WORKS
However, if I'm currently looking at a java file (say Myproject.java), Eclipse tries to open the java file at this url:
http://localhost:8080/MyVaadinProject/WEB-INF/classes/com/example/myproject/Myproject.java
Of course, that produces a 404.
Having to deselect/close my java files every time I want to debug is quite tedious. Is there some way to prevent this behaviour in eclipse?
I am on OSX Lion, Eclipse version 3.7.2.
Thanks!
When running the project, instead of highlighting the class file in the Project Explorer, highlight the very base of the project before running.
This is what we want to run anyway, not the class file itself.
Go to
Windows -> Preferences -> Run/Debug -> Launching
There, at the bottom, select "Always launch the previously launched application".
Now you just have to click your project name in the package explorer and do a Run As -> Run on Server once.
After that launch, you will just need to hit the Run Button and your application should always start the way it should be.