I'm trying to make Maven call an ANT build for some legacy code. The ant build builds correctly through ant. However when I call it using the maven ant plugin, it fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line:
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\bea\jdk150_11\jre"
My javac exists at C:\bea\jdk150_11\bin and this works for all other things. Im not sure where Maven is getting this version of JAVA_HOME. JAVA_HOME in windows environmental variables is set to C:\bea\jdk150_11\ as it should be.
The Maven code that I'm using to call the build.xml is
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<ant antfile="../build/build.xml" target="deliver" >
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
First thing: Why do you execute your ANT script in install phase and not in compile?
The second thing: Your problem may be caused by the fact that Maven executes JRE instead of JDK, despite the fact that your JAVA_HOME points to JDK. To fix this see you have to manually adjust dependencies for maven-antrun-plugin. This is just an example:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<phase>compile</phase>
<configuration><target><ant/></target></configuration>
<goals><goal>run</goal></goals>
</execution>
</executions>
</plugin>
Related
It has been few weeks since I build anything in maven, and I just tried to build one of the projects and it gives me this error. I try with multiple project and they are throwing same error:
Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.8:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.8 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:15.0.2 at specified path /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar -> [Help 1]
How can I resolve this error? I can't even run mvn install -DskipTests or mvn package.
I am on JDK version 8.
Edit: here is my plugin from pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj-maven-plugin.version}</version>
<configuration>
<complianceLevel>${java.version}</complianceLevel>
<source>${java.version}</source>
<target>${java.version}</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<aspectLibraries>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aspects</artifactId>
</dependency>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
java version = 1.8
aspectj-maven-plugin.version = 1.8
EDIT: I pull this project from the repo, which means it works on other people's computer/on jenkins. I believe this is something to do with my local computer. It also gives me same error if I use terminal.
I found the answer after more research. As #Michael Katt mentioned in the comment, my JAVA_HOME wasn't properly set up. When I did which java, it gave me /usr/bin/java, but when I did echo $JAVA_HOME, it gave me nothing.
So with help of other colleague, I did vi ~/.bash_profile and added export JAVA_HOME=$(/usr/libexec/java_home). Not exactly sure why, but it is something to do with matching it with my jdk in my project structure which has /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk...
I opened new shell and typed echo $JAVA_HOME and it gives me /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home. My project build/compiles now.
I am still not sure how $(/usr/libexec/java_home) translated to /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk...
I am trying to run my java program TopicPublisher.java via command line. There are several dependencies specified through Maven.
In the directory with the pom.xml file, I ran the following commands: mvn clean, mvn package, and java -cp target/SOM_Enrichment-1.0-SNAPSHOT.jar TopicPublisher.
I get the following error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: om/solacesystems/jcsmp/JCSMPStreamingPublishEventHandler
Below is a screenshot of my directory tree:
Any ideas how to solve this?
[EDIT]
Pom File:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>CAMM</groupId>
<artifactId>SOM_Enrichment</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.solacesystems</groupId>
<artifactId>sol-jcsmp</artifactId>
<version>[10,)</version>
</dependency>
</dependencies>
Your program loads classes from the com.solacesystems dependency in your pom.xml, but your classpath only contains your build artifact jar. Build a fat jar, as #Kerry suggests, or use the exec-maven-plugin to run from the command line. From within your project directory (where you execute mvn package), execute:
mvn exec:java -Dexec.mainClass=TopicPublisher
The plugin builds the classpath argument from the dependencies defined in your pom. See https://www.mojohaus.org/exec-maven-plugin/ for more options.
Without seeing your full POM.xml I am assuming you have not build the final artifact to be a 'fat jar'. By this I mean that the JAR not only contains your own classes but all the third party dependencies.
You would need to use something like the Maven assembly plugin or the Maven shade pluginto do this for you. From the screenshot though I see you are using IntelliJ so you should also be able to run through your IDE obviously for just testing purposes.
A project that was earlier on svn was recently moved to github after which i am facing this issue while creating a build. It fails to generate the build number with the below error
Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.4:create (default) on project line-management: An error has occurred while checking scm status. Exception while executing SCM command. Error while executing command. Error while executing process. Cannot run program "svn" (in directory "D:\workspace\project_git\project_management"): CreateProcess error=2, The system cannot find the file specified -> [Help 1]
code of pom.xml
<scm>
<connection>scm:svn:http://some.svn.url/</connection>
</scm>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<doUpdate>false</doUpdate>
<timestampFormat>{0,date,"yyyyMMddHHmmss"}</timestampFormat>
<timestampPropertyName>buildNumVar</timestampPropertyName>
<shortRevisionLength>10</shortRevisionLength>
</configuration>
</plugin>
Your scm tag still contains the the connection string to your old svn repository.
You should provide the url of the new git repository here, for example <connection>scm:git:https://github.com/your-git-repo.git</connection>. For the details of the connection string, please check here.
When you install the svn program (tortoise for example) you need to check the command line option. By default, that option is disabled. That worked for me.
I can not create javadocs to a folder I like, Here is how my javadoc plugin looks like;
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<outputDirectory>${build.dir}/resources/javadoc</outputDirectory>
<reportOutputDirectory>${project.reporting.outputDirectory}/javadoc</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any ideas?
EDIT MAven install leads to error"
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:aggregate
(attach-javadocs) on project priTool: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - C:\pricing\priWebApp\src\main\..webapp\backend\local\PriUpgradeHelper.java:5:
package ..upgrademanager does not exist
[ERROR] import ...upgrademanager.ComponentInfo;
Upgrade Manager is an external dependency, but I can see its jar in library
You need to understand the difference between mvn package and mvn install. package creates the JARs in the target folder of the Maven project/module.
If there are more modules, they won't be able to see these JARs - for each project/module, Maven only looks into the local repository to resolve dependencies, even if could resolve them in the same project.
And that's what install does: Package the JARs and then install them into the local repository.
When you have a Maven project, with several modules (a.k.a a reactor build), then never use mvn package. Always use mvn install.
I have an ant build file that works when invoked by itself. When I invoke it from maven, the first few tasks execute fine (init, clean, etc.), but build fails with:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (compile) on project maven-stream: An Ant BuildException has occur
ed: The following error occurred while executing this line:
[ERROR] C:\maven_projects\cm\Qlarius Underwriter\build.xml:24: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\Program Files\Java\jdk1.7.0_07\jre"
[ERROR] around Ant part ...<ant antfile="C:\maven_projects\cm/Qlarius Underwriter/build.xml">... # 4:69 in C:\maven_projects\cm\target\antrun\build-ma
in.xml
Why would ant find java when invoked directly but not through maven?
The ant portion of the pom.xml file is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="${basedir}/Qlarius Underwriter/build.xml">
<target name="LifeQuote"/>
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
As the error suggests you're not pointing to a JDK. You need to change JAVA_HOME to be the root of your JDK and not the JRE. That way it will be able to find javac.
The other tasks init and clean will probably be ok if they are not using javac