Maven build fails with "package com.fasterxml.jackson does not exist" - java

I need to parse a json file in my maven project.
For that I started with a simple import in my java file (App.java)
package com.mycompany.app;
import com.fasterxml.jackson.*;// <-------- HERE
public class App
{
public static void main( String[] args )
{
}
}
Then, I tried to compile the project by using mvn package but I got an error:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.mycompany.app:my-app >----------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # my-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /tmp/my-app/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # my-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /tmp/my-app/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /tmp/my-app/src/main/java/com/mycompany/app/App.java:[2,1] package com.fasterxml.jackson does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.628 s
[INFO] Finished at: 2022-05-10T15:31:39+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project my-app: Compilation failure
[ERROR] /tmp/my-app/src/main/java/com/mycompany/app/App.java:[2,1] package com.fasterxml.jackson does not exist
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Here is how I built my maven project:
I created my maven project:
mvn -B archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4
I modified the file App.java (created by the previous command) to match with my file.
I modified pom.xml in order to add the dependency:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
</dependency>
Do you know how to solve this error?

I've already recently answered a similar question: the problem is that com.fasterxml.jackson is not a package, there is a folder com/fasterxml/jackson (see the source), but not a package. In Java, package is a namespace that contains at least one class. Asterix import imports non-recursively all the classes in the package. So, if you need, let's say, to use classes JsonParser.java and JacksonException.java from the package com.fasterxml.jackson.core, you may add an asterix import like that: com.fasterxml.jackson.core.*

Related

Executing Project through Maven Invoker is throwing a compilation error

I am trying to execute the maven project from java main
Please refer the code below.
public static void main(String args[]) throws MavenInvocationException
{
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "C:\\Users\\DPKA764\\git\\be.axa.testautomation.phoenixiard\\pom.xml" ) );
request.setGoals( Arrays.asList( "clean", "install" ) );
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File("C:\\J\\apache-maven-3.5.3"));
System.out.println(""+invoker.getMavenHome());
invoker.execute( request );
System.out.println("suites are completed");
}
and when i execute the code as 'Java Application' it is throwing the following error.
[WARN] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< be.axa.PhoenixIARD:PhoenixIARD >-------------------
[INFO] Building git-training 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) # PhoenixIARD ---
[INFO] Deleting C:\Users\DPKA764\git\be.axa.testautomation.phoenixiard\target
[INFO]
[INFO] --- properties-maven-plugin:1.0.0:read-project-properties (default) # PhoenixIARD ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # PhoenixIARD ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\DPKA764\git\be.axa.testautomation.phoenixiard\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # PhoenixIARD ---
[INFO] Compiling 57 source files to C:\Users\DPKA764\git\be.axa.testautomation.phoenixiard\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
C:\Program Files\Java\jre7\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.885 s
[INFO] Finished at: 2020-02-03T18:24:34+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "metadata" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project PhoenixIARD: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
but when i execute the project directly as Maven Test It will run fine.Please suggest any changes i have to do

Java EE 8 tutorial - Maven archetype does not exist

I'm trying to do this tutorial from Java EE 8 tutorial.
I'm following the instructions on how to install tutorial archetypes, which I've downloaded from this repository.
Error message printed in the bottom.
Is this related to the fact that the repository is archived, and the tutorials are outdated, or am I doing something wrong?
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.1.0:generate (default-cli) > generate-sources # standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.1.0:generate (default-cli) < generate-sources # standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.1.0:generate (default-cli) # standalone-pom ---
[INFO] Generating project in Batch mode
[WARNING] Archetype not found in any catalog. Falling back to central repository.
[WARNING] Add a repository with id 'archetype' in your settings.xml if archetype's repository is elsewhere.
[WARNING] The POM for org.glassfish.javaeetutorial:jaxrs-service-archetype:jar:4.0.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.765 s
[INFO] Finished at: 2019-06-10T20:16:02+02:00
[INFO] Final Memory: 15M/195M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.1.0:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.glassfish.javaeetutorial:jaxrs-service-archetype:4.0.0) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

mvn install:install-file is unable to install ojdbc7.jar at correct location

I am having difficulty in getting this ojdbc7 JAR file installed in the correct location. I tried the following from Windows 10 command prompt and got the BUILD SUCCESS message as shown below:
C:\Users\john>mvn install:install-file -Dfile=C:\ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # standalone-pom ---
[INFO] Installing C:\ojdbc7.jar to C:\Users\l-john\.m2\repository\com\oracle\ojdbc7\12.1.0.1\ojdbc7-12.1.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.381 s
[INFO] Finished at: 2018-10-24T12:09:04-05:00
[INFO] ------------------------------------------------------------------------
However, when I went inside the 12.1.0.1 folder (located here C:\Users\john\.m2\repository\com\oracle\ojdbc7\12.1.0.1) I only saw the following files :
For one of my Maven project, eclipse(version 2018-19) is trying to access the JAR file and I keep getting following BUILD FAILURE message which is obvious since the file isn't there:
BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.208 s
[INFO] Finished at: 2018-10-24T12:15:39-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company.ii:MyProject:war:0.1: Could not find artifact com.oracle.jdbc:ojdbc7:jar:12.1.0.1 in spring-releases (https://repo.spring.io/libs-release) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
In my pom.xml, I do have the dependency defined as follows:
Is there anything I am doing wrong? Please let me know if I need to perform some additional testing?
I could see that in mvn install command -DgroupId is not correct, instead of giving "-DgroupId=com.oracle.jdbc", you have given just "-DgroupId=com.oracle"
Maven tells you it is installing the jar to
C:\Users\l-john\.m2\repository\com\oracle\ojdbc7\12.1.0.1\ojdbc7-12.1.0.1.jar
But you are looking at
C:\Users\john\.m2\repository\com\oracle\ojdbc7\12.1.0.1
l-john vs john

Jenkins Non-readable POM

This error is posted in different forums even here. I have tried the different alternatives. I tried changing the POM permissions. I am using the default maven settings. JDK is 8, Maven 3.5.3.
I just want to try a very simple junit application. From the command line I have no problems running "mvn test"
junitexample amh$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.junit:junit-example >-----------------------
[INFO] Building junit-example 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # junit-example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/amhg/Documents/dev/intellik2/junitexample/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # junit-example ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # junit-example ---
[INFO] Surefire report directory: /Users/amhg/Documents/dev/intellik2/junitexample/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running CalculatorTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.178 s
[INFO] Finished at: 2018-04-08T01:39:52+02:00
[INFO] ------------------------------------------------------------------------
But from Jenkins, from the Console Output I have this error:
Console Output
Started by user Andrea
Building in workspace /Users/Shared/Jenkins/Home/workspace/calc
[calc] $ /Users/amhg/apache-maven-3.5.3/bin/mvn -f /Users/amhg/Documents/dev/intellik2/junitexample test
POM file /Users/amhg/Documents/dev/intellik2/junitexample specified with the -f/--file command line argument does not exist
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (Permission denied) #
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project (/Users/amhg/Documents/dev/intellik2/junitexample) has 1 error
[ERROR] Non-readable POM /Users/amhg/Documents/dev/intellik2/junitexample: /Users/amhg/Documents/dev/intellik2/junitexample (Permission denied)
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
This is my POM file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.junit</groupId>
<artifactId>junit-example</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>junit-example</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And I just have a simple test:
import org.junit.BeforeClass;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class CalculatorTest {
private static ICalculator calculator;
#BeforeClass
public static void initCalculator() {
calculator = new Calculator();
}
#Test
public void testSum() {
int result = calculator.sum(3, 4);
assertEquals(7, result);
}
}
I donĀ“t know what else I could try. I opened all the topics related to the problem.
Any other suggestion?
I had exact same problem - local maven build works and Jenkins fails with the same error as yours.
Once Jenkins job is started, it will import source code to /your-jenkins/workspace/your-job-name folder and then start building. In your DSL, you have to mention the path to your pom in the workspace.
Take a look at the Jenkins workspace view to see where your pom is located once the source code is downloaded. This will aid in resolving the problem.
in the -f option you have provided. the maven is unable to identify the pom to read
-f /Users/amhg/Documents/dev/intellik2/junitexample test
try giving in the complete name of the pom including .xml
-f /Users/amhg/Documents/dev/intellik2/junitexample nameofpom.xml
Please check what you have in your Jenkins Build -> Goals and in your Build -> POM.
You probably switched those two.

Missing JUNIT Jar Exception while building project using Maven

I am in the beginning phase of Maven. I created a project and was trying to use the command. what is missing at my end? I am trying to compile and run a TestSuite File:
mvn clean package
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.myProject</groupId>
<artifactId>myTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>egdsvTest</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
but i get the below exception after using it.
Exception
D:\MVN_Shirish_Project\Test>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethrea
ded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Test ---
[INFO] Deleting D:\MVN_Shirish_Project\Test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Test
---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\MVN_Shirish_Project\Test\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # Test ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 1 source file to D:\MVN_Shirish_Project\Test\target\classe
s
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # eg
dsvTest ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\MVN_Shirish_Project\Test\src\
test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) #
Test ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 1 source file to D:\MVN_Shirish_Project\Test\target\test-c
lasses
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # Test ---
[INFO] Surefire report directory: D:\MVN_Shirish_Project\Test\target\surefi
re-reports
[WARNING] Missing POM for org.apache.maven.surefire:surefire-junit3:jar:2.12.4
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.968 s
[INFO] Finished at: 2014-10-14T12:28:09+05:30
[INFO] Final Memory: 7M/247M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
12.4:test (default-test) on project Test: Unable to generate classpath: org
.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
[ERROR] ----------
[ERROR] 1) org.apache.maven.surefire:surefire-junit3:jar:2.12.4
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=org.apache.maven.surefire -DartifactI
d=surefire-junit3 -Dversion=2.12.4 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file t
here:
[ERROR] mvn deploy:deploy-file -DgroupId=org.apache.maven.surefire -DartifactId=
surefire-junit3 -Dversion=2.12.4 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url
] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) dummy:dummy:jar:1.0
[ERROR] 2) org.apache.maven.surefire:surefire-junit3:jar:2.12.4
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] dummy:dummy:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] m1 (http://repo1.maven.org/maven2, releases=true, snapshots=false)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception
Maven works by creating a local repository in your desktop or the machine you have installed maven and running this goal.
In the process of maven running the goal, it first tries to get all the dependent jar files from Central repository as you have listed in your comments M1 or M2 and then stores them under C:/Users/yourname/.m2/repository folder (assuming you are using a windows machine) or the corresponding user folder in other OS systems.
Then it uses the jars to run the build as required per the goals given.
Now in your case, you got to figure out a way to connect to the repositories (check your settings.xml located in the .m2 folder in your User directory) and check if you can connect to the internet central maven repositories. If not you can get the jar file and manually install them as advised in the error you have got. Once you do that I think you should get past this issue. Let me know if you still have the issues.
In my case, it was caused by me doing an offline build (i.e. mvn -o install) and me not having that jar installed in my local Maven repository yet. Doing an online build (mvn install) fixed it.

Categories