Eclipse 4.3 SR1: when creating a new item (file, class, etc), it doesn't take into account the current selection - eclipse

I have recently updated to Eclipse 4.3 (SR1, WTP). And I have an issue: when I want to create something: a file, a class, a dir, etc:
I right click on a dir (or package); e.g. "myDir", or "myPackage"
the wizard appears, but it doesn't propose "myDir" or "myPackage" as parent element. I need to manually specify it
Do you have any idea what may cause this strange behaviour?

For Java Eclipse will only use the folder / package if the folder you right click on in is a source folder (usually the src folder). Source folders are defined in the project preferences in the Java Build Path Source tab.

Related

I need Netbeans help. NO project's -src node appears so no source files--only -Libraries node shows

I hope it's OK to ask this here. Netbeans forums isn't responding. If not, I'll delete this or ask for it to be deleted. I'm desperate so I'll face the wrath, if any.
I moved my Netbeans projects folder from one directory node to another to make backing up all my stuff easier. BAD MOVE.
Now when I open a project using Files | Open project (ctrl-shift-O) NO source files appear because there is no "+Source Packages" node to expand.
It looks like this for all projects, e.g. one named GBL:
Projects
-GBL
+Libraries
It doesn't look like this anymore:
Projects
-GBL
+Source Packages (How do I get this back?)
+Libraries
The Netbeans Properties for each project shows me the path it's using. Windows 7 Explorer shows me that the src, build, and nbproject folders contain files and ALL the source files are in the src folder for that path.
What have I done and more importantly what should I do to get back to being able to open a project normally?
(I've tried recreating the original Netbeans folder and using Windows Explorer to copy an entire project folder into it but: same result--all I see is the Libraries node under the project's name node.)
I just tried to Clean (and also Build) to see what would happen. Error:
ant -f C:\\Users\\Dov\\Documents\\NetBeansProjects\\BasicShirt -Dnb.internal.action.name=build jar
C:\Users\Dov\Documents\NetBeansProjects\BasicShirt\nbproject\build-impl.xml:[u]231[/u]:
Must set src.dir
I just Set Configuration by right-clicking the project's name and provided a path to the src folder.
NOW I SEE MY SOURCE FILES BUT NOW THIS line in the .xml file is flagged with similar message:
<fail unless="[u][b]test[/b][/u].src.dir">Must set test.src.dir</fail>
NOW what do I do? (Netbeans 7.4.)
If I could get rid of the 7.4 automatic creation of +Test Packages, I might be OK.
If you can help, I'd be very happy.
(I'm considering re-installing 7.3 if available or removing and reinstalling 7.4 and try to avoid the "testing" requirement, but there goes all my many tweaks of 7.4.)
Well, after considerable frustration with the problem, I solved it, essentially.
It's here, in total. My synopsis plus how it helped me follows. In short, I had to set up a new java project based on existing sources using the New Project Wiz and simply direct Netbeans to the sources.
File > New Project
Choose Java Project with Existing Sources.
Type a (new) project name and ...
... make the Project Folder contains the path to where you want the new project to be stored. (For me, this is the folder where Netbeans has been able to find my sources.)
Click Next for the Existing Sources page of the wizard and ...
5a. ... in the Source Packages Folder pane, click Add Folder and ...
5b. ... navigate to your sources and select the source root folder.
Clicking Next goes to the Includes/Excludes pane, which I didn't need to use.

.class file opens instead of .java while debugging

Current setup:
MainProject which is a Library Project
BranchProject which is a new projects and has MainProject as a Reference
Whenever I debug and a file from MainProject is on focus (actually BranchProject has only graphic and xml layout changes) the Debug window opens a .class file which is read only. I want it to open the .java file so I can edit it directly.
Skyler's answer from this post worked for me:
Opening source code from debug view edits .class after Android R18 update
Here is a summary:
The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.
When you're using a Library project one of the things you're in fact doing is compiling your Library project into a jar and then referencing that jar in your calling Project.
If you right click the Project, and select "Configure Build Path" you'll see a tab called "Libraries", if you look inside "Android Dependencies" you'll notice a list of jar's corresponding to your Library projects.
These jars are expandable, showing you that they have a slot for a source attachment. Usually this would be editable allowing you to directly link the source but in terms of ADT these are already filled and are uneditable.
When debugging these files you're linked to a read-only class file with this attached source. This is because you're not running against source files directly, you're running against a pre-compiled class file. Until the ADT team get this functionality in place, you're pretty much forced to jump to the direct source code and rebuild everything.
EDIT
See #Steven linked answer :)
I faced the same issue while debugging the a .java file using Eclipse IDE. As per my understanding this issue comes when we put the xyz.class file of xyz.java file or JAR at the project build path. Delete the .class or JAR file from the project class path and rerun .java file in the debug mode. This time you see a source not found window. Click on "Source not found" button and check "Find duplicates..." at the bottom of the window. Done your problem is solved :)
The problem is that the class file is preferred over the java (by default), here is how you can change that for Eclipse (tested on NEON 2):
Right-click on the Project in the Project-Explorer, click Properties
On the new window select: Run/Debug Settings
Create a new configuration (or duplicate another one)
Select the new config and click Edit...
Go to the tab Source
Select the Default and Remove
Create a new path with Add..., select Java Library, then JRE System Library
Create a new path with Add..., select the location where the sourcecode is by Workspace folder (if it is a project in the same workspace) or File System directory (it it is not)
I think this depends on, how you set up the dependency in eclipse. You should set up your BranchProject to depend on the source-Files of your MainProject. If you depend on compiles Class-Files is obvious that the debugger opens the class files, because it does not know about the source files.
I found a good solution for me here:
Using Android library in eclipse and jumping to class files instead of source file that is within eclipse workspace
Simply, select each library project your project depends on, and use Top or Up to move it above the projects outputs. Eg. move all library projects to the top.
Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
Switch to Order and Export tab and uncheck Android Dependencies
Enjoy
If you tried all above hints and it still doesn't work try this solution, it worked form me:
Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path...
Select tab Order and Export
select library that you can't reach code and then click on button Bottom
Then click on Apply and Close
hope this can help you
Most of the time it happens when specific source folder are not added in build path Sources tab.
Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path -> Source Tab
Add the source folder if your project source folder is not there.
Select Add folder -> select your project source folder specifically. Eg: project_name/src . Then Apply it and restart server.

Eclipse - How to give dependency between projects?

I have two java projects in eclipse. Second one is using first one's jar. When I try to navigate to first one's class from second one, it opens .class of that file. But I want to open the first one project file. Please help.
Thanks in advance.
If you want to link your second project with your first project, don't add the first project in form of a JAR file to the second.
Instead open the project properties of the second project and select "Java Build Path". On the right side on the "Projects" tab you can add your first project as "required project on the build path".
The class files of project 1 are now added to the class path of project 2. And if you click on a class name you directly get to the source code.
Ideally, the JAR of the first project would appear under the "Referenced Libraries" of the second project.
Right-click on that JAR, and choose Properties -> Java Source Attachment.
Provide a variable that links to the source files of this JAR.
Alternatively, install a decompiler plugin (see jd-eclipse) which will decompile class files when you navigate them in Eclipse, so that you can see the source.
Make one project in Eclipse depend on another so that the dependencies are available in the indexer
Tested on Eclipse IDE for C/C++ Developers 2022-09 (4.25.0) on Linux Ubuntu 18.04.
For C++, right-click on the project which depends on another project. Go to "Properties" --> Project References --> check the box next to the project whose files and resources you'd like to be available in the project you are editing --> click "Apply and Close".
The indexed resources in the project next to the box you just checked (glib in the screenshot below) are now available to the project whose properties you just edited! This means if you Ctrl + Click a variable which is defined in the project you are editing, your indexer will now jump to its definition even if it lies in the referenced project (glib in this case)!
Screenshot:
Done!
Old and wrong answer (but may be helpful for adding includes to your project)
For C++, right-click on the project which depends on another project. Go to "Properties" --> C/C++ Include Paths and Symbols --> click "Add Include Path from Workspace..." --> choose the project from your workspace which it depends on, and drill down into the folder of interest --> click "OK". Click "Apply and Close".
You've now made your project whose properties you just edited depend on the other project in such a way that the dependent project dir you just added will now be indexed!

How to make an existing directory into an eclipse project

I have a project I am working on. I have decided to try working with it in Eclipse. There is already a directory, under version control where all the code resides. I am having a rather strange problem. I cannot find any way to just start using an existing code directory as an eclipse project. All I can find is how to import existing source into a new project or check out source from version control into a new project. How do I make an existing directory into a project?
My project is a Django web app if it is any help
In the New Java Project wizard, uncheck the checkbox that says Use default location and the use the Browse button to find your directory.
It is pretty easy to do. Go to File->New-> Project. In the Project wizard, choose the type of project you want and then be sure to unclick the 'Use default location` checkbox. Browse for your folder in the widget that then becomes enabled. Click finish after that.
Alternatively, you could create a brand new project workspace in a new location. Then, assuming Java as your project type, you can open up your project properties and add as a source folder your existing directory. To do this, use the 'Link Source' button on the Java Build Path -> Source tab of your Project Properties dialog.
My Method:
I clone this file to new project directory , and rename Project-Name to my project name, after that i import new files and directory from Eclips
File Name: .project ( Use Notepad for make this file...select Save as type to All Files (*.*) and write file name like: .project )
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Project-Name</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
Hope this link answers the original question of this thread.
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-45.htm
Creating linked resources
Folders and files can be linked to locations in the file system outside of the project's location. These special folders and files are called linked resources.
To create a linked folder:
In one of the navigation views, right-click the project or folder where you want to create the linked folder.
From the pop-up menu, select command link New > Folder.
Specify the name of the folder as it will appear in the workbench. This name can be different from the name of the folder in the file system.
Click Advanced.
Check Link to alternate location (Linked Folder).
Enter a file system path, or click Browse to select a folder in the file system.
Click Finish.
Probably not the way most people would go about this, but I like all of my eclipse projects in one place but don't necessarily have my source in my workspace directory. Maybe there is a built in way to "symlink" in eclipse, but I sometimes end up with the project folder in the workspace, with the "src" symlinked to the actual source directory somewhere totally different. That's my personal preference anyway. If you too are on a *nix machine a simple
ln -s /path/to/source src
will do from your project directory.
You know, it is not so simple question. Depending on your project type (jar, web module, ear and so on) different structure and configuration files are used by eclipse. So the first really interesting question is that what is your project type? The basic solution after it to create a new project, and define the directory of your source code as project root. Then you will see what else to change (for example source path settings, classpath and so on). So how does your project look like? Can you proide structure tree of folders?
Since you are using Django you should first set up PyDev in Eclipse. You can install it from the market. Then you want to configure the PyDev Python interpreters to find your installation of Django (http://pydev.org/manual_101_interpreter.html). Make sure to provide the explicit path to the Django folder if your Django is not installed in the default location.
Once these things are ready you can select File > New > Other, then select PyDev Django Project from the PyDev sub directory.
Click next and here is the sweet part: Uncheck 'Use default' (as previously stated) and then find your Django project directory. Be sure to select the right project folder (ie: the folder that contains manage.py). When you have the right folder selected Eclipse/PyDev will recognize that a project already exists and make mention that it will use those files. Click Finish.
Then there is a DB form that asks about your DB settings. If you already have a settings.py file then this seems to make no changes (as it should not). So fill it in or don't. But this is the last step.
Then you should be able to view and use your existing project in Eclipse!
I just created a pom.xml by hand and imported the project as an existing Maven project in Eclipse. It even works for nested projects without problems.
Use "import - existing projects into workspace". This works for my case.
Right click on a project -> Properties.
Open project location in explorer, there's a little icon next to path.
Put your folder/file structure in there and refresh the project in eclipse.

Help me understand Eclipse's Java Build Path

I have been moving my Java projects from Jdeveloper over to Eclipse whenever I have to go back and make a change (I only work with Java projects sparingly).
Everytime I try to create a project in Eclipse (3.3.2) I spend quite some time trying to figure out the proper way to configure the source directories in the Java build path dialog.
The biggest problem I'm having is getting the source directories to match up with the package specified in the source files. For Example my project looks like this:
MyProject
DevelopmentBuilds
MainSRC
The MainSRC directory is also the "Root" package so my classes would be defined as:
package MainSRC.Sub1;
If I set my included directory to blank, the files compile but with many errors because the Packages are not in the right place.
How do I tell eclipse to start at MainSRC for the compilation rather than the children of MainSRC?
Or, should I the path up with one src folder with MainSRC as subfolder?
I basically don't understand how this works.
you need to set MainSRC as a 'Source Folder'.
Apparently, you project root are set as Source Folder.
Enter in project properties:
. Right click over your Project root, and select Properties
. Choose Java Build Path
. Remove all source folders
. Click 'Add Folder'
. Select 'MainSRC'
. Click Ok and Ok
Now, your MainSRC are a Source Folder. Some error occurs inside source files. For agile process, right click over package 'Sub1', and press F2. Rename your package for a new, then all your source files will be put in the correct new package.
[]'s,
And Past
You would need to set the source directory to the root MyProject directory. You would have to tell Eclipse to exclude the other directories (such as DevelopmentBuilds) as they are not source code.
You might find you're better off conforming to Eclipse's expectations and creating a source folder which contains your main package folder.