Project not appearing in Eclipse's explorer - java

I am new to Java programming.
Until now, all I was doing was writing the code on eclipse and running the code there only.
However this time i tried to write a code in text editor and run the same through following:
I created a folder named TEMP3 in workspace. (I could see as well the folders of other projects that I directly created on eclipse.)
Created a hello.java file in text editor which outputs "Hello world" and saved that file in the folder TEMP3 created above.
Now I successfully compiled and run the file.
Now when I open eclipse, I expect to see the TEMP3 Project (and in there the hello class) in eclipse's Package Explorer.
But I don't see the TEMP3 folder.
Why is it so?

You could try to import your new folder "TEMP3" and then it should appears.
I'm studying java from middle february 2017 and I can suggest you to use a correct package structure with right names. It helps a lot during programming.

Eclipse projects must contain at least a .project file for Eclipse to recognize them as a project. The folder you have created doesn't contain this file so it isn't recognized.
In addition to this Eclipse won't recognize a project added to the workspace externally until you do a 'File > Refresh'.
So the best bet is to create a Java project inside Eclipse in the normal way and then use 'Import > File System' to import the hello.java file.
Note that the Eclipse Package and Project Explorers normally hide the .project file so you don't see it in Eclipse. In addition on Linux and macOS the OS doesn't show files starting with '.'

Related

Eclipse - How to import a local source file into the same folder?

I wanted to import a file which was originally not imported into the source folder in Eclipse
What I did was:
I tried placing the file directory into a source file folder, which obviously did not work.
Then I right-clicked on folder->import->File System and tried to import that file, but eclipse then complains Source is in the hierarchy of destination.
What I did in the end was move the source file out of that folder, then import it back in from a different path, which I find really redundant.
What's the best way to include a file like that? Thanks in advance.
If you added (outside of Eclipse) a file to a source directory for your project, you should be able to get the file to show up in Eclipse by right-clicking your source folder in the Eclipse Package Explorer and selecting "Refresh" .
you can not import into the same folder bcz no OS allow to create multiple folder of the same name in same parent. instead, you put the folder being imported somewhere else, and while importing it to workspace, check the option to "copy into workspace"
As of October 2017, using Eclipse Oxygen 2017.1, I found that to accomplish what the OP wanted to do is not to what your natural instincts tell you to do.
In my case, I originally developed the code on Computer A in directory c:\projects\abc\ and copied the directory to computer B in directory c:\projects\abc\ outside of Eclipse.
Instead of
Import / General / File System /
which gives the error the OP mentioned, you instead need to:
Import / General / Projects from Folder or Archive /
When the dialog opens, point the "Import source:" to your already-present-where-it-needs-to-be directory (example: c:\projects\abc).
I left everything else to the defaults.
Click Finish.
When I return to Project Explorer, I did NOT need to Refresh the window. The project automatically showed up.
You've set up your Eclipse workspace and source code to be in the same folder i.e. the folder where your Eclipse .metadata resides is the same place as all your folders of code. Ideally, the folder for Eclipse's metadata should be somewhere else. (I did the same thing myself and then ran into all sorts of problems).
To expand on #user3785010 answer, I found that using Import > General > Existing Projects into Workspace worked for me with Eclipse Platform Version: 2021-09 (4.21).
When I tried Import > General > Projects from Folder or Archive, I pressed Finish and nothing happened.

Eclipse error with archived java projects "editor does not contain main type" [duplicate]

This question already has answers here:
Error: Selection does not contain a main type
(24 answers)
Closed 8 years ago.
I am receiving the errors: Editor does not contain main type, or, Selection does not contain main type when I import an archived Java project into Eclipse and try to run it. I have gotten this error on several different operating systems.
Archive Protocol
Export project
General->Archive File
All are selected: project folder, .classpath and .project
[x] save in zip format
[x] create directory structure for files
[x] compress contents of file
A Work Around That May Explain It... but how?!
I notice that when I import an archived project into an existing project (a blank Java project), The folder hierarchy is something like:
Project
src
bin
imported_project
bin
src
actual_code.java
Now, when I try to run actual_code.java, I get the above error. I discovered the following work around: if I drag actual_code.java and drop it into Project->src and then run it, it works.
This is a nice work around. However, I would prefer to be able to run the imported project without moving things around. Any suggestions on how to do this? It seems like it should be a trivial fix--it simply seems like the project isn't importing to where it ought to.
And yes...
I have tried every method I have come across to remedy this. That includes quite a few from this site and others: syntax, libraries, source path, restart eclipse, rearchive, different operating systems, different machines... etc.
The .java files are in the src folder before I archive them, and my build path seems correct.
You could import the archive as a Project instead of as files into a newly created blank project. Use Import > Existing Projects into Workspace. Then, use Select archive file.
You might want to put the src folder of your imported_project in classpath.
Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder
I also faced the same error ajnd after reading above article i just drag/drop my class-file to src and new class-file generated in src is working fine .
I had the same problem after I New/Java Project then pulling src, docs, lib, examples, ... folders. I could not import it as an Eclipse project since the code is not an Eclipse project. The main is right there in the example code, but the IDE would find it.
The solution for me is deleting the project from the IDE, then recreating it with the Eclipse IDE. When recreating, the IDE cached all the sub-folders for me. Also, make sure you add the code onto the Java Build Path as Source using the 'Configure Build Path...' of the project.
Restarting IDE, closing then reopening the file didn't help me.

Eclipse edit java files and run under original folder

Although this seems an easy thing I'm not able to find the answer for it.
What I'd like to achieve is simple. I have a folder with java source files and I want to edit them using eclipse within a new project. But at the time of running the application I don't want eclipse to use the workspace project folder as "root", instead it should use the folder with the java source files.
The effect should be like opening the source files with a text editor directly and changing them, but instead this should be done through an eclipse project but still use the original folder to run the application.
I just want to have all the advantages that come from editing source files within an eclipse project instead of using something like notepad++.
I tried linking the source files and changing the relative path to the source directory but it doesn't work. When running the application it needs xml files which exist in the directory but because it's running "from" the eclipse project folder it doesn't find them.
I'm not sure I really understand what you want to do, but sounds like you want to set the run configuration's working directory: Open 'Run Configurations', choose the class containing your main method (or create a new run configuration for that class first if it's not yet there), then specify the Working Directory on tab 'Arguments'.
I do same with all my projects. What you need to do is :
Create workspace directory on different location than your source code.
Import your source code in your workspace directory. Here don't copy source to your workspace
EDIT
In Eclipse
Go to File->Switch Workspace->Other-> Type "new directory workspace" path, click OK. Eclipse will restart.
Go to File->Import->General-> Existing Projects into Workspace-> Next-> Select Root directory
Eclipse will list your project, select it.
Start editing and saving files.
Thought this does not directly answer your question, as an alternative to using Eclipse IDE for Java files try using Padclipse which is a text editor based on Eclipse.
Padclipse is a light weight text editor based on Eclipse. The basic
product is composed of Eclipse RCP plus Text Editor, Compare and
Search facilities and their dependencies. A few additional third party
plug-ins are included as well.
Check it out here
Also, the default JDK on my system was a 64 bit because of which starting up padclipse failed. Create a padclipse.ini in the folder where you unzipped it in and put in the following contents :
-showsplash
-launcher
padclipse.exe
-name
Padclipse
--launcher.library
plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.0.v20070523\eclipse_1017a.dll
-startup
plugins\org.eclipse.equinox.launcher_1.0.0.v20070606.jar
-vm
C:\dev\jdk\1.5\1.5.0_21\jre\bin\server\jvm.dll
Change -vm argument to point to the java.exe or jvm.dll of a 32 bit jdk.

How to take package .java files into a Eclipse Project

I've got a copy of a java package, with example implementation. The package is in a structure called com.java.project (folders, containing myriads of .java files) and there's also a few example files (example1.java, example2.java)
The example files have 'import com.java.project' calls in them, that's all well and good. However, I can't seem to work out how to get Eclipse finding the package contents (currently returns "Type not found" for any calls to the project objects.
I've tried placing the com structure in the same level as my example1.java, but that doesn't work. I have read that I need to compile the package into a .jar to get it to work w/Eclipse, but that doesn't seem to want to behave, none of the files compile.
In Eclipse you can right click on the Project Explorer and select "New -> Java Project"
Then you can import your java files by right clicking your project, selecting import from file system. If the class file shows an error, open the class file, the class name should have red curly braces, click on the error tick mark and Eclipse will give you an option to move the file to the correct package which in turn creates the folder structure for you.
1.Can you do a check on the build path of your Java project? (Right-click the project -> Properties -> Java Build Path -> Source tab), and see if the root folder contains the code is properly specified here.
2.Maybe a Project->Clean will help as well.
Hii,
Just Create a new project with File -> New menu
you need to open Java Perspective and there you will find a package named "src" you need to copy your "com" directory and paste it at the src folder.
I hope this will work for you.

Eclipse WTP: "The import ___ cannot be resolved for" error in a JSP file for a class defined in project

A Visual Studio user struggling w/ Eclipse...
I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. /page.jsp has the following import statement:
import="com.foo.bar.*"
Eclipse is displaying an error:
The import com cannot be resolved.
The class that implements the above import is in /WEB-INF/src but I don't know how to build the class in Eclipse to resolve that error. I assumed Eclipse would automagically build the .java file and place the output in /WEB-INF/classes, but it's not doing that.
It could be that I haven't structured my project directories correctly so perhaps that's why Eclipse isn't building my source. Any suggestions? How can I get this to work?
First of all, /WEB-INF/src is a rather strange place to keep your java sources; you may want to move them out of /WEB-INF (into /src in project root, for example)
Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:
Right-click on your project in Eclipse, select Properties
Click on Java Build path on the left
Click source tab on the right
Click Add Folder button and add your source folder (/WEB-INF/src or wherever you moved it to)
Ensure Allow output folders for source folders is checked below
Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice.

Categories