I have a run configuration in my eclipse. In my project we have two branches : DEV and STABLE.
I would like to create one run configuration for building my project whatever branch it is on.
For now, when I set Base directory with one of those two variables : ${project_path}, ${build_project}, I face this error :
Base directory doesn't exist or can't be read.
This works : ${workspace_loc:/my-project-dev-branch} but is tied to a particular branch. I must duplicate this configuration for building the stable branch.
So, how can I view the actual content of ${project_path}, ${build_project} ?
Or which variable should I use to get this result : ${workspace_loc:/${eclipse_variable_with_project_name}} ?
I'm not sure I follow how your branches are represented within the workspace, but
${project_path} represents a path relative to your workspace
${build_project} will only be set during an actual build (not during an execution of your program)
Based on your description you want to be using ${project_loc} instead.
Nota: The project MUST be selected in the perspective project before launching the run configuration. Otherwise, you will get a message like in the screenshot below :
As you are already creating a String Substitution variable, through Run Debug->String Substitution in Eclipse Preferences, to deal with separate paths, you could either:
Create a variable, e.g. branch_loc, with a value of ${workspace_loc:/my-project-dev-branch}
If the paths only differ slightly, e.g. by branch name, then you could create a variable branch with a value, e.g. dev, and then create branch_loc with ${workspace_loc}\${branch}
Then use ${branch_loc} for you Maven base directory.
It would be better to have all branches use the same path, which git and mercurial allow you to do. Then you could use ${project_loc} for your Maven base directory. For project_loc if you specify the project name of your project, e.g. ${project_loc:MY_PROJECT_NAME}, then it doesn't require you to select the project in order to work.
If you right click on the project and then select Properties, you can see what ${project_path} will resolve to by looking at path and what ${project_loc} will resolve to by looking at location.
First of all, if you are using git as version control system: Do not checkout the project twice, but just switch between branches in a single project. Git was designed for that and can do that in seconds. That way your problem would vanish completely.
If that is not an option, maybe putting the run configuration under version control itself would be an alternative. Set the Shared file option as shown with the first highlight:
Then you can run the run configuration by selecting it in the respective project (as that is really a file there) and launch it via context menu. However, I've never tried this with the same launch configuration checked out twice.
You can set the base directory in below mentioned way:
${project_loc:${project_name}}
You can find the above variables from the variables option.
Also you can set your mvn command in goals as example below:
clean install -PautoInstallPackage -Padobe-public -DskipTests
Related
So i am using the Plugin Eclipse-PMD (http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/) in a shared version control enviroment.
We have multiple smaller projects in the entire project.
Out of the box it seems that this plugin requires individual configuration for every single project.
The way it works it that it searched for a .pmd file in the project and read information from that.
But it's really inconvenient to do that for 10-20 subprojects.
There is a general setting under Preferences -> PMD. But this doesn't seem to apply globally, even if that global checkbox is checked.
What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.
There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.
The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.
I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.
So, did anyone achieve what i am looking for?
Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path??
The default value for ruleSetFile is ".ruleset". So i thought, analogous to that, i could create a file in the exact same dir, call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!
Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest). With eclipse-pmd you can configure your projects to use a single rule set file for several projects. It also stores its path relative to the workspace. You still have to configure each project individually though (for now, this will change in a future release).
To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set. Select the rule set type "Workspace" and pick your rule set file.
For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.
If you set it up this way there will be a .eclipse-pmd file in each project containing the settings. If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).
Disclaimer: I wrote eclipse-pmd. Mostly because I had the exact same problems as you with the other plugin.
I've been struggling a long time to get this working with PMD for Eclipse. While Eclipse-PMD has this feature built-in, I had some other issues with it (e.g. I think it is not meant to create reports).
The trick was adding the rules to the project as a link.
Create the rule file, e.g. pmd.xml, in the parent folder of the project. Add the file to the projects to be checked, but add it as a reference. Therefore, drag the file from the explorer to the bundle and select:
In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.
Now close Eclipse. Edit the file with the name .pmd in the project folder by replacing the content with the following:
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
Restart Eclipse and right click the project. Select PMD/Check Code. Now, only the violations defined in pmd.xml should be reported.
Configuring PMD only using the GUI does not seem to work for me.
I want to build a maven integrated project with a given java home property. At exactly i want to write a code in java that sets the java home property for an InvocationRequest object. The main goal is to build a project with the runtime given(by an algorithm) java home. So i would call getInvoker().execute(request); to execute maven goals where request is an InvocationRequest object.
I tried to set the request java.home property with properties.setProperty(Goals.JAVA_HOME, javaHomePath); and call the method executeGoals(pom, new String[] { Goals.INSTALL, Goals.CLEAN }, properties); . This executeGoals(...) method contains getInvoker().execute(request) call and the request object definition too.
Output is: Missing: 1) com.sun:tools:jar:1.5.0 #Solved
EDIT: solved the output problem, but a new one appeared:
class file has wrong version 50.0, should be 49.0. Maybe i changed the jre home, so i think i'm compiling with a newer version of java than i'm running with.
Reminder: i want to build with a specified java home property = i want to change the compiler java home(or version) to the specified one. (In eclipse)
I would appreciate any help.
I dont think it is configurable. It is part of the Maven Core to use the JAVA_HOME environment variable. Please see the accepted answer of:
How to set specific java version to Maven
Also it is not possible to set or change environment variables (not system properties) within a Java process (for the current process). If you create another process from within your Java process, there will be methods to specify environment variables for this sub process.
Maybe the solution will be to execute a Maven command e.g. "mvn clean install" with a specific JAVA_HOME variable set as sub process (this requires, that Maven is installed and mvn is available as command). Use the ProcessBuilder to switch into the working directory, where the pom.xml of the target project is located and set the appropriate environment variable(s) before starting the process.
If Maven should not be installed at the enviroment your application is running on, you could also distribute a Maven installation with your application (maybe in a separate directory). Then you could run against the mvn.bat or mvn.sh of this distribution (depending on the os).
When using Eclipse, Build in Run as Configuration, go to the Environment tab and add the new JAVA_HOME variable.
Do not forget to check the Replace native environment ..... option.
This will override your default OS variable. No need to change at the OS level.
I have 3 Jenkins job. Below are the name of those Jenkins job:
test_existing_api
test_others_api
test_new_api
I have a config file in java project which have 3 different configuration. I want to pick the configuration depend upon Jenkins job. So first I want to check which Jenkins job is executing and then I will take configuration according to that job. That configuration will further require in java code.
Please help me to understand how can I check which Jenkins job is executing now in Java.
Assuming you want to get this data within the job that is executing, see manual entry:
Jenkins Set Environment Variables
When a Jenkins job executes, it sets some environment variables that you may use in your shell script, batch command, Ant script or
Maven POM 1. The following table contains a list of all of these
environment variables.
Environment Variable Description
BUILD_NUMBER The current build number, such as "153"
BUILD_ID The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
BUILD_URL The URL where the results of this build can be found (e.g. http://buildserver/jenkins/job/MyJobName/666/)
NODE_NAME The name of the node the current build is running on. Equals 'master' for master node.
JOB_NAME Name of the project of this build. This is the name you gave your job when you first set it up. It's the third column of the Jenkins Dashboard main page.
BUILD_TAG String of jenkins-${JOB_NAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.
JENKINS_URL Set to the URL of the Jenkins master that's running the build. This value is used by Jenkins CLI for example
EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that's carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
JAVA_HOME If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME/bin.
WORKSPACE The absolute path of the workspace.
SVN_REVISION For Subversion-based projects, this variable contains the revision number of the module. If you have more than one module specified, this won't be set.
CVS_BRANCH For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.
GIT_COMMIT For Git-based projects, this variable contains the Git hash of the commit checked out for the build (like ce9a3c1404e8c91be604088670e93434c4253f03) (all the GIT_* variables require git plugin)
GIT_URL For Git-based projects, this variable contains the Git url (like git#github.com:user/repo.git or https://github.com/user/repo.git)\\
GIT_BRANCH For Git-based projects, this variable contains the Git branch that was checked out for the build (normally origin/master)
Sorry about bad formatting (SO doesn't support nice tables), but you should be able to retrieve these variables with System.getEnv(). This means you don't need to add anything to your Jenkins configuration, just read from java what it already sets.
http://<Jenkins_server>/job/<Job_name>/lastBuild/api/xml?depth=1
Above url will give you the xml structured data, in which you can check <building>false</building> tag value from your java code by parsing the xml.
If value is true than jenkins job is running at the time.
To check which of given three job is running, you can check the status of each job by parsing xml in java code for each job and get configuration file of running job.
P.S. : Replace the place holders in url with applicable data. <Jenkins_server> and <Job_name>
You could pass a system property from the job to the JVM when launching the project:
...whatever... -Dconfig=test_existing_api
and retrieve it in your classes with:
System.getProperty("config")
I may have a corruption problem in Eclipse run configurations. This happened after I dragged (or copy-pasted, I don't remember) a Java class called MyClass from project1 to project2. Then I deleted project1. When I create a new run configuration the name given is MyClass (1). In other words, it thinks there is already a run configuration called MyClass, so the new one will have to have a number appended. (Edit: There is no existing MyClass run configuration so there is no apparent reason for the appended number. In fact, I deleted all of my run configurations.)
How can I easily clean up meta-data and be able to build again with minimal manual effort?
If there is a meta-data deletion recommendation that gets rid of more than just run configurations, that probably would still be a good solution, if it does not create a lot of manual work to get set up to work again.
Edit: The problem might be caused by the fact that there is a launch configuration named MyClass - project1 visible in the export dialogue. project1 no longer exists, but this remnant lives on, tying up the class name MyClass. I am not sure if there is a difference between a run configuration and a launch configuration.
AFAIK launch configurations are stored on:
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches
Take a look to the existent configurations and remove those that are not interesting to you.
And restart Eclipse
Open Eclipse. Follow Run => Run Configurations. You will see options on the left hand side. Under the Java Applications option, you will see the list of runnable classes (the ones have a main method). These class nodes on that list are right clickable. By right clicking on your running configuration, you will see New, Duplicate and Delete options. You can delete your old running configuration via delete option. To create a new running configuration, right click on Java Applications option and click on New and then configure it.
You could try starting eclipse with the -clean command line option.
On windows the easiest way to do that is to copy your shortcut to eclipse and add the option to the arguments list, then start using the new shortcut.
I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt:
Define value for groupId: : com.example
Define value for artifactId: : myproject
Define value for package: com.example: :
Define value for includeGradleSupport: : y
Based on the value of includeGradleSupport, I want to include (or not include) the build.gradle file in the generated project. If the user does not want Gradle support, I don't want to clutter up the generated project with unnecessary files.
Another example is that I might need to provide a Jetty web fragment (to activate a listener perhaps) if the user wants Jetty support.
It's all about customization of the project based on what the developer intends to use. While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
Is there a way to control this behavior using the archetype-metadata.xml descriptor?
I personally would move the parts that can be removed/added on user request and put the into different maven profiles so u can build different part using different profiles
I can have a look into what coding it would take to enable this in the archetype plugin.
I think the primary vehicle to do this today would be to conditionally produce two different archetype artifacts during the original build. The archetype user would then explicitly use yourarchetype-withthing or yourarchetype-withoutthing.
I know this isn't perfectly what you are after and I agree that what you are asking for is a sensible use case.
While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
This sentence made me think...
It seems like you have a default project structure.
Let's suppose it is big, has many files. Of course, you don't want to duplicate the logic and the files in a different archetype.
Now sometimes, a project has an additional behavior (related to Gradle).
This sound a typical use-case for another archetype that does not start from nothing, but that comes after the first one. I've seen several examples of such archetypes on the web. The developper triggers this archetype only if the project needs Graddle. :-)
So I suggest : create your Graddle archetype, that adds only the files relevant to Graddle.
Thanks for the info Dan !
I just looked at looked at archetype plugin source code, and http://jira.codehaus.org/browse/ARCHETYPE-58 doesn't appear to have resolved this issue.
Just created http://jira.codehaus.org/browse/ARCHETYPE-424 to track it.