openshift: maven compiler error : Base64 can not find the symbol - java

I am deploying webapp to the openshift cloud.
While compiling the resources by maven automatically after deploying, it shows Base64: symbol not found
However when I maven compile it on my Pc, their are no errors and build is successfull. I tried to change Base64 from java.util to apache.commons.codecs. The error is still there while deploying and it successfully runs at my local machine
Following is the pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
Should I place the commons-codec jar in WEB_INF directory. i read the solution somewhere but was not sure about it.
please suggest a solution. Thank you
</dependencies>

My guess is that you're using JDK 8 on your machine, but JDK 7 where the error is happening as java.util.Base64 is only available since Java SE 8.
I recommend to use the same Java version on both machines.
Otherwise you should consider cross-compiling. Just setting the source and target level is not enough, as you can see, as you're still able to call new APIs.

Related

Unable to build Java project targeting JDK 11, Invalid target release 11

I have JDK 11 installed along with Maven 3.6.2 and am using error prone to compile my Java maven projects. With this configuration:
pom.xml:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<useIncrementalCompilation>false</useIncrementalCompilation>
<compilerArgs>
<arg>-Xep:ParameterName:OFF</arg>
</compilerArgs>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${google.error.prone.version}</version>
</dependency>
</dependencies>
</plugin>
I get this error:
CompilerException: InvocationTargetException: invalid target release: 11
I tried following this information:
Unable to compile simple Java 10 / Java 11 project with Maven
However, upgrading ASM did not change anything.
As per the maven documentation:
The Compiler Plugin is used to compile the sources of your project.
Since 3.0, the default compiler is javax.tools.JavaCompiler (if you
are using java 1.6) and is used to compile Java sources. If you want
to force the plugin using javac, you must configure the plugin option
forceJavacCompilerUse.
Also note that at present the default source setting is 1.6 and the
default target setting is 1.6, independently of the JDK you run Maven
with. You are highly encouraged to change these defaults by setting
source and target as described in Setting the -source and -target of
the Java Compiler.
After changing the source and target to 11 as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
the above mentioned error of invalid java 11 version didn't appear
I put in properties this: <java.version>1.11</java.version> and in maven compiler pugin of this way: <source>11</source> <target>11</target>.
It works for me.

Exception java.lang.NoSuchMethodError on ExecutionStrategy constructor method

I am using GraphQL on a Java project and it was working on a server.
When I changed to another server, it stopped working and it is throwing the following exception:
java.lang.NoSuchMethodError:
graphql.execution.ExecutionStrategy.(Lgraphql/execution/DataFetcherExceptionHandler;)V
at graphql.execution.AbstractAsyncExecutionStrategy.(AbstractAsyncExecutionStrategy.java:19)
at graphql.execution.AsyncExecutionStrategy.(AsyncExecutionStrategy.java:23)
at graphql.GraphQL$Builder.(GraphQL.java:199)
at graphql.GraphQL.newGraphQL(GraphQL.java:166)
I am using exactly the same Java version (1.8.0_181), the same graphql-java dependency version (7.0) and the same project version.
Am I missing something? Anyone with the same problem?
Thanks in advance,
Solution
After analyzing the dependencies of each one of my project dependencies, I noticed graphql-java-annotations was importing version 3.0 of graphql-java library.
graphql-java library is one of my project dependencies as mentioned before (was using version 7.0).
As consequence, two different versions of graphql-java where being referenced and were conflicting with each other.
To solve this issue, I removed graphql-java dependency and I started using only the version imported on graphql-java-annotations.
Usually this is because dependency confliction.
You can add this to your pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
then try package your application, it will log which jar the graphql.execution.ExecutionStrategy class is loaded from. Then you can check if it is the correct version.

Can't link to JDK10 in Javadoc comments

After upgrading from Java 9 to 10, links to the JDK no longer work when generating documentation with the Javadoc tool (e.g., for a file importing java.util.Optional, {#link Optional} renders as Optional instead of as Optional; same issue with #see, #param, #return, and anywhere else you normally see Javadoc links).
I have a simple modularized project, and I'm using Maven with the Javadoc plugin (source and target options set to 10 in the configuration section for the compiler plugin). My understanding is that by default it passes -link https://docs.oracle.com/javase/10/docs/api/ to the Javadoc tool. It's also my understanding that, historically, the Javadoc tool expected a text file named package-list to be present at the URL where it was told to find external docs. Java 8 has one. Java 9 has one. Java 10 does not (404 error). Apparently, the Javadoc tool now outputs a text file named element-list instead of package-list for modularized projects, but it seems like that isn't provided either (nor for Java 9, but it is available for early-access builds of Java 11).
Generating Javadoc through IntelliJ with the option Link to JDK documentation enabled produces the same result. It says it's passing -link https://docs.oracle.com/javase/10/docs/api/ to javadoc.exe, and it reports javadoc: error - Error fetching URL: https://docs.oracle.com/javase/10/docs/api/. Despite the error, it does output the Javadoc, but as with Maven, no JDK links are present.
How is this supposed to work? Did Oracle screw up when they put the JDK docs online?
The relevant bits of my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!--update dependency for Java 10 compatibility-->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Output of mvn -version:
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T12:49:05-07:00)
Maven home: C:\Program Files\apache-maven-3.5.3\bin\..
Java version: 10, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-10
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
There are two parts to this.
In JDK 10, the format and name of the file have changed, to better support modules. The new name is "element-list" and the change in format allows the javadoc tool to know what modules are present in an API as well as what packages.
The copy of the API that is posted at https://docs.oracle.com/javase/10/docs/api/overview-summary.html seems to be blocking the "element-list" file, giving a 404. That needs to be investigated and fixed.
Note that you will need to use a JDK 10 version of javadoc to point to the JDK 10 API. The latest version of the tool understands both element-list (for docs about modules) and package-list (for docs about packages (i.e. no modules)).
My workaround for the moment is to point javadoc.exe at a local package-list using the offlineLinks option of the Maven Javadoc plugin (which corresponds to the linkoffline option of the Javadoc tool). I added the following to the configuration section for the plugin:
<detectJavaApiLink>false</detectJavaApiLink>
<offlineLinks>
<offlineLink>
<url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
<location>${project.basedir}</location>
</offlineLink>
</offlineLinks>
And I added <maven.compiler.release>10</maven.compiler.release> to the properties section of my pom.xml so that I could use ${maven.compiler.release} in the value for the url. (That makes the source and target compiler options redundant, but IntelliJ doesn't seem to understand release when importing Maven projects, so I kept them.)
I created a text file named package-list (no file extension) and put it in the root directory of the project (hence ${project.basedir} for the location, which is where it will look for package-list). That file looks like this:
java.lang
java.util
java.util.concurrent
java.util.function
java.util.stream
It only needs the packages that you're trying to link to. I also tried naming the file element-list and following the format that javadoc.exe uses for modularized projects, like so:
module:java.base
java.lang
java.util
java.util.concurrent
java.util.function
java.util.stream
But that didn't work (Javadoc successfully generated, but no JDK links, as before). It complained that it couldn't find package-list.
So, once again, the relevant bits of the pom.xml:
<properties>
<maven.compiler.release>10</maven.compiler.release> <!--release makes source and target-->
<maven.compiler.source>10</maven.compiler.source> <!--redundant, but IntelliJ doesn't-->
<maven.compiler.target>10</maven.compiler.target> <!--use release when importing-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!--update dependency for Java 10 compatibility-->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<detectJavaApiLink>false</detectJavaApiLink>
<offlineLinks>
<offlineLink>
<url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
<location>${project.basedir}</location>
</offlineLink>
</offlineLinks>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
...Maven committer here.
Appropriate bits have been added to Maven Javadoc Plugin in master already, but that won't help due to a bug in javadoc(1) in Java 11. See MJAVADOC-561 for details. The broken links can only be fixed by Oracle.
Edit: The fix is scheduled for Java 11.0.2 by Oracle.

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).

Eclipse doesn't move classes compiled with maven to tomcat running directory

Well I'm running Eclipse with Tomcat runtime environment (it is run from Eclipse) and I've recently turned my web project to Maven project. Now it finally compiles well, however when I try running it on server it doesn't seem to load the compiled classes and hibernate configuration files to the Tomcat working directory in :
**D:\Dropbox\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myProject**
So I have to copy all the compiled classes and practically all the missing files manually everytime I now change anything...
Can I change anything in Eclipse settings? Also where should I output my compiled classes from Maven? At the moment the build in pom.xml looks like this:
<build>
<sourceDirectory>src/</sourceDirectory>
<directory>${basedir}/build</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Can anyone help me with this? Thanks in advance.

Categories

Resources