How to specify javax.xml.accessExternalSchema for the JAXB2 Maven plugin - java

I have a maven plugin (jaxb2) and I need to supply a jvm arg to it. I don't think there is a tag to add jvm args in the pom for it.
I know I can pass in jvm args on the command line eg: mvn clean install -Djavax.xml.accessExternalSchema=all
Is it possible to set this jvm arg in the pom so that I don't have to type it into the command line every time?
(As aside - this jvm arg is required in order for it to work with JAVA-8. It works fine with JAVA-7)

This is relevant to the new XML security properties in JAXB 1.5, introduced in Java 8. This is why your builds now fail on Java 8 but work with Java 7.
If you're using my maven-jaxb2-plugin, please upgrade to the version 0.9.0 or later (current is 0.10.0). It has now a accessExternalSchema switch (default is all).
This sets precisely javax.xml.accessExternalSchema=all.
Please see the documentation.

I came across this issue while working with jaxb2-maven-plugin. I found a related jira issue for maven-jabx2-plugin - https://java.net/projects/maven-jaxb2-plugin/lists/issues/archive/2014-03/message/0
According to this issue Stephan202 suggested using properties-maven-plugin which worked like charm. Here is a sample code from his post -
<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>file,http</value>
</property>
</properties>
</configuration>
</plugin>

Re; the post - "I needed a solution that doesn't use alpha versions as that is my companies rules. –"
Changing the version to 1.0 & the value to 'all' got it working for me:
<plugin>
<!-- We use this plugin to ensure that our usage of the
maven-jaxb2-plugin is JDK 8 compatible in absence of a fix
for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<!--
<version>1.0-alpha-2</version> -->
<version>1.0.0</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>all</value>
</property>
</properties>
</configuration>
</plugin>

It has worked for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<vmArgs>
<arg>-Djavax.xml.accessExternalSchema=all</arg>
</vmArgs>
<keep>true</keep>
<verbose>true</verbose>
<wsdlDirectory>${project.build.directory}/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>ServiceWsService.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>custom-binding.xml</bindingFile>
<bindingFile>custom-binding2.xml</bindingFile>
</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>

Take a look at the Maven Compiler Plugin. Specifically you should be able to use the <compilerArgument> element to pass settings to the compiler.
See http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html for examples.

If you are trying to change the behavior of the JVM that is running Maven itself, add options to MAVEN_OPTS in the environment before launching mvn.

For maven-jaxb2-plugin version 2.5.0 trying to generate from DTD and spitting
org.xml.sax.SAXParseException: External parsing is disabled. Cannot
parse URI: ...
it helped adding the following to plugin configuration
<configuration>
...
<externalEntityProcessing>true</externalEntityProcessing>
</configuration>

Related

exec-maven-plugin: Can I run exec:exec goal without first running the toolchains:toolchain goal?

I've inherited an application that only compiles and runs in Java 1.8. Because I don't want to make Java 1.8 the primary jvm on my machine, I felt that the best way to manage this was through Maven toolchains. Configuring the maven-compiler-plugin was pretty straight forward, but I also want to add the ability to execute the service via Maven in order to take advantage of the toolchain I have configured for 1.8.
The challenge is that I don't seem to be able to get the exec-maven-plugin to use the toolchain as documented. According to the documentation, I would think that the exec-maven-plugin would utilize the maven-toolchains-plugin as needed. However, in order to get exec:exec to use the right toolchain, I have to use:
mvn toolchains:toolchain exec:exec
This works, but the documentation leads me to think that the toolchain would be configured automatically without me needing to execute the toolchains:toolchain goal.
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.8</version>
</jdk>
</toolchains>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath></classpath>
<argument>com.my.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
toolchains.xml
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<id>1.8</id>
<version>1.8</version>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
</toolchains>
Additional Note: I also tried configuring the exec-maven-plugin to run on exec:java with the following configuration:
<configuration>
<mainClass>com.my.Main</mainClass>
</configuration>
However this does not work, not even with mvn toolchains:toolchain exec:java.
Is there a way to configure this so that I only have to run mvn exec:exec, or mvn exec:java?
I think the answer is you must ensure that the toolchains plugin itself is part of your build. Or that's what the relevant documentation seems to say. (I see above you have that; what I'm saying is yes, that is required.)

jaxb2-maven-plugin not generating sources from wsdl

I have the following configuration for jaxb2-maven-plugin version 2.4
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/wsdl/osg_data_sync_service_1_0.wsdl</source>
<source>src/main/resources/wsdl/parlayx_sms_notification_service_2_2.wsdl</source>
</sources>
<outputDirectory>${project.basedir}/src/main/generated</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
But when i run mvn jaxb2:xjc, no classes are generated.
What could I be overlooking?
I have pasted one of the wsdl here
EDIT
As it was mentioned that this might be a possible duplicate, I downgraded the plugin to version 1.6 and changed configuration to the following and still no classes generated.
<configuration>
<wsdl>true</wsdl>
<xmlschema>false</xmlschema
<schemaFiles>osg_data_sync_interface_1_0.wsdl,parlayx_sms_notification_interface_2_2.wsdl</schemaFiles>
<schemaDirectory>src/main/resources/wsdl</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/generated</outputDirectory>
</configuration>
Full pom here as site was complaining too much code
It finally works with version 1.6 after cleaning. Why does version 2.4 not work?
Finally got version 2.4 to work. I don't know exactly what the issue was but I was able to generate the classes by running mvn generate-sources instead of mvn jaxb2:xjc as suggested in the comments. I also had to run mvn clean first

Maven does not use profile properties on Mac OS X

Suppose I have a profile
<profile>
<id>ak</id>
<properties>
<db.host>localhost</db.host>
<db.name>ak_cit</db.name>
<db.user>user</db.user>
<db.password>pass</db.password>
</properties>
</profile>
And somewhere in root of pom.xml there are default values
<db.host>NOT_DEFINED</db.host>
<db.name>NOT_DEFINED</db.name>
<db.host.reporting.db>NOT_DEFINED</db.host.reporting.db>
<db.name.reporting.db>NOT_DEFINED</db.name.reporting.db>
The problem I have while launching my application mvn -Pak clean install is that I get an exception because database NOT_DEFINED does not exist. Same command works totally fine on ubuntu or windows. After asking around my co-workers, I've found that some of them are experiencing same problem on OS X.
The only solution which somewhat works for me right now is passing variables through a command line: -Ddb.host=localhost -Ddb.user=user -Ddb.password=pass -Ddb.name=ak_cit. The problem with this solution is that there are a lot of properties which need to be passed through.
does anybody knows how to fix this or what might be causing such issue?
The problem was in settings.xml. was overriding my selected profiles. After checking my other systems I've noticed that there were no profiles defined in settings.xml.
Huge help in figuring this out was plugin echoproperties
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Is it possible to compile grunt project from maven?

I'm trying to execute grunt tasks from within maven without needing to install Node.js or anything. This is because I wan't my artifact to be packaged by Jenkins and I can't install Node.js on that machine.
I know that it's easy with npm and a few commands to get it working, but I also think that it should be easy to integrate with maven, the problem is that I don't know where to start since I'm new to npm.
Yes, using the frontend-maven-plugin, you can compile Grunt projects via Maven (found via the NodeJS mailing list).
As the documentation points out, the plugin has the following features:
Let you keep your frontend and backend builds as separate as possible, by reducing the amount of interaction between them to the bare minimum; using only 1 plugin.
Let you use Node.js and its libraries in your build process without installing Node/NPM globally for your build system
Let you ensure that the version of Node and NPM being run is the same in every build environment
I've walked through the code and it's fairly simple. Thank goodness someone finally put this together; it's an elegant solution. The repository includes an example that uses a regular Gruntfile.js to invoke jshint analysis.
UPDATE 2014-09-19: This is no longer the most accurate answer - please take a look at some of the other answers below. It was accurate at the time when I answered the question, but there seems to have been a good deal of progress in this area since then.
I'm afraid you're out of luck. Grunt is built using node and needs to be installed using npm. You might be able to copy an existing installation of Grunt from another machine if you don't want to use npm, but will still use the grunt executable and all of its dependencies on your build server.
In addition to that, many of the Grunt tasks are implemented as Node.js modules, and you will have to install them as well. Again, you might be able to copy them from another server, where you've done the Node.js/Grunt installation, but at one point, you have to do it.
For running Grunt from Maven, your best bet is to use the Maven exec plugin and then execute the grunt executable from there.
As an alternative, there are several Maven plugins that allow you to do things similar to Grunt in a Java-based fashion. They require additional configuration not compatible with Grunt, so YMMV. One that I've used in the past is http://code.google.com/p/wro4j/, which comes with a Maven plugin as well: http://code.google.com/p/wro4j/wiki/MavenPlugin
Any particular reason why you can't install Node.js on your build server?
You can use grunt-maven-plugin. It allows you to easily integrate Grunt tasks into Maven build process. No dirty hacks.
This is what I use in my current project and it works just perfect.
Finally I ended up with this (which is close enough but doesn't solve the problem):
<plugin>
<groupId>org.mule.tools.javascript</groupId>
<artifactId>npm-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>fetch-modules</goal>
</goals>
<configuration>
<packages>
<package>grunt-cli:0.1.6</package>
</packages>
</configuration>
</execution>
</executions>
</plugin>
that installs locally the grunt-cli, but if I don't have installed node.js it's worthless. Although I try to install node.js locally there's the need to have installed python, g++ and make. So I'll go with the KISS solution: install grunt in the build server.
References:
https://github.com/mulesoft/npm-maven-plugin
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
https://github.com/mcheely/requirejs-maven-plugin
You might want to checkout http://jhipster.github.io/ : it's a Yeoman generator, that generates an application which has Maven, Grunt and Bower all working together.
It's a bit like your third option, but everything is configured for you, which isn't that easy. It's also generating the basic AngularJS and Java REST services for you
This is a full copy/paste solution which work in 2017 using frontend-maven-plugin for front build, and maven-war-plugin to build the war.
What it does ? install npm, bower grunt,and everything you need, then run npm install, bower install and finally grunt build.
You can remove/add replace the steps you want, for me it's a full 30 sec install/build library and project.
<dependencies>
...
</dependencies>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.github.eirslett/frontend-maven-plugin -->
<dependency>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp/YourFrontJsFolder/dist</warSourceDirectory>
<warName>YouWarName</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warSourceExcludes>node_modules/**</warSourceExcludes>
<includeScope>system</includeScope>
<webResources>
<resource>
<directory>WebContent/WEB-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/*.jar</include>
<include>**/*.jsp</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>YourAppName</finalName>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks
nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v7.6.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually "install", so unless
you need to run some other bower command, you can remove this whole <configuration>
section. -->
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run Grunt's default task
(and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<installDirectory>target</installDirectory>
<workingDirectory>src/main/webapp/YourFrontJsFolder</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>debug</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>IDE</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<!-- Put the IDE's build output in a folder other than target, so that
IDE builds don't interact with Maven builds -->
<directory>target-ide</directory>
</build>
</profile>
</profiles>
Then you can Run as -> Maven build ..., with goal clean install and profile release
The first problem is that Maven is Java, but Grunt.js runs on the Node.js runtime. The easiest integration I ever achieved between the two involved the maven-exec-plugin. The maven-exec-plugin is capable of executing .sh/.bat/.cmd scripts, whichever are native to the OS you are using. So during a Maven build I would have the maven-exec-plugin execute a script named optimize-js.sh, for example, which would simply do something like “grunt release –force”, or whatever. The scripts can be made to do whatever. The important thing is to configure the maven-exec-plugin to execute them in the correct working directory. Of course, “grunt” and “node” need to be executable from the command-line.
If the problem is installing NodeJS on the Jenkins machine then you can use the NodeJS Jenkins plugin.
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
We're not using it with Maven (yet) but we've got grunt running.
Can be done with exec-maven-plugin.
Define a script and dependency to grunt-cli in your package.json:
...
"scripts": {
"build": "./node_modules/.bin/grunt install"
},
"devDependencies": {
"grunt-cli": "^1.2.0",
...
In your pom, add the commands to run:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>X.Y.Z</version>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-grunt-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
It will now run on mvn package

How to pass arguments to GWT compiler using Maven GWT plugin?

I need to pass "-deploy src/main/webapp/WEB-INF/deploy/" argument to GWT Compiler in gwt-maven-plugin configuration.
My purpose is to integrate remote logger using gwt-log.
To achieve I need to pass above mentioned argument to GWT compiler.
Thanks!!
Bhavesh
See gwt-maven-plugin
<project>
[...]
<build>
<plugins>
[...]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<configuration>
<deploy>src/main/webapp/WEB-INF/deploy/</deploy>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</plugins>
</build>
[...]
</project>
As noted you'll need to upgrade.
It looks like this parameter is only available since 2.3.0-1 version of gwt-maven-plugin (see here).

Categories