Linking external source folder with name "src" in an eclipse project - java

This is NOT a question about linking source in eclipse java project
Is it possible to add an external folder named "src" in eclipse as the source folder.
The problem here is to keep the external folder name as "src" and not any other name; to do that I tried deleting src and bin folder from the standard eclipse java project and then tried to "Link Source" but that does not work.
Is there any other way I can make this happen?
That is make the Eclipse java project's src actually point to an external folder named "src"?
Similar issues with the out put folder "bin" as well.
System Information
OS: Windows 8, 32 bit
Eclipse: 3.7
Thanks.

You need to use Eclipse to remove the existing source folder from the project configuration, then delete it from the file system, then you can add the externally linked source folder as "src".
Right-click on the project and bring up "Properties..."
Click on "Java Build Path" and then the "Source" tab to show a list of the source folders on the build path.
Select "yourproject/src" and click the "Remove" button. This will remove it from the project (and the .classpath file).
Come out of it and physically delete the folder.
Go back to that dialog box and this time click "Link source...". It should work now. It works for me.

To make link with external folder, we need to rename the folder if any folder already exists with same name like "src" or better delete that folder. After that you can make link with the external folder using the anyone of the following method:
Method: 1 - (Make link manually via code):
1. Open the .project file from root folder of your workspace.
2. Include the below code with your file path:
<linkedResources>
<link>
<name>folder_name_list_in_your_project</name>
<type>2</type>
<location>folder_path_to_include</location>
</link>
</linkedResources>
3. Save the file and refresh the project to include the external folder in your project.
Method: 2 - (Make link manually via UI):
1. Right click the project, select "Build Path -> Configure Build Path".
2. Choose "Source" tab.
3. Click "Link Source" button.
4. Click "Browse" to choose the folder.
5. Enter the folder name in "Folder name" field to list the external name in your project.
6. If you need to add the pattern for include and/or exclude file, click "Next" and enter the pattern. Then click "Finish".
7. Otherwise click "Finish".
It works for me and hope that my steps also help you.

It is somewhat ugly, but you can create a hardlink in your filesystem. In the Windows command line, use mklink /H src d:\path\to\external\src.
I know that the following will hardly be useful, but: Think of a different approach.

Related

How to import OEM Java lib and source into Netbeans?

I have done a reasonable amount of programming in various languages but I am a Java / Netbeans newbie. I have successfully created and run "Hello World" so my Netbeans installation is OK.
I want to write code to control an LED display controller card. I have sample demo code zipped up by the OEM. I am trying to import, run and edit that code. If I can get this running, this will be the starting point of my own code.
The zip files only include library and source files in a directory structure that does not match Netbeans. All of my attempts to import the source and lib files have given fatal errors in Netbeans.
The directory tree has a lib and src branch at the root. The src branch cascades 4 levels to get to the source files.
I figure if I use a different tree structure, I will need to change the import statements in the source file. I'd rather not touch the code until I have it running. I have tried to unzip the project tree directly into the Netbeans directory but that didn't work.
How to import a JAR (Java Archive, the "library" in your case) in Netbeans:
Right click on your project name, in the 'Projects' pane usually located on the left
Click the 'Properties' link from the pop-up menu
Click the 'Libraries' link in the Categories list
Choose 'Add JAR/Folder', browse to your JAR and click OK
If you want Netbeans to create the JAR for the sources you have, do like Stefano says.
You should package the src folder as src.zip with a zip utility and the structure under lib with the java archiver as a jar file.
Now you can define a library in NetBeans and add these files to it (Tools => Libraries => New Library).
For Netbeans to be able to open a project, the folder has to contain some files that Netbeans itself generates when a project is created.
Since you only have src and lib folders available, I think the easiest solution would be to create a new project from Netbeans, so that the creation of those files is automatically managed, and then copying the content of the folders you have in the folders Netbeans will create.
You will also have to tell Netbeans to use those library, and you can do that from you new project's preferences.
Edit
A few more things you can try:
in NB, right click the folder containing the JARs you imported and select "remove", then import them back but selecting the jar files instead of the whole folder;
if you're not already doing so, use the "Clean and build project" button instead of "Build project";
If none of the above solve the issue, try starting from scratch again following these steps:
unzip your OEM files somewhere in your disk;
create a new empty project in NB
copy the files from the src OEM subfolder to src NB project subfolder
in NB, right click Libraries, then add JAR/Folder and select the jar files from the lib OEM subfolder
If this doesn't work either, tell me where I can find the OEM stuff and I'll try it myself :)

Running two java source folders in Eclipse where one is a sub-folder of the other

I'm trying to run some java code in Eclipse (Mars) downloaded from a link in the following paper:
http://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1001059#s4
A direct link to this code is:
http://www.comp.nus.edu.sg/~rpsysbio/pada
To run this code in Eclipse I initially run .java files in the subfolder "src/sbml2spa", which works fine. To run the next part of the program I need to run .java files from "src." I have tried taking the files from "sbml2spa" and placing them directly into "src", but this causes the initial .java files from the "sbml2spa" subfolder to fail.
Does anyone know of a solution for this?
Thank you for your time!
Add an exclude of the sbml2spa folder in the definition of the src folder.
Right-click project and select "Properties".
Select Java Build Path on the left.
Select Source tab.
Expand src path.
Select Excluded: ... and click Edit.
Click Add in the Exclusion patterns section.
Type sbml2spa/** and click OK.
The Java compiler will now ignore the sbml2spa folder when compiling from that Source Path.

How to rename / move a project in Intellij Idea 12?

As stated here one can change the name of a project. However, it only changes the name of the project and it will not change the folder structure.
As an example if your project is called sample1 and it resides ~/user1/development/IdeaProjects/sample1, the folder location won't be changed to ~/user1/development/IdeaProjects/sample2 if one changes the project name to sample2.
Right click on project, then Refactor -> Rename... (shift+F6), set desired name
Close IntelliJ
Rename directory in your filesystem to your desired name
In startup dialog select Open (or File -> Open... in main window)
Please select renamed project directory
Enjoy, it work's for me!
It seems that one has to right click on the project (after following the instructions to rename the Project), then choose Refactor -> Move to relocate project to the new location. I didn't find any solution to rename and move a project at once.
Close IntelliJ
Rename the folder in Explorer (Windows) / Finder (OSX)
Open IntelliJ
Import Project from Dialog, or File -> Import Project
Select the folder with the new name
Follow the dialogues
I know that probably I won't be able to help sheidaei after more than 7 years from asking question, but I hope that someone will find it useful :)
To change project directory name of a current project without closing Intellij, choose view of "Project Files" in drop-down menu in the project browser(typically on the left) instead of "Project".
How to select "Project Files" view in project browser
Then use right-click on project's directory name/path to open context menu.
Use Refactor->Rename.
Finding option "Rename" in context menu
Type in a new directory name, apply changes using button "Refactor" and that's it.
"Rename" dialog box
If you wish to change Module Name to match directory name, use Refactor->Rename option on project name in "Project" view of project browser.
If it is a gradle project, instead of renaming it using Refactor->Rename :
set the rootProject.name variable in the settings.gradle file to the new project name.
reimport the project. Hit the 'Refresh all Gradle Projects' button in the Gradle Tool Window.
Then follow steps 2 to 5 in #Dawid's answer.
To remove the old project from IntelliJ's list of managed projects:
select File->Open Recent->Manage Projects..
click the 'x' next to the old project name
Go to File then Project Structure
Under Project Settings -> Project make sure that you change the project name.
Then under Project Settings -> Modules change the name there as well.
Restart Intellij
Use your File Explorer to confirm that the project/modules have been renamed.
After renaming the project folder of a Kotlin project in IntelliJ, using the Import Project option as suggested in the other answers created module related problems for me. I was not able to select Main class in the Run dialogue. To solve this, I used Create New Project option. It doesn't delete your project files.
So to rename the folder, first create a copy of your project for safety and then follow these steps:
Close IntelliJ.
Go to file explorer and manually rename the folder.
Open IntelliJ.
Choose the option Create New Project
Select your desired language/framework e.g. Kotlin, click Next
For Project Name, specify your desired project name. Maybe same as folder name.
For Project Location, choose the folder that you manually renamed.
Click Finish, IntelliJ will ask if you want to overwrite .idea and .iml files. Click Yes for both.
Hope that helps.
For JetBrains v. 2019.2 (September 2019):
To move project directory without changing it's name:
Press Alt+1 to open project structure
Right click on project directory
Go to File -> Refactor -> Move directory
OR
Left click on project directory
Press F6
Specify target parent directory and hit OK.
To rename project directory:
Press Alt+1 to open project structure
Right click on project directory
Go to File -> Refactor -> Rename...
OR
Left click on project directory
Press Shift+F6
Select Rename directory (actually it's already selected) and hit OK.
Specify new directory name.
If you need both to move project directory and to change it's name, then do the steps one after another.
After you've done renaming/moving, close the project and remove it from the recent projects list (it became non-functional and you won't need it anymore there).
Then hit "Open" and find the project directory at it's new location. Now you have your project directory moved!
The last two steps should be done with a command like Edit project or something like that, where you can directly specify project directory, but as there is no such command, you need to remove project and reopen it at it's new location instead.
A work-arround for this, if you get an error when click "projectPackage" -> Refactor -> Move, is to close Intellij, move the folder manually, and then in:
C:\Users\user.name\ .IntelliJIdea2019.1\config\options
edit the file recentProjects.xml like this, with you new path, save and close, re-open jetbrains ide and it's done.
Well, I have figured this out and I will write down a step by step guide to how to rename the project directory linked to a GitHub repo.
Situation:
Windows 10
IntelliJ project is linked with a GitHub repo
I want to rename the GitHub repo and the project directory name and keep all my work the same.
Solution:
rename the repo on GitHub, make sure pages is still working with the new name
rename the project from IntelliJ by (right-click on the parent directory -> refactor -> rename)
rename the directory from IntelliJ by (right-click on the parent directory -> open module settings -> project)
3.1. update "project name"
3.2. update project compiler output
rename the GitHub remote repo from IntelliJ by (VCS -> git -> remotes)
close IntelliJ
open System Explorer
6.1. rename the project directory
6.2. open "workspace.xml" and rename all occurrence of the old word (you might want to cut it in another place, update it, then paste it back)
open IntelliJ and select import project
now, everything is okay, you can use Git inside IntelliJ normally as nothing has happened!
That is it, I just made a push from IntelliJ to the renamed repo and everything works as before without any mention of the old name.
click on your project file,which is you want to move and then push F6
Close IntelliJ
Rename the folder in Explorer (Windows) / Finder
(OSX)
Open IntelliJ Import Project from Dialog, or File -> Import
Project
Select the folder with the new name
further additional steps might be required if you see your module named
as new_modulename[parent module/old module name],
then update
settings.gradle with new name and reimport

accidentally deleted the default output folder in eclipse

I was rearranging some files in eclipse, and I accidentally deleted the default output folder. This is the location where eclipse stores the class files. Can anyone show how to recover it? Or rebuild it from the .java files?
EDIT:
I just restored the project from backup files. So this question is no longer relevant. Unless some future reader did not backup their application before making this same mistake.
from the menu bar select:
Project->Clean...
That will bring up a dialog box to select which projects to rebuild. The bin directory should be automatically regenerated.
Recompile your project, and Eclipse should create it again (default name is bin on some versions)
If not, navigate to your project settings, and go to
Java Build Path > Sourceand at the bottom you will see the default output folder. You can create it again by using the Browse button, and then Create new folder
All you need to do is re-compile your project, For that you can select your Project and do Ctrl+B or just select Project->Build Project
EDIT:
As you mention in the comments that you still do not see the class files. Please check the Default output folder by selecting your project Right-click Build Path -> Configure build path... then select Source tab and see what the Default output folder: mentioned there, your class files must be created there.

Change Eclipse's project location in file-system

I have a project of eclipse that is located in some folder on my my local-disk. Let's say: c:\proj1.0
and after a while I need to change the folder name to proj2.0 (why? because I started working on the next version of my application and I want to save the time of creating the new project in Eclipse. The older version is stored in the source control anyway)
How can I do it? if I try to change it than the project cannot be found by eclipse.
I didn't find the eclipse configuration file where the absolute location of the project is defined.
You have to change the project's name from Eclipse. In the Package explorer Right-click the project -> Refactor -> Rename. Or simply click on the project and press Alt + Shift + R. This way no configuration will be lost.
Another way would be to move the project's folder by Right-clicking on the project > Refactor > Move.
Alternatively, if you already renamed the folder's name and cannot see the project in Eclipse anymore, you can select File menu -> Import -> Existing projects into Workspace, navigate to the parent folder of your project's folder, then select the projects you want to import and press Finish.
It sounds like you think the name of the project comes from the workspace folder. This is not the case. The project name is contained in a hidden .project file. The refactoring tools are probably a better way to go, but that doesn't seem to be what you want.
Make new proj2.0 directory.
Copy hidden .project and .classpath files from proj1.0 directory to proj2.0 directory.
Edit .project in a plain text editor and change the name.
In Eclipse, Import Existing Projects into workspace and point to the proj2.0 directory.
if you wish your Source folder some where else :
Right Click > Build Path > New Source Folder > Link Source >
then choose your Source file Location
and then Click
Finish
When you make Source file some where else out of your Eclipse project
then :
1st : You are able to have more than one project in Eclipse from same Source also
2nd : Save your time for transferring your source file with out Eclipse project
3rd : you wont delete your source file by the mistake when you delete Eclipse project
First I use Refactor/Move to rename my project folder's name. Then I use Refactor/Rename to change my project's name in Eclipse.

Categories

Resources