I try to use eclipse-cs (eclipse checkstyle plugin) in our Eclipse 4 teamproject.
The idea is that we define one checkstyle.xml for our team and have this checkstyle.xml under sourcecontrol.
The Project structure looks like this
Root
Checkstyle.xml
PluginProjectFolder1
PluginProjectFolder2
According to the documentation it should be possible defining relative paths with the ${property} style pattern(s)...
When I try to define the location for the checkstyle.xml I get an error "Property xy has not been set".
What I'm doing wrong ?
The documentation you reference says:
To do this use ${property} style pattern(s) in the location string,
these patterns will be resolved from equally named Classpath Variables
or Environment properties (passed into Eclipse via -D parameter)
${project_loc} is not a Classpath variable or an environment property. It is an Eclipse String Variable which is different and the dialog needs to have specifically added code to support it. It looks like this dialog has not done that.
You can define Classpath variables in the Preferences in 'Java > Build Path > Classpath Variables'
I would assume that PluginProjectFolder1, PluginProjectFolder2, and Checkstyle.xml are all inside your Eclipse workspace. If they are not, then that is what you should try to do, e.g. by including an Eclipse project called WorkspaceConfig or some such which includes the checkstyle.xml.
Then, in order to achieve what you describe, you can select "project relative configuration" from the dropdown box. This actually refers to the Eclipse workspace. Select WorkspaceConfig/checkstyle.xml, and there you have it: The checkstyle.xml is under version control, and it will not matter where the developer's workspace is located on his PC.
An added advantage is that such a configuration will work out of the box, without required extra configuration steps such as defining classpath variables.
Related
Is anyone using the variables ${project_loc} and ${workspace_loc} in environment variables in an Eclipse launcher? I'm trying to use them, primarily ${project_loc} but nearly every time I run my launcher I get the following:
Variable references empty selection: ${project_loc}
I have four environment variables defined, two of which use ${project_loc}, though I've also tried ${workspace_loc}. These Maven projects were created outside of Eclipse and then imported as "Existing Maven projects". This may have something to do with the problem but I'm confused as to how to proceed.
Is anyone using these environment variables successfully?
The description in the help for 'project_loc' says
Returns the absolute file system path of a resource's project. The
target resource is the selected resource when no argument is
specified, or the resource identified by a workspace relative path.
So ${project_loc} returns the project containing the current selection - if there is no selection you get the error. It is better to use an argument to project_loc:
${project_loc:/MyProject}
In the Eclipse Ant task configuration, I can use variables to point to different aspects of my project. Ex: build_files, java_type_name, etc..
Is there an existing variable that resolves the Java Build Path->Default Output Folder as configured in the Java Build Path window? None of the default vars seem to point to that configuration, unless I am missing the obvious.
Is there a way to use %UserProfile% when specifying paths in a Eclispe .classfile? I have a project that contains the following line in its .classfile:
<classpathentry kind="lib" path="C:/Users/<username>/.ivy2/cache/somelib.jar"/>
Is there a way to specify this in a more portable way that can be checked into a repository and used by different users? In particular I'd like to get rid of the C:/Users/<username> part of the path.
I see two possible ways to solve the problem, but don't know how to implement either of them:
Use %UserProfile% in the path to refer to the users directory. On Linux, one could use ~, but this does not seem to work on Windows.
Use an environment variable that specifies the location of the ivy cache.
Any hints how to do either of these things, or how to solve the problem in an other way would be appreciated.
Background: The project is a Scala project that is built using sbt, which manages dependencies with ivy.
Have you thought about just using the sbt eclipse plugin to manage your eclipse project?
https://github.com/typesafehub/sbteclipse
This generates a project which you can import in your workspace.
Another option is that a classpath container can be used. [I didn't try that for Ivy.]
http://ant.apache.org/ivy/ivyde/history/latest-milestone/cp_container.html
Classpath variables (Option 2 which you mentioned) is possible too.
Right click on project > Configure Build Path > Add Variable > Configure variables > New variable [create one with a proper name] > OK > Extend [select the jars which you need to use].
Your classpath should be updated. Your project team needs to follow the same procedure in this case.
from another stack overflow entry: does this work for you?
System.getenv(String name), which I guess would be or System.getenv("USERPROFILE") System.getenv("%USERPROFILE%") - the "answer" link below isn't as naive as my simple asssumption
Can we read the OS environment variables in Java?
Consider a configuration class which needs to parse a different config file for each Eclipse project.
For instance, If Configuration class is called from Project1, it should parse special/path/fileX, and if it is being called from Project2, it should parse special/path/fileY.
I've tried using Eclipse's {project_name}, but surprisingly it is being parsed to the project being highlighted by the cursor, not the parent project of the current class.
Any ideas how can I distinguish one project from another in Eclipse Runtime, preferably using JVM arguments?
This is a workaround to your described problem, but I guess it's a better solution as it's independent from Eclipse and will easily work in production too.
Simply load the same file from the classpath, regardless which Project you're starting this from:
/my/file/from/classpath.txt
But put this file only in Project1 / Project2, such that the various files mutually exclude themselves according to your set-up:
/Project1/src/my/file/from/classpath.txt
/Project2/src/my/file/from/classpath.txt
Where src are Java source folders. Now you can still use your JVM parameter to override this, or to provide a default if the above is missing.
I think the easiest way would be using eclipse's run configurations. Simply create as many configurations as you want, supply all the JVM args you want, and use them to launch. This will also be very close to what you're going to do in production mode
or you can go to your Eclipse' Installed JRE's and have the configuration set as JVMArgs just the way you would have in prod.
If required, you can have diff copy of JREs per env.
Also if running from the IDE, you can get the
System.getProperty("user.dir")
which should be the root of the project.
that system property can be used to track the callee. Better still, set the Installed JRE's JVM Args to be something like this
-Dtheflaginprod=${project_loc}
project_loc = absolute path of the the project (/usr/projects/project1)
project_path = project name relative to the workspace (/project1)
In Maven, you can have compile-time dependencies and test dependencies. This is a feature I love, and the M2Eclipse plugin makes this available in Eclipse, too, which is great. So if I add jmock.jar to my project as a test dependency, it will show up on the classpath for JUnit tests, but won't be present when I'm debugging the application itself.
This is exactly what I'd like to achieve now, but without M2Eclipse or Maven. Is there a way to do this in plain Eclipse? (Possibly without installing any plugins.)
You could separate all your tests into another project and add the main project as a dependency (Project->Properties->Java Build Path->Projects->Add...)
Update: To avoid changing the original project structure, your test projects can use linked locations.
Create the test project as normal, you now need to create a linked resource to bring in the src/test/java folder. It is best to create it using a variable so that your projects can retain some platform independence.
To create a new linked folder select New->Folder, input src in the folder name: field then click Advanced>>
Click Link to folder in the file system
Click on Variables... to bring up the Select Path Variable dialogue.
If this is your first time, or you are linking to a new location select New... and give the variable a sensible name and path. If all your projects are located in c:\workspaces\foo** it makes sense to call the variable **WORKSPACE_ROOT and give it that path. If you have some other convention that is fine, but it makes sense to put a comment in the .project file so someone has a chance of figuring out what the correct value should be.
Assuming the values above you can now set a value of WORKSPACE_ROOT/[subject project name]/src on the input field
Once you confirm that you should see the src folder with a little arrow, and if you look in the .project file see something like this:
<linkedResources>
<link>
<name>src</name>
<type>2</type>
<locationURI>WORKSPACE_ROOT/esf-ns-core-rp/src</locationURI>
</link><!--NOTE the WORKSPACE_ROOT variable points to the folder containing the subject project's sandbox-->
</linkedResources>
You can now add the src/test/java folder as a source location as normal.
Note you can also share just the src/test/java folder by changing the config to something like this:
<linkedResources>
<link>
<name>src/test/java</name>
<type>2</type>
<locationURI>WORKSPACE_ROOT/my-project/src/test/java</locationURI>
</link>
</linkedResources>
This gives more control over the config, but you would have to repeat for src/test/resources, src/it/java etc.
You then set all the test dependencies only in the test project.
Very not pretty, but it does work (I've also used this where my test compliance level is different to the main compliance level, e.g. 1.5 for tests, but 1.4 for the target environment).
I'm afraid the answer is that you can't. There are 2 open issues which were postponed from 3.5 related to your problem:
Ability to mark source folder as test sources
[buildpath] Should be able to ignore warnings from certain source folders
Since you use both Eclipse and Maven you can workaround it.
Create a new "Maven Build" run configuration with goal "exec:java" and parameters "exec.mainClass=com.example.Starter". This way the classpath will be calculated by Maven.
Actually if you look in eclipse as to how Maven integrates dependencies it will not make the difference in test or runtime dependencies your test libraries are always accessible.
Maven will keep the difference when packaging the application and when it generates the runtime classpath if maven has control over the execution of that part. When eclipse is concerned Maven simply adds them all without question to the eclipse build path.
Why is it you need to have this separated like so ? What will this help you acheive ?
Eclipse Photon finally added this feature, with m2e support for it.