setting ANT_OPTS in eclipse - eclipse

Does anyone know how to set ANT_OPTS in eclipse's ant runner and have it picked up?
I've tried setting it via the Environment tab in the External Tools setup, but that doesn't appear to be picked up.
I'm trying to set the following:
-Djava.util.logging.config.file=logging.properties
so that I can turn on debug logging in some Oracle deployment ant tasks. Their instructions specifically say to set ANT_OPTS, although any other way to get ant to pick up the setting would be fine as wel.

You are correct:
The kind of JRE property is to be set in the Argument tab (VM part) of a launcher:
(source: sim-bio.org)
The Environment tab defines the environment variable values to use when running or debugging a Java application. By default, the environment is inherited from the Eclipse runtime. You may override or append to the inherited environment.
(source: eclipse.org)

Related

Setting a default working directory in PyDev/LiClipse/Eclipse

I am using LiClipse / PyDev. When I run some test or other python module from the package explorer via right click -> run as -> python run, the working directory is set to the directory of the corresponding file, e.g. ${workspace_loc:MyProject/tests/misc}.
I want everything to be executed from the root folder of the project though. Under run configurations -> arguments, that folder can be selected via the button "default" which sets the working directory to ${project_loc:/selected project name}. Unfortunately the "default" button apparently is not selected by default, but instead the "other" option with the directory set as described above.
When having many test modules it becomes a little bit annoying to select this "default" button manually for each one. So how do I get LiClipse to actually select that button by default? Or to use the project directory as the working directory by default in some other way?
A similar question was already asked before, but without a satisfying answer: Configuring the working directory in Eclipse 3.8.1 with PyDev-project. The only conclusion was that an Eclipse bug does not allow to configure the value of the default option, which is not necessary for my purpose though. I only want this option to actually be selected.
The issue might be specific to PyDev, as it seems that Eclipse usually has the "default" option selected according to what I read.
Well, unfortunately, as you discovered, there's really no way to set that default in the IDE.
Still, to solve your problem related to tests, my suggestion would be using the pytest runner (you may have to install it -- instructions at: https://pytest.org/latest/getting-started.html and then set in the PyDev > PyUnit preferences the setting to use the pytest runner)... as a note, even if you won't be using the pytest way of writing tests (which I highly recommend), and using unittest.TestCase, it should work...
When running pytest, PyDev needs to follow a different logic because of how it deals and loads its fixtures which make it use always the same folder (I think it's the source folder, but if you're using the source folder and the project folder as the same it should work -- and if that's not the case, in pytest, it's trivial to create a session auto-use fixture which you could use to change the working directory to a given folder (with unittest.TestCase this is more difficult to do as you're constrained through your test class hierarchy, but you could also override the setUp of your tests to do that).

Eclipse ${project_name} expanded inconsistently

I've been using Eclipse ${project_name} variable as a configuration class hack to determine which project is running.
VM args
-Dproject_name=${project_name} in the relevant JRE builder.
Code
String projectName = System.getProperty("project_name");
The problem is that projectName is inconsistent across different machines, and sometimes in the same machine.
Sometimes it is parsed into ${project_name}, sometimes into the the configuration project, and sometimes into the project calling the configuration.
We use Eclipse 3.6 and 3.71, if that's relevant.
Any ideas?
I have seen that the value of ${project_name} depends on the project that has currently the focus in the IDE. A project has a focus for example when one of its files is selected in the package explorer or one of its files is opened in an editor and the focus is on the editor.
Unfortunately it is not related to the project to which the started application belongs to, and I don't know an Eclipse variable that contains that project (although I'm also interested in a solution for this).
So as a workaround, make sure you are actually in the right project when you run the application from within Eclipse.

Eclipse with DLTK plugins for tcl, has multiple "Run Configurations"

Since setting up Eclipse with the DLTK plugins for TCL (from a fresh install) I've noticed that every time I attempt to 'run' or 'debug' I'm prompted to choose a run configuration. These are listed as 'Tcl Script' and 'Tcl Testing'.
The run configuration propery panel shows both 'types' of configuration, but has no facility to remove them (the types, not the configurations themselves).
Is there any way I can remove the 'Tcl Testing' config type? Or some other way to prevent it asking me which type I want to use every time I run/debug a project?
I've tried ensuring I have only a single configuration defined, but it still asks me which configuration type I'd like to launch.
Setup a new Debug Configuration of whichever type you want. Under the common tab check off the 'display in famorites menu' boxes. Hit Apply, then Debug. It should launch properly.
From then on, when you hit Debug (or at least F11, as I do) it will launch that debug config every time. If you run something else, that config will be an option in the drop-down.

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

Ant build won't run in Eclipse

I have an Ant build.xml which no longer runs when launched in Eclipse.
I click on the External Tools Configuration, select the Ant Build I've been running, and click Run.
Nothing happens -- no console window and the build doesn't appear to launch (the classes are not compile nor is the WAR file created).
I recently added a plugin (Spring IDE), this is the only thing I can think of that has changed recently as far as my Eclipse configuration.
I can run the Ant build fine from the command line.
Can anyone suggest where I might look to track down my error?
I'm using the Eclipse Helios release, Build id: 20100617-1415 on Windows XP.
As per pstanton's comment this symptom will occur if your ANT_HOME folder is not correctly defined in Eclipse. Eclipse seems to ignore the ANT_HOME system property.
window->preferences->ant->runtime->Classpath Tab
I faced same problem today , reason behind this was ANT_HOME path variable explained in other answers also.
Initially I added ANT_HOME at 2 places given below and it was not working.
window->preferences->ant->runtime->properties Tab
window->preferences->ant->runtime->Classpath Tab
But when I remove Classpath tab ant home entry ( by setting it to default using Restore default option on right bottom of preferences window ) it worked :). So far it is just a surprise for me because I added same ant home path at both the places.
You can check out the example in this Apache Ant tutorial.
But you can also try to run your same build.xml ant files through a Java Launcher, with org.apache.tools.ant.Main as the Main class.
That would at least prove your scripts are working in an Eclipse environment.
When you look at the Ant FAQ, you also see:
I installed Ant 1.6.x and now get java.lang.InstantiationException: org.apache.tools.ant.Main
The cause of this is that there is an old version of ant somewhere in the class path or configuration.
Maybe your error message is somehow hidden, but it can be worth checking your classpath and see if no other ant library is there.