After checking out code for the first time from a repository into Eclipse using the Subclipse plugin, I've found that I am not able to run Java applications anymore. Usually when I right click in the text editor window and select "Run As", I see the option to "Run as Java Application". Now, however, all I see is "Run on server." Is there another way to run it as a Java application or is there some option that I need to re-configure?
Does the class you're trying to run have a public static void main(String[] args) method signature?
I actually figured it out - I checked out the wrong directory. Because the src directory was a sub-directory, it wasn't being recognized as a package and thus wasn't allowing the .java files to be run as Java apps. Once I checked out the right directory, it worked.
You can go to Run As->Run configurations to set where your main class is located, as this was likely changed or not set.
I have seen this if the Eclipse project is not a Java project.
Does it have Java nature?
If not, delete it, and use Check out as.. to ensure it is setup correctly. This behaviour depends on the existance of the .project and .classpath files in the source repository.
Related
I started to use VS Code with Java extension from Rad Hat and I have some problems. For example I want to use interface from another project in workspace but I only found how to add reference to jar libraries, not to source files. It's not a soluiton to make jar file every time I changed one word. I know Idea and Eclipse have this functionality out of the box but I cant find it in vs code. Maybe there are some additional extensions to realize it?
UPD: I was trying to use "java.project.sourcePaths" property in different ways from java.code-workspace.json but I can't see int_proj sources from proj1 in any way.
Add the following configurations in Workspace Settings.json and have a try:
"java.project.sourcePaths": [
"path/to/your/soucefolder",
]
[UPDATE]
Your current working directory is JAVA(WORKSPACE), press Ctrl+, and turn to the option Workspace, then click the logo to open settings.json, which will generate a folder .vscode and settings.json is stored there, then add the above settings. Clean Java language server workspace from Command Palette then run again:
I'm trying to add another class to an IntelliJ project I created. I already have one program in the project and it is running perfectly. I tried to add another program to the same project's src folder but cannot Run this file. The s/w allows me to build and compile the file but I'm only able to Run the first program I created in the project.
I could do this in Pycharm but not in IntelliJ. Am I missing something? Is there a different method to achieve this in IntelliJ?
You should press shortcut :Alt+Shift+F10.Then you could choose which program you wanna run.
If you click on main method not found, it should bring you to the page where you can add the configuration.
I'm posting this query after doing lots of googling and trying out different options for last few days. Is there an easy way to attach source in Eclipse? is the closest answer I found to my question.
From above post, I tried all solutions but each time Eclipse is opening .class file instead of .java file.
Eclipse Details:
Kepler Service Release 2
Build id:20140224-0627
Please let me know if this is a bug with Eclipse or if I am missing something.
If you are using Maven, try this:
Double click on your project in eclipse -> Maven -> Enable Workspace Resolution
This is most likely because Eclipse actually use the class file for declaring the item you have requested the declaration for, and not the source file you think it should be using.
The typical reason for this is if you have a jar file containing previously compiled classes on your build path before (or instead) of the project containing the source you want. This is very rarely desirable as it can take quite a while to discover that your edits do not take effect.
Examine your build path carefully and ensure it is as you want it to be.
Maven is likely supplying a Classpath Container to your project, and generating entries for the Java Build Path based on the pom.xml contents (the JRE System Library is another example of this). Its entries will not have source attachment unless the container decides it will, which is why the Installed JREs preference page offers to let you set Source Attachments. If the pom.xml has something like that, see if you can use it. If not, see if you can configure the Maven container from its context menu. Otherwise, you may simply be stuck.
I had this same problem: when I pressed F3 or tried to open Declaration (after right click) for any element, it took me to the bytecode .class file.
My solution:
I went to the project in Project Explorer:
right click on project name->Properties
Then in Porject Properties window,
Java Build Path->"Order and Export" tab
There I selected the folder with the .java files (source code), which was below the folder having the .class files -in my case "JRE System Library [java-11-openjdk-amd64]", and pressed 'Top' button on the right frame. Then the folder with source files moved to the top.
Finally, pressed "Apply and Close" button.
That solved my problem forever and ever.
The folder
I installed a plug-in which allows me to download the sources for a maven project.
I'm not by my develop machine right now, but I think it was this:
http://marketplace.eclipse.org/content/m2e-dynamic-sources-lookup#.U8gjGWIaySM
With this, you can select a project an have maven download the sources and make then available when you navigate the code in Eclipse. All without "leaving" Eclipse.
Check into your project modules the Java Build Path, look inside the Source tab and verify if you have "Allow output folders for source folders" checkbox flagged; in this case you just need to uncheck it and you will be able to see again the right source from java files.
This is related to the Call Hierarchy in Eclipse IDE.
If you are in a situation, where you're seeing duplicate methods inside the call hierarchy showing Members calling 'myMethod(...)', double-clicking on one of the listed methods may open the .class file instead of the .java file.
When this happens, the solution is to set the search scope in the call hierarchy to Project instead of Workspace.
After setting the search scope, you won't be seeing duplicate methods listed in the call hierarchy, and double-clicking on the listed methods will only open the .java files.
(Using Eclipse DevStyle Dark Theme)
When I try to export my project as a runnable jar Eclise gives me the following error:
No resources selected.
The project runs fine within Eclipse, I already tried to clean the project before exporting, but that didnĀ“t work.
Any ideas on how to fix this.
The problem is most likely with your run configuration.
Go to your Class that contains the main(String[] args) method you wish to automatically run
when the jar is called from the command line
Right-click->Run As...->Application
Make sure it runs to your satisfaction
Now go through the export process as before, selecting the newly created launch configuration.
The last step is key.
I found another solution.
I found that there's a bug in JDK 9.
I solved it by downgrade to JDK 8(1.8.1)
I fixed the problem, I exported the project as an archive file. Then I opened up a new workspace and imported the the archived project. After that I tried to export the project as a runnable jar, after two tries the jar runs as is it should.
I still don't know what the exact cause was but I hope someone how has run into the same problem finds this helpful.
Doing a (project->clean) and creating a new run configuration (with correct project and class name with main() method, selected) solved the problem for me.You just have to select the new run configuration while exporting runnable jar :)
Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
When you click this option in Eclipse you should get a popup that lets you choose what files to export, you need to select the src folder.
I was having this same problem, and I was able to resolve it. Maybe you should cross verify the main class, that you selected in this project. It is possible that some other project's main class may have the same name as the main class you selected. Make sure the main class you selected is the one from the project that you selected.
The problem is your package. You probably renamed it, and in the export option, the program was confused, and it was using the first name of your package.
This is basically happen when you change package name under which you made your program. This will create confusion regarding package, as per program export, main method still written in old package.
To resolve it, Just copy it and paste it in same package with different name and then try to export it. Check for log too.
I was in the same situation. For me deleting existing eclipse installation(not not the project workspace) and opening the existing eclipse workspace with new installation of eclipse was the only thing that worked.
Just copy the project as a new one. Configure the build path by creating new Run/Debug Settings.this would resolve the problem.
I continued to get the "no resources selected" error. I then did the procedure I am quoting and it gave me a MANIFEST file. Then I was able to create an executable JAR.
Quoting: "I exported the project as an archive file. Then I opened up a new workspace and imported the the archived project. After that I tried to export the project as a runnable jar, after two tries the jar runs as is it should."
I also faced the same issue, in my case, I just closed the project and reopened it, now it's wokring
Check that your project is correct at the time when you select the main class.
If the class non exist, it's the standard error of Eclipse.
I need to run Maven from the command line while Eclipse is open. Since this can confuse Eclipse, I configured the two to use different output folders (Maven writes to target, Eclipse m2e uses target-eclipse). This works very well.
But in one of my unit tests, I need to load classes which are part of a project but not on the classpath. Basically, I build my own URL classloader. Now, I have a problem: Which class folder to add?
If the project is open, target-eclipse/classes is the correct choice, otherwise I should use target/classes.
Assume that I know the Eclipse folder and the workspace folder. How can I tell from Java code running in a child process of Eclipse (not an Eclipse plugin) which projects are open and which aren't?
The existence of the folder is not a good criteria since the folder isn't deleted when I close a project.
[EDIT] Basically my question is: Eclipse must store that information somewhere in $workspace/.metadata or in $ECLIPSE_HOME/configuration. In which file do I need to look?
A file [Workspace_Home]/.metadata/.lock tells You the workspace is open.
The list and settings of projects in the workspace are in [Workspace_Home]/.metadata/.plugins/org.eclipse.core.resources/.projects.
It seems like open Java projects have a folder [Workspace_Home]/.metadata/.plugins/org.eclipse.core.resources/.projects/[Project_name]/.indexes, and closed don't have it. - I double checked it, and it seems I was wrong here.
But I just checked that closed Java projects have a file: [Workspace_Home]/.metadata/.plugins/org.eclipse.core.resources/.projects/[Project_name]/org.eclipse.jdt.core/state.dat, and open projects don't have it.
I would just use some configuration parameter (a system property for example), telling where the folder is. See http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html for how to pass system properties when running tests with Maven. The first example in this page shows how to pass the build directory as a system property.