Can I use Windows Environment Variables into Eclipse Workspace path? - eclipse

When you start Eclipse for the first time, it asks you the path for the workspace. Now, normal path should be C:\Users\USERNAME\Workspace but, if I try to set %USERPROFILE%\Workspace it doesn't work, it creates a folder called %USERPROFILE%\Workspace under the Eclipse folder.
So the question is: how to use windows environment variables to specify workspace path? Thank you.
P.S: I know that Eclipse has got customizable environment variables but I didn't try them and I want to use them neither.

You can run eclipse.exe -data %USERPROFILES%\myCustomWorkspaceDir to have the workspace in your wanted sub directory. In this case, you will not even get the dialog asking for the workspace.
There are still more runtime options for Eclipse.

Related

How can I switch a eclipse workspace without running the aplication?

I am having a problem with eclipse on a dropbox shared workspace. My friend who shared the workspace with me said it has a bug. When I run eclipse (and I think that workspace is default), it just appears a window with nothing in it. So I think if I could change the workspace without running eclipse I could use another one with no bugs. Does anyone know how to do this?
Try using the -data command line argument.
For example:
-data path_to_workspace
See http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Frunning_eclipse.htm.

Access eclipse variables outside eclipse

I am working on an ant scrip that can be located in one place, but can be targeted to run on each project. I am able to do this in eclipse using the ${project_loc} variable in eclipse. I was also able to get this variable to work in ant, by setting it as a variable to through the eclipse preferences. This works fine, but it only works in eclipse. Is there any way that I could get the path to a specific project through a script so that I could run my ant script outside of eclipse?
Any help is appreciated.
Thanks
http://ant.apache.org/faq.html#passing-cli-args
ant -Dname=value

How to force Eclipse to ask for default workspace?

I noticed that after installing cdt, Eclipse always loads the default workspace. The workspace listed in the config.ini in osgi.instance.area.default. Eclipse does not ask which workspace to open regardless if Prompt for workspace on startup is set or not.
How do I force Eclipse to ask which workspace to load on startup?
It works for me if I tick the box Prompt for workspace on startup, which you can find in
Window → Preferences → General → Startup and Shutdown → Workspaces.
I had the same problem with indigo on linux 3.0 X86_64:
After runnning eclipse -clean everything went back to normal.
Thanks to some comment on the eclipse issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=134412
Inside the configuration/.settings folder of your Eclipse installation, there is a file called org.eclipse.ui.ide.prefs. Open this file in a text editor and change the property SHOW_WORKSPACE_SELECTION_DIALOG from false to true.
Tested with Eclipse 3.7 on Windows.
Using Eclipse Indigo this is how I did it:
Window → Preferences → Startup and Shutdown → Workspaces
Check the box at the top of the window that says "Prompt for workspace on startup"
The “Prompt for workspace at startup” checkbox did not working.
You can setting default workspace, Look for the folder named “configuration” in the Eclipse installation directory, and open up the “config.ini” file.
You’ll edit the "osgi.instance.area.default" to supply your desired default workspace.
Version: Eclipse CIndigo Service Release 2
File > Switch Workspace > Other...
In the textbox, write the path in the Workspace or Browse
It automatically sets the default Workspace during exit.
I followed the thread and tired all things but didn't work. Finally I saw that my eclipse shortcut target is like below
C:\Eclipse_3.6\eclipse\eclipse.exe -clean -data "C:\workplace" ...
I simply removed -data option and it worked. Now I got popup to choose workspace at startup.
cheers.
I had the same issue (in Eclipse Juno), but I just wanted to change the default workspace to the one I'm using
There's a setting in ECLIPSE_DIRECTORY/configuration/config.ini that is causing a specific workspace to be loaded without prompting for a workspace. If you just want to change the default workspace, you can just modify the value or add it if it doesn't exist:
osgi.instance.area.default=#user.home/some_workspace
or
osgi.instance.area.default=/some/absolute/path/some_workspace
Starting eclipse with eclipse -clean did wonders for me.
I can confirm that I am having the same issue. I am also using Eclipse classic with CDT. The funny thing is that it only started happening earlier this evening. Before then, I was always prompted for the workspace. Checking Prompt for workspace on startup has no effect. I am not launching eclipse using a startup script, so the -data flag is not set on launch. I have removed the line osgi.instance.area.default from the configuration/config.ini file, but that had no effect.
A few strange quirks that are incidental to this problem: If I delete the workspace workspace it creates it again upon launch. However, when I switch to one of my "real" workspaces I notice that the workspace workspace is not listed as an option to be switched to.
As would be expected, reinstalling Eclipse resolves the issue. But it would be nicer to find a way to fix the problem without resorting to that.
Under Aptana 3.2.2, in \configuration\.settings\org.eclipse.ui.ide.prefs, edit:
RECENT_WORKSPACES=I\:\\PDT\\workspace
It will check the recent workspace, so just set it to what you want. I do it for running off an external drive.
Editing the config.ini file with
osgi.instance.area.default=\D:\\Projects\\Eclipse Workspace\\
worked for me.
Sometimes you need to pay attention to howw Eclipse is launched. I ever pinned Eclipse by rigk-click on the excutable and pinning it to taskbar. In this way, the Eclipse is launched to use settings under c:\User\public\public Documents\eclipse" which is not very desirable.
However, if you pin it by creating a short-cut, then it will launch to use settings in the folder of Eclipse installation. Then everything makes much more sense.
I'd recommend you to create a shortcut to eclipse.exe with the -data command line option. This way you can create a separate shortcut to each workspace you use, and avoid unnecessary dialogs and mouse clicks.
Windows: Just create an Eclipse shortcut on your desktop, then right-click to open Properties and under Shortcut set something like this as Target: C:\eclipse\eclipse.exe -data C:\Path\to\your\workspace1. This will launch Eclipse and automatically open workspace1.
Repeat the steps for all the workspaces you use often.
I resolved the problem by adding the -showLocation flag to eclipse.ini.
I first tried the -clean option, but that didn't solve the problem. Then I added the -data option with the correct path to the workspace, which worked.
If your Eclipse is auto-closing at startup you can
Open the properties of your shortcut and add -clean at the end of the path,
Or, in a command prompt, run C:\PATH_TO_YOUR_ECLIPSE\eclipse -clean like mentioned in the comments and other answers
I had the same problem on my Eclipse, and calling eclipse -clean did not solve the problem.
In the end I figured out that within the installation folder of Eclipse there is a script called eclipse. This script does some setting of environment variables and then calls eclipse.bin. The call for eclipse.bin contained the this command-line switch:
-data ~/.eclipse
When I removed that switch from start-up script, I got the workspace selection as expected.
Go to Window → Preferences → General → Startup and Shutdown → Workspaces (or Eclipse → Preferences → ... on macOS)
Check the checkbox Prompt for workspace on startup
Then at startup Eclipse will ask for workspace selection.

Running ant through eclipse it doesn't find environment variables, but running ant through terminal is fine

When i run ant through Eclipse some targets build fine, but ones that need a specific environment variable i.e. SOME_SDK that i set in my .profile file won't work. Even if i try to echo out ${env.JAVA_HOME}, Ant through eclipse will just print out that string. But if i run ant through the terminal (i.e. ant sometarget), it will find JAVA_HOME and SOME_SDK and echo those paths out. Ive checked eclipse that it's pointing to the same ant that is in my environment path (/usr/share/java/ant-1.8.1). Any ideas?
Thanks
When you open a terminal, the environment variables in your .profile get loaded. When you start Eclipse via the windowing system it is not being run under your user account, so your .profile is not available to Eclipse at runtime.
At least that's the case on my linux machine and I'm guessing its the same on a Mac. I put the environment variables that Eclipse needs to see in the /etc/profile file, which gets loaded at system startup.
You can specify variables in your Ant run configuration (Run As > Ant Build... > Environment tab).
I'm thinking that the Eclipse IDE environment handling is a bit spoiled, at least in *nix environments. Although similar to Kevin's case, what I'm finding is that although I do create a separate run profile and -successfully - run the test/install goals (maven instead of ant here, but that's negligible noise), and specify the JAVA_HOME environment variable for that run profile, the project does not validate the POM file.
All I'm left with is two separate choices:
use the /etc/profile approach, or
Edit eclipse.ini file including the system property there.
I think the latter is a cleaner workaround since it affects a configuration file that is only for the problematic application after all. Nevertheless, Eclipse should use the variables found in the user's path and leave us at ease to produce :)
What you need to do is remove the java.exe from c:\Windows\System32.
The reason is, in your %PATH% environment variable, it includes c:\Windows\System32, which has a java.exe file. If you run c:> java -version from a command prompt, you'll see that the version you're running does not match the jdk version.
Once you've done this, you will need to add: %JAVA_HOME%/bin to the %PATH% environment variable, so you can execute the java.exe from the jdk when running apps. Be sure to restart any application (including the command prompt) before expecting it to pick up the change.
Add this line to ~/.bashrc (or you can use another profile file):
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
(Don't forget to run source ~/.bashrc)
If you run start-eclipse from the command line, all environment variables will be picked up. This way, you only need to maintain a single set of environment variables across both command-line and eclipse environments.
NOTE: Stolen from Chris Fegley's answer at Launch mac eclipse with environment variables set

Eclipse is not starting

Eclipse starts from terminal but when i try to start it from gui then it says java runtime environment don't found.
Environment variables are:
JAVA_HOME="/opt/jdk1.6.0_20"
PATH=$PATH:"/opt/jdk1.6.0_20/bin"
And one more thing so far i normally copy jre folder from jdk to eclipse directory, which works fine but what is actual way. i mean this won't be standard way to do that.
Thanks in advance
And one more thing so far i normally
copy jre folder from jdk to eclipse
directory, which works fine
No, this is not necessary or desirable. You should not have to do any such thing.
If you open up a command shell and type "java -version", what comes back?
Edit eclipse.ini (from the Eclipse folder) and add the following at the beginning:
-vm
C:/Java/jdk1.6.0_22/bin
where C:/Java/jdk1.6.0_22/bin should be your path to the java bin directory.
Keep it on two lines.
Well the reason eclipse won't start from GUI despite of the fact that environment variables are set, is:
You have set the variable in bashrc or bash_profile, these two are for the specific logged in user, but you also need to set in etc/profile which is for all the users.
So once you set the PATH and JAVA_HOME in etc/profile it will launch from GUI.
Worked for me! ;)
Faced the same problem and the suggestion addressed my problem!
After setting /etc/profile as indicated in the link below, I logged out and logged back in for GUI based Eclipse to work.
http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/