Arguments for eclipse compiler in Maven - java

In the Eclipse Compiler for Java standalone, I am able to log in XML the compilation info via a command-line atribute, as in this stub:
java -jar ecj-4.3.2.jar -log compile.xml <classpath,files>
However, when I use maven-compiler-plugin with plexus-compiler-eclipse, it seems I am unable to pass this argument to the compiler, and I am not sure the cause of this, whether the plugin's compiler is another one, it doesn't spawn new processes (i even tried the executable parameter), or other reason.
Here is the pom.xml section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<!--<compilerArgument> -log compile.xml </compilerArgument>-->
<compilerArgs>
<arg>-log</arg>
<arg>compile.xml</arg>
</compilerArgs>
<fork>true</fork>
<verbose>true</verbose>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>

The eclipse implementation is plexus-compiler-eclipse, it doesn't accept fork argument, as it uses the internal jvm. So, it can only accept jvm options like MAVEN_OPTS.
However, the default implementation is plexus-compiler-javac, which supports custom executable. The workaround may like this: set fork to true, and specify the executable.
For wraper in bash, you can visit here: https://stackoverflow.com/a/37971000/3289354

Related

How to configure tomee to run over https?

I am trying to configure a web application to run on https using tomee maven plugin, but it defaults to http. How can I specify the necessary config to use https?
This is what I did so far:
<build>
<plugins>
<plugin>
<groupId>org.apache.openejb.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>1.7.1</version>
<configuration>
<tomeeVersion>1.7.1</tomeeVersion>
<tomeeClassifier>plus</tomeeClassifier>
<tomeeHttpsPort>8443</tomeeHttpsPort>
<context>${artifactId}</context>
<tomeeHost>testapp</tomeeHost>
<systemVariables>
<javax.net.ssl.keyStorePassword>changeit</javax.net.ssl.keyStorePassword>
<javax.net.ssl.keystoreFile>keystorePath</javax.net.ssl.keystoreFile>
</systemVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
As I see by checking the version of the plugin, the feature to use https by default isn't implemented.
You could use version 7.0.3 instead:
<dependency>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>7.0.3</version>
</dependency>
I'm not entirely sure, if it's the same plugin just with another groupId, but the github where the plugin is developed looks promising.
So as stated in this mailing-list the plugin will use https by default, if not http-port is set. Also you could set forceHttps to true to force the server to use https.
Also there might be some errors because of the openejb-core version you use in your current plugin. You may need another openejb-core-version if you switch the plugin.

Incremental java compile with maven (like Eclipse does)

I want to use maven to build projects in which there are unresolved compilation problems.
The main purpose is package and deploy or run aplications using some kind of stubs for classes that contains compilation errors, like I understand that Eclipse does (thanks to JDT Core).
I configurate maven java compiler plugin following Apache Maven documentation at Using Non-Javac compiler to use Eclipse compiler. Thinking that maybe should set some arguments to modify the compiler/builder behaivor I was reading Help Eclipse - Compiling Java code but I don't realize which compiler/builder option or combination of these does the trick.
So far, the next configuration of the maven java compiler plugins compile using the eclipse compiler and package the application including generated .class (jvm bytecode) only for java classes without compilation errors. To get this behaivor it just require use the eclipse compiler (see compilerId and the dependency) and set failOnError=false.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<failOnError>false</failOnError>
<compilerArguments>
<org.eclipse.jdt.core.compiler.problem.fatalOptionalError>disabled</org.eclipse.jdt.core.compiler.problem.fatalOptionalError>
<org.eclipse.jdt.core.compiler.problem.forbiddenReference>ignore</org.eclipse.jdt.core.compiler.problem.forbiddenReference>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
With this configuration I could run java application as long as the execution doesn't use classes not included for compilation errors (because the stubs aren't generated) but on a Java EE container, the classloading will faild so the application can never be deployed.
I appreciate any help on this.
Just for share the solution, at that moment I just replace the plexus-compiler-eclipse with tycho-compiler-jdt to get the desire behaivor.
The proceedOnError parameter indicates that it must keep compiling in spite of errors, dumping class files with problem methods or problem types how to deal with the compilation errors.
Next is the final configuration sample.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>jdt</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<failOnError>false</failOnError>
<compilerArguments>
<proceedOnError/>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-jdt</artifactId>
<version>0.22.0</version>
</dependency>
</dependencies>
</plugin>
There is more plugin configuration examples in the Tycho FAQ.
And the possible compiler arguments are described in section Using the batch compiler of the Java development user guide (Eclipse Help site).

How can I switch the bytecode target level in IntelliJ using Maven 3 profiles

I am using maven profiles to switch between two "setups" in Intelli J. How can I switch the bytecode target level? That is: I want to change the following setting in compiler.xml
<bytecodeTargetLevel>
<module name="finmath-lib" target="1.6" />
</bytecodeTargetLevel>
Note: I tried to perform this via the following part in the respective Maven 3 profile
<profile>
<id>java-8</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
but this does not work!
Note: The pom.xml etc. belongs to the finmath lib project, and if you are interested, it can be found at www.finmath.net
I am using IntelliJ IDEA 14.1.3 and it works with following config ...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Hope this is helpful. Thanks!
The problem is that you want to change it to 1.8.
I've tried to switch IntelliJ's compiler version between 1.7 and 1.6 or 1.5 using Maven profile successfully.
However when you want to change it to 1.8, the config will be ignored.
I don't know whether this is maven's problem or Intellj's.
It seems that the JDK 1.8 is not well supported now, which is understandable.
You can open the Maven Projects tool window in IntelliJ and select the profile you want to use from the list.
In IntelliJ 13, File > Project Structure, set the Project language level to 8.0.

The command line is too long Standard error from the DataNucleus tool

I am getting this error
The command line is too long.
mvn install
Standard error from the DataNucleus tool org.datanucleus.enhancer.DataNucleusEnhancer
The command line is too long.
If you is using datanucleus-maven-plugin in windows simply set fork property as false in configuration of plugin as follow:
<plugins>
...
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>3.3.0-release</version>
<configuration>
<verbose>true</verbose>
<fork>false</fork> <!-- Solve windows line too long error -->
</configuration>
</plugin>
...
</plugins>
See the datanucleus enhancer page for more datails.
You may look at http://www.datanucleus.org/products/accessplatform/troubleshooting.html.
and here: http://code.google.com/p/vosao/issues/detail?id=47.
==============QUOTE==============
Problem
CreateProcess error=87 when running DataNucleus tools under Microsoft Windows OS.
Windows has a command line length limitation, between 8K and 64K characters depending
on the Windows version, that may be triggered when running tools such as the Enhancer
or the SchemaTool with too many arguments.
Solution
When running such tools from Maven or Ant, disable the fork mechanism by setting the
option fork="false".
==============END==============
pom.xml file needs to be adjusted as follows:
==============WAS==============
<plugin>
<groupId>org.datanucleus</groupId>
....
<configuration>
<mappingIncludes>**/*.class</mappingIncludes>
<verbose>true</verbose>
<enhancerName>ASM</enhancerName>
<api>JDO</api>
</configuration>
...
</plugin>
==============END WAS==============
==============SHOULD BE==============
<plugin>
<groupId>org.datanucleus</groupId>
....
<configuration>
<fork>false</fork>
<mappingIncludes>org/vosao/entity/*.class</mappingIncludes>
<verbose>true</verbose>
<enhancerName>ASM</enhancerName>
<api>JDO</api>
</configuration>
...
</plugin>
==============SHOULD BE==============
My suggested change to pom.xml also specifies limiting scope of Enhancer work area.

How do I compile with -g option in Netbeans?

When debugging I get an warning message on exception saying 'variable info not available - compiled without -g' - how do I set to compile with -g in netbeans?
thanks
As far as I know your own code is compiled with debug information. The Java runtime library, however, isn't.
Please double check that the location you see this message, is in your own code and not the runtime library.
In my Nb 7.4 there is a "generate Debuging info" flag on
project propertyes -> Build -> compile ;
but if you, like me, are using maven, you have to check in pom.xml too
let me show an example:
you can ave a production profile and in that profile you can have the maven compiler plugin with debug setting to false
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<showWarnings>true</showWarnings>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
...
see the false setting
if you have a similar setting on your pom.xml local variable on debug are not show.

Categories

Resources