Maven uses JRE7 instead of JDK? - eclipse

Eclipse Juno Release
Window / Preferences / Java / Installed Jres
shows two installed Jres.
jdk1.7.0_07 and jre7.
I get the following error when trying to clean and process-classes with maven:
Failed to execute goal org.apache.maven.plugins:maven-compiler-
plugin:2.4:compile (default-compile) on project reputation: Fatal
error compiling: tools.jar not found: C:\Program
Files\Java\jre7\..\lib\tools.jar
I added tools.jar as external jar already, out of desperation, but it didn't help. Why is maven trying to use the other JRE?
EDIT:
Compiler plugin excerpt from pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

You need to set your JAVA_HOME environment variable to the JDK directory.
EDIT:
In your installed JREs preferences window in Eclipse remove the JRE and select the JDK. Also make sure that your project is set to use that JRE library (Right-click on the "JRE System Library" under your maven project structure in the explorer and set it as the "Execution Environment")

You should verify that the Maven "run configurations..." is connected to the correct JRE. If the project JRE is correct but the run configuration JRE is incorrect you will get this error. To fix, go Under Maven Build, choose the JRE tab.

To configure maven builds to use the correct java execution environment you need to change the execution environment used by Maven.
1. JRE Locations
To set up JRE locations load the preferences window under Window\Prefences (Windows) or Eclipse\Preferences(OSX) or Edit\Preferences (Linux).
Expand the Java/Installed JREs option
Select the JDK of choice, or Add one if not configured.
2. Map Execution Environments
To map any java version to a particular installed JRE select the Java/Installed JREs/Execution environment menu item
Select the appropriate default JRE installation for that version.
3. Run Configurations
If you have particular run configurations, you can change/create specific run configurations and link a specific execution environment just to that command.
To do that select Run/Run Configurations
Select or create the run configuration.
Select the Execution Environment tab.
Select the appropriate execution environment for this command.

Maven 2.0.9+ supports toolchains that allows you can declare the version of the JDK required for the build.
Excerpt from the related Maven mini-guide:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.5</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
...
</plugins>

In your installed JREs preferences window
"go to the submenu Execution Environments and mark this JDK as compatible" from
How to force Eclipse m2e plugin to use jdk for a project

Related

Apache CXF using eclipse: A required class was missing while executing org.apache.cxf:cxf-codegen-plugin:3.2.:wsdl2java

When trying to build our project from within Eclipse I keep getting the following error:
Execution generate-sources of goal
org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java failed: A required
class was missing while executing
org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java:
javax/xml/bind/annotation/adapters/HexBinaryAdapter
The reason for that is that - while we still compile for a Java-8 target environment - the tool chain (i.e. Eclipse, M2E (Eclipe's Maven-plugin), Maven, and CXF) is executed using Java-11.
In Java 9+ javax/xml/bind is not part of the rt.jar anymore, hence the class is missing when the plugin tries to start up. Elsewhere I found that one can enable it by specifying an "--add-modules java.xml.bind" JVM option.
I tried adding that option to the MAVEN_OPTS environment variable but that is apparently ignored when M2E starts up Maven (and with it the CXF plugin) in a separate VM.
Next I tried to specify that option in the plugin's configuration in the pom.xml like so:
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<fork>true</fork>
<additionalJvmArgs>--add-modules java.xml.bind</additionalJvmArgs>
...
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
...
... but that also didn't fly. :-(
Any idea anyone, how and where one can specify that option or how I can make the former standard javax-classes available to a Maven-plugin running under Java 9+ (when executed from Eclipse M2E) ?
Just in case: this is NOT an Eclipse or M2E issues! Even when I start Maven on the command line using Java 9+ I get:
...
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java (generate-sources) on project my_project: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java failed: A required class was missing while executing org.apache.cxf:cxf-codegen-plugin:3.2.0:wsdl2java: javax/xml/bind/annotation/adapters/HexBinaryAdapter

TestNG in Eclipse, Reference to undefined variable env.DOMAIN_PATH

I just got a error when I try to run a unit test in Eclipse with TestNG, the error message is: Reference to undefined variable env.DOMAIN_PATH
but this problem does not exist when I run it in Intellj or with maven.
any one experience this problem?
I use Eclipse Mars.2 Release (4.5.2), and updated TestNG plugin version 6.9.12.201607091356
thanks.
When I was trying to run TestNG, I got the same error. I changed the preferences in Eclipse for TestNG -> Maven so that systemPropertyVariables and environmentVariables are unchecked, and I was able to run the test cases successfully.
Before
After
I faced the same issue. and for me, it worked by unchecking all the options from
Preferences->TestNG-> Maven.
you need to enable the 'environmentVariables' option at either Eclipse workspace level preferences or project level properties, for example for workspace level: navigate to Eclipse preference -> TestNG -> Maven -> enable option 'environmentVariables'. By default it's disabled.
see more details in the official guide
Just uncheck System Property Variables from Preferences->TestNG->Maven.
It works just by disabling systemPropertyVariables under Window--> Preferences --> TestNG --> Maven
In case you are working with maven project, setting your custom property to some default value could resolve this issue. below is a sample.
<properties>
<environment>local</environment>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<environment>${environment}</environment>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
you can make use of "environment" property in project using below call.
System.getProperty("environment");
I unchecked everything and left just the argline checked, and this worked for me

My java project build in jdk 7 . I want to convert it into jdk 6. How can I do this?

My java project build in jdk 7 . I want to convert it into jdk 6. How can I do this?
It is possible that convert it?
in netbeans.
Add separate JDK (1.6) to your IDE preferences. In build path of project change used JRE Environment from 1.7 to just added 1.6.
UPD:
For NetBeans click Tools > Java Platforms > Add Platform where you specify additional JRE.
Then go to your Project view > Right Click on libraries > Properties and select just added java platform.
You can configure your NetBeans project source code and binary output to be Java 6, see this answer:
In the Project tab, right click on the project and select Properties. In the Library category select Java Platform JDK 1.6. Then, in the Source category select Source/Binary Format JDK6.
Note, you don't have to since JDK 7 is backward compatible.
Alternatively, if it is a Maven based project, you can configure the maven-compiler-plugin to use version 1.6:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

Weblogic maven plugin with ssl problem

I am now trying to use oracle weblogic maven plugin to deploy an application to an admin server with administration port.
I am using t3s protocol to connect but I am wondering whether I can set my custom keystore and certs in the maven plugin/parameters
in pom.xml or command line.
I cannot find the solution on the internet.
Help would greatly be appreciated.
In theory you can set the weblogic ssl headers in maven opts - like so
-Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=
But the plugin doesn't seem to pick these up where as the weblogic.Deployer will. This is a little odd since the maven plugin just runs the deployer anyway.
I've also tried setting the java keystore to a custom one (also with no luck)
well the question is like "old" :) - but it seems there is no conclusive answer around and since this question pops up at google in the top10 here is what I did to make the maven -> weblogic deployment work
Using: maven 3.2.3 to deploy to WLS 12.1.3 and the WLS 12.1.3 DEV (Do not forget to execute the configure script prior to starting - well - anything)
Setup (done once)
Follow the Oracle Docs for the Maven Plugin to setup the plugin. In short:
Mainly you will install a maven plugin from the WLS DEV zip to install another maven plugin:
cd %WL_HOME%\oracle_common\plugins\maven\com\oracle\maven\oracle-maven-sync\12.1.3
mvn install:install-file -DpomFile=oracle-maven-sync-12.1.3.pom -Dfile=oracle-maven-sync-12.1.3.jar
install the plugin to be used to deploy:
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=%WL_HOME%
Verify the plugin is ok:
mvn help:describe -DgroupId=com.oracle.weblogic -DartifactId=weblogic-maven-plugin -Dversion=12.1.3-0-0
If you need this to be added to a Maven repository proxy you can temporarily change the path to your local repository, executes those commands and that's what will be required (around 230MB in my case). I would add another thirdparty repository on the maven proxy and put everything in there in case you need to clean up later.
Then use the InstallCert tool to import the SSL certificate into a new keystore. We will place this keystore in the maven module that creates the EAR file and executes the deployment.
Deployment
Once you have your EAR file ready you need to add this to your build section:
(not the SSL / keystore messing around is only required when using t3s, you obviously skip the property setting if there is no self-signed certificate involved)
The "TrustKeyStore=CustomStore" parameter is somehow required! The name must not be changed.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<configuration>
<properties>
<weblogic.security.TrustKeyStore>CustomTrust</weblogic.security.TrustKeyStore>
<weblogic.security.CustomTrustKeyStoreFileName>${basedir}/src/main/keystore/cacerts.dev.jks</weblogic.security.CustomTrustKeyStoreFileName>
<weblogic.security.TrustKeystoreType>JKS</weblogic.security.TrustKeystoreType>
<weblogic.security.CustomTrustKeyStorePassPhrase>changeit</weblogic.security.CustomTrustKeyStorePassPhrase>
</properties>
</configuration>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>12.1.3-0-0</version>
<configuration>
<adminurl>t3s://HOSTNAME_HERE:7101</adminurl>
<user>WLS-USER-IN-DEPLYOERS-GROUP</user>
<password>WLS-USER-PASSWORD</password>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<targets>TARGET_SERVERNAME_IN_WLS_TO_DEPLOY_TO</targets>
<verbose>true</verbose>
<name>YouApplicationName</name>
<remote>true</remote>
<upload>true</upload>
</configuration>
<executions>
<execution>
<id>wls-deploy-dev</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The above configuration will deploy the EAR during install phase - feel free to change to phase of the weblogic-maven-plugin. It could also be in a profile I guess.
Happy Deploying :)
Links:
weblogic.Deployer command line reference
Docummentation of the WLS maven plugin
Properties Maven Plugin
InstallCert Tool

How do I develop a maven plugin using Groovy in Eclipse

I want to write a Maven plugin in Groovy, but under Eclipse (Galileo).
I've downloaded and installed Groovy-Eclipse plugin
I've created my very simple POM file (included below).
I've created a simple Echo mojo and place it under "/src/main/groovy/com/acme/maven/plugins/foo".
I performed "Import Existing Maven Project" in Eclipse (using M2Eclipse plugin).
The problem is that I don't see "src/main/groovy" as a source folder, which makes it hard to develop:
- I have to create the package directory structure (com/acme/maven/plugins/foo) manually
- Refactoring probably won't work easily
- Incremental probably won't work.
How do you guys develop your Maven plugins using Groovy in Eclipse?
You should definitvly install the Groovy-Eclipse plugin if you plan to develop Groovy code in Eclipse. You can find all the details here:
http://groovy.codehaus.org/Eclipse+Plugin
You should also add the Groovy Maven Plugin to your pom.xml like this (see this page for details):
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now update your Eclipse project configuration via Right-click on project -> Maven -> Update project configuration. Now you should see that the src/main/groovy folder has been added to the source folders.
Use GMaven and the eclipse plugin as suggested by chkal.
In addition to GMaven, and Groovy-Eclipse, there is m2eclipse support for Groovy-Eclipse that should be installed separately. Go to the Groovy-Eclipse snapshot update site:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
And install the feature from there. This feature will ensure that your groovy/maven projects are set up correctly when they are imported.