Unrecognized target bytecode. Compiling Java with Groovy - java

I saw couple of problems like this but none of the given advice helped me, so I add this.
I have Java app and I migrate it to Java 11. I can run it but when i try to mvn install it i get tge error:
Failed to execute goal
org.codehaus.gmavenplus:gmavenplus-plugin:1.6:compileTests (default)
on project osa-backend: Execution default of goal
org.codehaus.gmavenplus:gmavenplus-plugin:1.6:compileTests failed:
Unrecognized target bytecode.
This is my plugin:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.16</version>
</dependency>
</dependencies>
</plugin>
Thanks for any suggestions cause I have no idea what can I change now.

This message is to warn you that your desired bytecode is not supported by the versions you currently have.
Targeting Java 11 bytecode requires Groovy 2.5.3/3.0.0-alpha-4 or newer and GMavenPlus 1.6.2 or newer.

In my case bumping the version of the maven-compiler-plugin from 3.8.1 to 3.10.1 solved the issue, every other approach suggested in similar threads failed :
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
where ${maven.compiler.release} = your java version

Related

How to run a Java/Maven application with external libraries in Heroku?

I've been building a Java application, which runs as expected when executing it locally. Now I'm trying the next step, to move it into an external platform. I chose Heroku because of their free plans for a starter, and also because it lets me have a small PostGreSQL database, which I use along with the application.
Due to the way Heroku works, I was forced to integrate Java with Maven, which I know little to none about. But I was still able to work my way there until I was able to compile and deploy the application (source code is in GitHub), albeit with errors.
For once, I'm using a couple external libraries:
jsoup-1.13.1.jar – Jsoup, for easier parsing of HTML files
mail.jar – Java mail, for emailing reports
Whenever the application is deployed in Heroku, there's an Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup, ultimately triggered by the Jsoup.connect invocation. From what I understand, Maven only add the references to the program but does not include the actual libraries there for runtime, which I think may be the cause of the issue.
I've tried modifying my pom.xml file by adding these dependencies manually:
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.18</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
</dependencies>
And also these plugins in the build section:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>checker</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
What am I doing wrong? I would be very grateful for hints to help me get my application running, at least resolving the reason why Jsoup isn't working at all in Heroku. Thanks in advance!

maven ignores sourcelevel in pom.xml

Okay, I'm pretty sure I'm missing a fundamental point here, but I'm stumped. I'm playing around with maven to get main and test sources to compile at different levels (1.7 & 1.8) - found a lot of posts but haven't gotten it working yet, so back to basics with an empty project.
So first, I want to try off by having maven not compile my code by setting the maven-compiler-plugin to source level 1.7 and using 1.8 code (stream).
This is my test code:
public static void main(String[] args) {
new ArrayList<>().stream();
}
And this is my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
IntellIJ is not having any of it and complains about the source level as expected until I change it. Now, why is it that when running maven from the command line...
$ mvn compile
or
$ mvn install
Maven won't complain?
maven version 3.5.0
java version 1.8.0_131
There's nothing in the syntax that won't work in Java 7. However, the stream() method was only introduced in JDK 8. This code compiles because you happen to be using JDK 8. If you switch to an older JDK, your code will break.
One way to prevent such potential bugs is to use the Animal Sniffer Maven Plugin which allows you to check that you aren't using parts of the JDK that are too new, even when compiling against the aforementioned new JDK:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.15</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java17</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

ERROR [SoapUI] An error occurred [No suitable driver found for jdbc:oracle:thin:#//174.23.0.187:1111/qwe]

After updating maven plugin to version 5.1.2 I get an error message
$ERROR [SoapUI] An error occurred [No suitable driver found for jdbc:oracle:thin:#//174.23.0.187:1111/qwe], see error log for details
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:#//174.23.0.187:1111/qwe
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at groovy.sql.Sql.newInstance(Sql.java:398)
at groovy.sql.Sql.newInstance(Sql.java:442)
at groovy.sql.Sql$newInstance.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
...
register JDBC driver solved the issue
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "oracle.jdbc.OracleDriver" )
You need to include oracle jdbc driver to your classpath, which you can download from here
Since you've a maven project the most normal thing to do was to simply include the dependency in your pom.xml, however due to the oracle jdbc licence there is no public repository with this jar, however recently (a few days ago) oracle adds this jar to their repository. You can try with it following the details on oracle blog (note that user auth is required and maven version 3.2.5 o higher).
In case you do not want to use the password locked Oracle repo, you can do the following:
Download the O-JDBC from Oracle.
Place it in your project. Somewhere like a lib directory.
Use the maven-install-plugin to install the jar in your local repo. Something like this:
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>install-ojdbc7</id>
<phase>pre-integration-test</phase>
<configuration>
<file>lib/ojdbc7.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
The details of how this works are discussed little further here.
For your SoapUI, you will then need to link in the dependency:
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>${soapui-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
I am using mvn verify to run all this.

Compile errors with Maven but not in Eclipse after upgrade from java 1.7 to 1.8

I am aware that similar questions has been asked in the past, but I couldn't found my answer in it.
I am using Eclipse Luna and upgraded to java 8 (build 0.25).
The JAVA_HOME points to java 8 and also it's part of the Windows Classpath.
After the upgrade, maven compile shows some Ambiguous method calls that didn't show up in java 7.
The problem is that these errors aren't shown in Eclipse and I can't find why.
I removed all jre's in eclipse and removed/added the java 8 jdk, but still no luck.
Also Eclipse is using the java 8 environment for compiler errors/warnings.
With maven I use the "plexus-compiler-javac" compiler, snapshot 2-4. I also tried without the plexus compiler and with version 2.0, but no luck.
Any idea what this could be?
My Pom snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<!--version>2.0</version-->
<version>2.4-SNAPSHOT</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
<source>1.8</source>
<target>1.8</target>
<fork>false</fork>
<encoding>utf-8</encoding>
<meminitial>256m</meminitial>
<maxmem>1024m</maxmem>
</configuration>
</plugin>
Try telling maven to use java 8 source level by adding/changing configuration of your compile plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
i face this issue with tools.jar not found, so download the latest tools.jar & copy to D:\Java\jdk1.8.0_25..\lib\tools.jar, thanks.

How to increase aspectj-maven-plugin's memory limit

I'm trying to build project with Maven, but I'm getting this error:
[INFO] --- aspectj-maven-plugin:1.4:compile (default) # core ---
[ERROR] ABORT
[ERROR] AspectJ 1.6.1 ran out of memory during compilation:
Please increase the memory available to ajc by editing the ajc script
found in your AspectJ installation directory. The -Xmx parameter value
should be increased from 64M (default) to 128M or even 256M.
I tried configure aspectj-maven-plugin in pom.xml, but it doesn't take any effect:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<configuration>
<argLine>-Xmx1024m</argLine>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
My local copy works fine, this error happens only in deployment. How it can be fixed?
export MAVEN_OPTS="-Xmx2048m -XX:MaxPermSize=512m"
into the build script solved the problem. (I tried to use 1024m)
I can't seem to find any memory usage options in the plugin manual. Maybe you should do as it suggests and manually change the ajc script in your local installation directory (although I must admit it seems a poor solution)

Categories