setting user.dir for gradle app running in eclipse - eclipse

I have a gradle app a former employee developed that runs perfectly from the command line using ./gradlew. But now I'm trying to debug it in eclipse, so I'm starting by just trying to run it in eclipse.
I have the Buildship Gradle plugin installed and have created a run configuration that specified the working directory and passes program arguments. WHenever it tries to access anything in the filesystem, it's using the wrong path when the app uses System.getProperty("user.dir") - which is defaulting to my user's home directory instead of the project folder.
I've tried adding a "GRADLE_USER_HOME" classpath variable, but it doesn't seem to change anything. I've also tried setting Gradle User Home (under Preferences - Gradle) to the project folder, but that too doesn't help. I've also tried changing the Gradle Distribution from "From Import Settings" to "Gradle Wrapper", but that doesn't help.
Any help would be appreciated!

The system property user.dir has nothing to do with Gradle and I bet that it is also not set in the Gradle scripts. The system property user.dir is the current working directory of the user when he starts the program. So if you are in your project directory and call ./gradlew run, the working directory is your project directory. If you go one level up and call <project>/gradlew run you will also see a different behavior like from eclipse.
Set the working directory for the run configuration to your project directory, then you should get the right behavior. And probably you should fix this, so that not user.dir is used, if the project depends on the path being the project directory.

Related

CMake Eclipse project, make targets not available

I use CMake as a build manager for a C++ project. All my sources are in a src subdirectory, and I created a sibling build directory. Following the directions from https://cmake.org/Wiki/Eclipse_CDT4_Generator, the build commands I use are:
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src
This creates the .project and .cproject files used to import an existing project in Eclipse. In the IDE, everything seems to work perfectly, except that the make target does not work.
When I click on a build target, the CDT build console opens, but nothing occurs. Also when I click on Project / Clean in the Eclipse dropdown menus, nothing occurs. I checked the commands invoked by the targets, and they are of the form /usr/bin/make -j8, which should work.
Can anyone help me get the make target work ?
An automatic update to CDT just occurred and everything works now. So check for updates I guess.
Hope this is followed to create target....
The docs for eclipse says:
Your project name should be different from your executable name and different from your build folder name. Otherwise, Eclipse will NOT pick up your executable as you build them. Since my build folder name is certi_build, a CMakeLists.txt file like below should work (notice the difference in project name and executable name)
PROJECT(AwesomeProject)
ADD_EXECUTABLE(AwesomeProjectMain
main.cpp
util.h
util.cpp
)

Changes to HTML files not showing on built phonegap 3.0 app

So I have a Phonegap 3.0 app (project folder), and it's project (project/platforms/android) on Eclipse.
The problem is that when I change project/www/index.html , and tell Eclipse to Run the project, the changes don't appear on my device.
I noticed that Eclipse was saying Application already deployed. No need to reinstall. so I tried adding a space in a .java file so that Eclipse would notice some change in the project and rebuild it. It worked, Installing RingTo.apk... Success! showed on the log, but still the changes to index.html didn't show at the device...
Changes made to the files inside project/www/ are not automatically copied to your project (in your case to project/platforms/android/assets/www/). You have to run the following command to iteratively copy the changes to platform specific projects and build them. Open the command prompt and navigate to the root of the project (In this case project/). Or you can even right click on the project/ folder while pressing the shift key. Then run the following command:
cordova build
You can optionally limit the scope of each build to specific platforms:
cordova build android
Alternatively, you can run the following commands:
cordova prepare android
cordova compile android
In this case, once you run prepare, you can use Eclipse with ADT installed as an alternative to modify and compile the "platform-specific code" that Cordova generates within platforms/android.
Source - Cordova Docs
So, when you have made a slight modification in a .java file (which is an android platform specific file) and tried to rebuild it within Eclipse, you were actually trying to rebuild the same project without any actual modifications.
Another alternative would be to copy the files within the project/www/ to project/platforms/android/assets/www/ by hand and then build it within Eclipse, which would, of course, be an unnecessary pain.

Eclipse RCP product - is there anyway to update the PATH during launch

I am working on an eclipse RCP product on windows which internally uses some native binaries (dlls) located in a folder called "bin" which would be available as a part of the product.
I need to make sure that the folder "bin" is present in the PATH when the product.exe file is executed. Is there a clean way to make sure that the folder "bin" is added to PATH when the eclipse RCP product is launched?
I don't want to write any script or batch file that updates the PATH and then calls the product.exe. I also don't want to update the environment variable through the windows UI or command prompt.
I know that when we try to run my product from the eclipse IDE environment, there is an option in the run-configuration, wherein one can configure Environment variables on the Environment tab. I can append the "bin" folder to the PATH by creating a new environment variable called "Path" whose value is C:\EclipseRCPProduct\bin;${env_var:PATH}.
However - I would like to do the same when I run my product directly from the Product.exe which is generated. Does anyone have any idea regarding this?
Also - if anyone has any idea regarding the eclipse code which processes the information specified on the Environment tab of the run configuration, it would be great. I could try playing around with the code to see if I could get it to work when the product is launched from outside eclipse IDE - via the generated RCP product.exe
I don't think there's a way to define system environment variables within the launcher.
The following bug seems to request just that
https://bugs.eclipse.org/bugs/show_bug.cgi?id=286463
In the above mentioned bug, a .bat is attached to achieve your goal.
That said, why do the native binaries have to be located in a bin folder?
I.e. why are they not included in a plugin/fragment?

Eclipse doesn't see my new junit test

I'm using eclipse to run the tests in a single junit(4) test class. The tests in the class all run just fine. Then I add an additional test and run the class through the test running in ecplise again. Only the old tests are run. The new test isn't seen by eclipse. There's no error or anything, it's just as if eclipse is looking at an old version of the test.
If I run the tests using maven, everything works fine. Additionally, after I run the tests in maven, ecplipse can see and run the new test correctly.
Any ideas what's going on? Any ideas how to get ecplipse's test runner to see my new test cases?
I had the same issue. I solved it by doing the following:
Going to Project -> Properties -> Java Build Path
For the source folder src/test/java, the output folder was set to
"Default output folder"
Setting this to the typical Maven target/test-classes directory in your Maven structure
After this, Maven and Eclipse were in sync (as opposed to Eclipse happily running an older version of the tests, from whenever the last Maven compile was).
Maybe you "just" need to create a new Run configuration. Eclipse "remembers" the latest used Run configuration and just repeats it if not told otherwise. To make sure you have a new Run Configuration you can rightclick the test case in the package explorer and choose Run As | Junit Test. Next time you hit play this will be the "remembered" Run configuration etc.
Possibly src/test is not in the Java Build Path.
Solution on Kepler:
Project -> Build Path -> Configure Build Path -> Source -> Add Folder
Then check the box corresponding to test under src
You might find this is likely caused by using Maven to build (Maven usually builds into the 'target' folder), but Eclipse is using a different build folder for its own build process. Simplest way is to go into the target folder under your Eclipse Project (or Bundle if using OSGi) and delete the conflicting subfolders/class-files from under that directory; for me this is my "target" folder. Then get Eclipse to rebuild, and everything should be fine.
Technically, and alternatively, you could just blow away the entire build/target folder if you wanted to, and let Eclipse rebuild everything.
In response to the answer provided by Ryan Dawe, I have found out that Default output folder can be set to only one folder, for all the source folders on build path. So if i changed the output folder to target/test-classes, my src/main/java was also outputting classes there.
You might have written this response for a different older version of eclipse, but as of Mars.2 release, we can only have one default output folder for all source folders.
The best solution i have found so far for this problem is to just include the target/test-classes as a class folder, by going to Project -> Properties -> Java Build Path -> Libraries -> Add Class folder.
It seems that your project wasn't recompiled. Either check Menu:Project/Build Automatically or do it manually as Boris Pavlocic commented.
This seems to be the same issue as junit not using the newest file
The problem seems to be that Eclipse puts the compiled tests in the wrong folder which can be solved by manually specifying where they should end up.
Add "test" in front of your test classes if not there already the #Test annotation isn't always picked up from Eclipse's Junit Test framework.
Here is how i fixed my problem...
right click project and go to Run As -> Run Configurations...
select JUnit -> [project-name] on the the popup that came up
(this configuration of [project-name] was created for me by eclipse
but if not there you can right click JUnit -> New and create it)
goto Classpath tab
highlight User Entries and click Advanced... button
on the Advanced Options popup that came up select Add Folders and click OK
on the Folder Selection popup that came up scroll to your project open up target and select test-classes and click OK
repeat steps 4-6 for the [project-name]/target/classes directory and any other directory needed in your classpath (like properties files used in your tests etc.)
Note: this assumes your project's default output folder for tests is target/test-classes, if it is not then adjust accordingly. Also, make sure you have the right JUnit version selected under the JUnit Run Configuration as well and your src/test/java directory is a source folder to your project, etc. as mentioned by others.
It means that you have created a Test class that you havenĀ“t build yet.
After a build, for example with "gradle build" the Test class will be found by Eclipse too.
In my case I had to make a cleanup before as well.

System.getProperty("user.dir") anomaly in Eclipse

In my current project settings, I have configured Eclipse to place the compiled .class files in the /bin directory.
My puzzle is that, when I run the application via the IDE and get it to print the current working directory (System.out.println(System.getProperty("user.dir")) I expect the console output to be /bin - instead the value printed is the projectRoot folder (without the /bin suffix).
If I were to navigate to the /bin folder directly, and execute my java class, the current working directory is printed as I expect it to be. What I would like is the Eclipse IDE to behave similarly.
Any ideas as to why I am observing this disparity? I have gone through many project build settings, but cannot seem to find anything that would cause this anomaly.
Kind regards,
Dinuk
In Eclipse, the working directory defaults to the project directory.
You can change this in the run properties
(Project->Properties->Run/DebugSettings->Edit->Arguments tab, at the bottom of the page).
Edit: Actually, the easiest way to get to it is Run->Open Run Dialog->Arguments tab.
It's been a while since I used Eclipse.
From an example of Eclipse Setup New Project
alt text http://apps.sourceforge.net/mediawiki/sprite2d/nfs/project/s/sp/sprite2d/a/ae/EclipseNewProjectDebugArguments.jpg