Maven plugin external dependencies are not resolved - java

I am writing a maven plugin using Mojo classes. The plugin requires a dependency called jcifs and included it in the pom.xml of the plugin. I am able build the plugin and it is deployed into my local repository. I can find the jar file and pom.xml in my local repository.
When I use this plugin in another project in my local system, when executing the plugin goal, I am getting an exception saying the class not found. But the class is coming from the jcifs jar and it is included as part of the dependency for my plugin.
I am not able to figure out what I am missing here. Any help is appreciated
Following is the plugin pom.xml
<?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.mayuran19.maven.plugin</groupId>
<artifactId>LocalToRemoteRepo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>localtoremoterepo-maven-plugin</name>
<properties>
<mavenVersion>3.2.1</mavenVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-descriptor</id>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Following show is the pom.xml of the project that use this plugin
<?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.mayuran19.maven.plugin</groupId>
<artifactId>LocalToRemoteRepo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>localtoremoterepo-maven-plugin Test</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.mayuran19.maven.plugin</groupId>
<artifactId>LocalToRemoteRepo</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<localRepoDir>C:/Users/smayuran.SITBCS/.m2/repository</localRepoDir>
<remoteRepoDir>smb://192.168.9.196/internal</remoteRepoDir>
<username>G3App</username>
<password>P#ssword$1</password>
</configuration>
</plugin>
</plugins>
</build>
Error I am getting is class not found exception from the library jcifs

You can do this way, if you want:
**Step 1:**Download the jar file to you local machine
**Step 2:**Moving you jar to you maven repo:Run as shown bellow
Example:
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.1</version>
</dependency>
mvn install:install-file -Dfile=C:\Users\username\Desktop\mockserver-netty-3.10.1.jar -DgroupId=org.mock-server -DartifactId=mockserver-netty -Dversion=3.10.1 -Dpackaging=jar

Related

Maven successfully add dependency but found nothing in lib

Here 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">
<parent>
<artifactId>parent-web</artifactId>
<groupId>com.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web-amazon-auth</artifactId>
<description>
Amazon Auth
</description>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>web-common</artifactId>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
</dependency>
<!--failed dependencies-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.1024</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
<version>2.16.81</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<version>2.16.81</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<!--quick boot-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork: required to enable devtool-->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
That was quite strange, All the dependencies added below tag <!--failed dependencies--> are successfully added to maven, but I cannot use them in my code.
By searching them in lib, there is nothing until I force add them manually from module setting, this situation will not happen in any of other modules. I have tried to clean or invalid cache and restart, also I have tried to relink the child pom to the parent, so far , only force add manually worked. I don't know how to fix this...
All the required jars are normal in my maven repository, and they all run well in my other projects with the same pom.xml. I'm stuck here for a long time why the jars will not added into lib in this module.

Fail to Maven Build due to an API incompatibility

I want to build a maven project using Servlet API.However,I failed and error comes that:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.0.0:war (default-war) on project myfirstservlet: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:3.0.0:war failed: Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:3.0.0' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: null
I do know a little for the problem but still not know how to solve it.Should I download another version of JDK、JRE or something else,or just rewrite my code?
Here is my code of 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.mavenservlet</groupId>
<artifactId>myfirstservlet</artifactId>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>myfirstservlet Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>myfirstservlet</finalName>
<plugins>
<plugin>
<groupId>com.mavenservlet</groupId>
<artifactId>myfirstservlet</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>WebContent</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
here is the right code and it costs me some money.I still can't konw how it works.But I'd love to share it for the followers.
<?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.mavenservlet</groupId>
<artifactId>myfirstservlet</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</project>
One of the solutions is to change the default plugin version, your default maybe 2.2 or 3.0.0 so read carefully the error maven-war-plugin mentioned there.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
]

Eclipse signals me an error in this POM, even after cleaning the project and validating it in XML

I was getting an error because I mistakenly misplaced a dependency outside the dependencies tag. I corrected it, cleaned, updated, built, but I still have the error. What is wrong with my POM?
<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>it.polimi.ingsw</groupId>
<artifactId>cg_43</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cg_43</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7.1</version>
</plugin>
</plugins>
</build>
</project>
The Error that I'm getting is:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'dependency'. One of '{"http://maven.apache.org/POM/4.0.0":parent, "http://maven.apache.org/POM/4.0.0":description, "http://maven.apache.org/POM/4.0.0":prerequisites, "http://maven.apache.org/POM/4.0.0":issueManagement, "http://maven.apache.org/POM/4.0.0":ciManagement, "http://maven.apache.org/POM/4.0.0":inceptionYear, "http://maven.apache.org/POM/4.0.0":mailingLists, "http://maven.apache.org/POM/4.0.0":developers, "http://maven.apache.org/POM/4.0.0":contributors, "http://maven.apache.org/POM/4.0.0":licenses, "http://maven.apache.org/POM/4.0.0":scm, "http://maven.apache.org/POM/4.0.0":organization, "http://maven.apache.org/POM/4.0.0":build, "http://maven.apache.org/POM/4.0.0":profiles, "http://maven.apache.org/POM/4.0.0":modules, "http://maven.apache.org/POM/4.0.0":repositories, "http://maven.apache.org/POM/4.0.0":pluginRepositories, "http://maven.apache.org/POM/4.0.0":reports, "http://maven.apache.org/POM/4.0.0":reporting, "http://maven.apache.org/POM/4.0.0":dependencyManagement, "http://maven.apache.org/POM/4.0.0":distributionManagement}' is expected.
<dependency>
<groupId>it.polimi.ingsw</groupId>
<artifactId>cg_43</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> replace with <type>jar</type>
</dependency>
Deleting the project and importing it again made the error go away.

Driver class not found

I`m getting an error in my Maven mysql project in netbeans when I try and clean build. The error is:
Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (default) on project utopiaDatabase: Driver class not found: com.mysql.jdbc.Driver
I looked around and figured this is probably because my project isn`t finding my mysql-connector-java, but I have it added as a dependency and everything in my POM file looks fine, do you know why it might not be finding it?
pom.xml:
<?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.eeu46f</groupId>
<artifactId>utopiaDatabase</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<profiles>
<profile>
<id>hsql</id>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<classifier>jdk6debug</classifier>
</dependency>
</dependencies>
<properties>
<jdbc.url>jdbc:hsqldb:mem:testDB</jdbc.url>
<jdbc.username>SA</jdbc.username>
<jdbc.password></jdbc.password>
<jdbc.driver>org.hsqldb.jdbc.JDBCDriver</jdbc.driver>
</properties>
</profile>
<profile>
<id>mysql</id>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<jdbc.url>jdbc:mysql:taken out for security</jdbc.url>
<jdbc.username>taken out for security</jdbc.username>
<jdbc.password>taken out for security</jdbc.password>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<classifier>jdk6debug</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<driver>${jdbc.driver}</driver>
<url>${jdbc.url}</url>
<username>${jdbc.username}</username>
<password>${jdbc.password}</password>
</configuration>
<executions>
<execution>
<phase>generate-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<srcFiles>
<srcFile>src/test/resources/1-destroy.sql</srcFile>
<srcFile>src/test/resources/2-create.sql</srcFile>
<srcFile>src/test/resources/3-insert.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<name>utopiaDatabase</name>
database properties file in src/main/resources:
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.driver=${jdbc.driver}
I have tried adding mysql-connector-java-5.1.6 as a dependency in my maven project manually also. Thanks in advance
If you look at the homepage of the sql-maven-plugin under "Usage" it clearly shows that you have to give your driver as a dependency to the sql-maven-plugin. You only gave it as a dependency of your project.
If your project needs that dependency as well or not is a different story.

How to slim your war file by excluding jars already on the server using maven?

I am developing a tomcat project, managed by maven in eclipse. I have to deploy it remotely and everytime I deploy it, maven copies all the jar files. I aim to use tomcat shared libs but I am not quite sure about the configuration ... here is my pom.xml:
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.springer</groupId> <artifactId>GraphStatistics</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>GraphStatistics Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-jcs-core</artifactId> <version>2.0-beta-1</version> </dependency> <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j</artifactId> <version>2.2.3</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>7.0.47</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> </dependencies> <build> <finalName>GraphStatistics</finalName> <plugins> <plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>blahblah</url>
<password>blah</password>
<username>admin</username>
<path>/Yesyes</path>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Any ideas or hints?

Categories

Resources