I've an application that uses Maven to build a JAR with the maven-assembly-plugin.
The project includes a list of dependencies and one of these is another Maven project.
I'm developing with Eclipse and when I run the project everything works fine. When I build with the Maven goal assembly:assembly, it makes the JAR but when I run the JAR it gives me this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method configure(Map<String,String>) of type SMTPMailService must
override a superclass method
at rey.sto.utils.mail.SMTPMailService.configure(SMTPMailService.java:89)
at com.ppl_sftp.transfer.FileTransfer.startTransfer(FileTransfer.java:232)
at com.ppl_sftp.transfer.MainApp.main(MainApp.java:33)
Here is the pom.xml file of the main project:
<?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.ppl-sftp</groupId>
<artifactId>transfer</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>A Camel Route</name>
<url>http://www.myorganization.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<!-- logging -->
<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.10.0</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<version>2.10.0</version>
<type>jar</type>
<scope>test</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>2.9.2</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>my-utils</groupId>
<artifactId>my-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.5</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- allows the route to be ran via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.10.0</version>
</plugin>
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.ppl_sftp.transfer.MainApp</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.ppl_sftp.transfer.MainApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
and this is the pom of the my-utils project dependency:
<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>rey-sto-utils</groupId>
<artifactId>rey-sto-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.0-beta2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>ojdbc6</groupId>
<artifactId>ojdbc6</artifactId>
<version>6</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.5</version>
</dependency>
</dependencies>
The problem is related to the Java mail dependency. As you can see I've used com.sun.mail but I saw some other different libraries that correspond to javax.mail.
Maybe I'm missing something in my poms, such as configuration parameters or plugins.
I've also tried to put in my local repository a mail.jar that works fine in other projects but I get the same error.
The "Unresolved compilation problem" comes from a class file in your utils project that Eclipse has compiled, but where Eclipse was unable to compile it properly.
The reason you are seeing different results from Eclipse and Maven is that they are using different versions of the class file. Eclipse is doing workspace resolution, so it's using the version of SMTPMailService in utils/target/classes. Maven is resolving the utils jar from your local Maven repository, which was put there by running mvn install while you had compile errors in Eclipse.
Try running mvn clean install in the utils project (clean to remove any class files generated by Eclipse, install to replace the jar in your local repository). Then rebuild your assembly.
Related
during my build (using the maven command mvn clean install) my maven compiler automatically downloads the log4j dependency 1.2.12 (repository/log4j/log4j/) but since this has vulnerability issues I need to exclude this transitive dependency download.
This is my POM (however not really needed since an empty pom would download it as well using the default mvn compiler I guess?)
<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.dsm</groupId>
<artifactId>testing</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<cucumber.version>7.3.3</cucumber.version>
<selenium.version>4.1.4</selenium.version>
<awaitility.version>4.2.0</awaitility.version>
<assertj.version>3.22.0</assertj.version>
<commonsmodel.version>5.3.3</commonsmodel.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<junit-jupiter-engine.version>5.8.2</junit-jupiter-engine.version>
<maven-cucumber-reporting.version>5.7.0</maven-cucumber-reporting.version>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven-cucumber-reporting.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>TestExecutor</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
</dependency>
</dependencies>
<configuration>
<includes>
<includes>**/ExecutorTest.java</includes>
</includes>
</configuration>
</plugin>
<!--cucumber report plugin-->
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven-cucumber-reporting.version}</version>
<executions>
<execution>
<id>generate-cucumber-reports</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Automation report</projectName>
<outputDirectory>${project.build.directory}/cucumber-reports</outputDirectory>
<inputDirectory>${project.build.directory}/cucumber</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<checkBuildResult>false</checkBuildResult>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
You already gave half of the answer yourself: you need to change the version of the maven-compiler-plugin. Instructions can be found at https://maven.apache.org/plugins/maven-compiler-plugin/usage.html
It is always a best practice to lock versions of plugins in your pom, just to ensure you can rebuild your project in X years too.
I tried updating the compiler version but now it’s giving same transitive dependency error in maven-dependency-plug-in.
Currently it’s is using 2.8 .I tried changing it to 3.3.0 which is latest but still same issue.
I have a project which works perfectly on eclipse, but when I try to run it on terminal using jar file then I get an error. Basically, the aim is to create a fat jar with all dependencies included.
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.scryAnalytics</groupId>
<artifactId>NLPAnnotationController</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>NLPAnnotationController</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hadoop.version>2.6.0-cdh5.5.1</hadoop.version>
<jdk.version>1.7</jdk.version>
<hbase.version>1.0.0-cdh5.5.1</hbase.version>
</properties>
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/cloudera/cloudera-repos</url>
</repository>
<repository>
<id>maven</id>
<url>https://repository.apache.org/content/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-api</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-common</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
<version>2.6.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.0.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.0.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.0.0-cdh5.5.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.ac.gate</groupId>
<artifactId>gate-core</artifactId>
<version>8.1</version>
</dependency>
<dependency>
<groupId>uk.ac.gate</groupId>
<artifactId>gate-compiler-jdt</artifactId>
<version>4.3.2-P20140317-1600</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.8</version>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>${jdk.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>com.scryAnalytics</groupId>
<artifactId>NLPGeneric</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>NER</groupId>
<artifactId>NER</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>NLPAnnotationController</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.scryAnalytics.NLPAnnotationController.GateNLPJob</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>conf</directory>
</resource>
</resources>
</build>
and when I run it I get the error shown below.
java -jar target/NLPAnnotationController-jar-with-dependencies.jar -inputTable posts -outputTable posts -batchId 1
Error: Invalid or corrupt jarfile target/NLPAnnotationController-jar-with-dependencies.jar
As suggested in a comment, double-check to see if the JAR file is really corrupt using jar tv <filename.jar>.
There are a couple of common causes for corrupt JAR files:
The file was corrupted by copying / transferring it the wrong way; e.g. using FTP in ASCII rather than BINARY mode.
The file system filled up while you were writing the file.
This is the ZIP64 problem. The original ZIP file format did not support more than 4GB in size. This was addressed by an extension to the format, but versions of Java prior to Java 7 did not support that.
Reference: https://blogs.oracle.com/xuemingshen/entry/zip64_support_for_4g_zipfile
There is a hard limit of 65535 entries in a ZIP file. Unfortunately, some Maven plugins does not entirely understand this limit. When you attempt to generate a JAR with too many entries, the result is a corrupt JAR file.
References:
Invalid or corrupt JAR File built by Maven shade plugin
Create a large zip assembly with maven-assembly-plugin
The first three explanations are unlikely in your case, for various reasons. That leaves a Maven plugin problem. One of the Q&As that I found said that this was fixed in version 2.5 of the maven-assembly-plugin. But you appear to be using a later version. So maybe this is not the problem after all.
Anyhow:
Check that you are using a Java 7 or later JRE or JDK on your build and execution platforms.
Try updating the version of the maven assembly plugin in your POM to the latest available.
I am trying to create a jar file from my project in Eclipse IDE. I was trying to run mvn package on my pom.xml that looks like this:
<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.javacodegeeks.snippets.enterprise</groupId>
<artifactId>springexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.javacodegeeks.snippets.enterprise.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version> 3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<version> 0.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>jfreechart</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>jcommon</groupId>
<artifactId>jcommon</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-core</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-ui</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.graphstream</groupId>
<artifactId>gs-algo</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>
<dependency>
<groupId>org.rxtx</groupId>
<artifactId>rxtx</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
<artifactId>rxtxcomm</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
Afterwards, I have gotten a file MyProject-0.0.1-SNAPSHOT.jar in the target directory of the project. Double clicking on that jar in Eclipse gave me a pop-up Windows window saying "Java Virtual Machine Launcher - A java Exception has occured!". To find more about what a possible problem could be, I have copied that jar on the desktop and run java -jar MyProject-0.0.1-SNAPSHOT.jar from that. After that, I got a following error:
Assuming from the error log, I tried to search if I have included org.hibernate.cfg.NamingStrategy in my Maven repository, and yes, I do have it there. After that I got stuck. Any ideas? Thanks.
You need to create an executable fat jar: one that contains your jar dependencies as well. See: Building a fat jar using maven
You have to include all the dependencies on the classpath that are required by your code.
You can naively do this with a shell script that manually adds everything to java -cp parameter, but this is brittle and a complete fail when something changes.
The simplest way to do this is to use the shade plugin to make an uber-jar that includes all the dependencies.
Note that this won't work correctly if any of the dependencies are cryptographically signed, unfortunately the signing stuff is in the MANIFEST file in such a way that it applies globally to the entire .jar and not individual classes or packages. You would have to manually remove the signatures from the uber jar.
I am building android project with maven. But I found when I call getChildFragmentManager in v4.Fragment, it shows an error that this method is not found. I doubt that the support-v4 package is not newer enough because if I using ant to build my project everything works just fine.
However I can't get the newer support-v4 to be included into my project.
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.meishixing</groupid>
<artifactid>crazysight</artifactid>
<version>1.0.0-snapshot</version>
<packaging>apk</packaging>
<name>crazysight</name>
<properties>
<project.build.sourceencoding>utf-8</project.build.sourceencoding>
<fest-assert.version>1.0.4</fest-assert.version>
<junit.version>4.10</junit.version>
<robolectric.version>2.0</robolectric.version>
<intellij.annotations.version>12.0</intellij.annotations.version>
</properties>
<dependencies>
<dependency>
<groupid>com.google.android</groupid>
<artifactid>android</artifactid>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>com.viewpagerindicator</groupid>
<artifactid>library</artifactid>
<version>2.4.1</version>
<type>apklib</type>
</dependency>
<dependency>
<groupid>com.tjerkw</groupid>
<artifactid>slideexpandablelistview-library</artifactid>
<version>1.1.0-snapshot</version>
<type>apklib</type>
</dependency>
<dependency>
<groupid>com.meishixing</groupid>
<artifactid>android-async-http</artifactid>
<version>1.4.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupid>com.meishixing</groupid>
<artifactid>baidu-locationp</artifactid>
<version>3.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupid>com.google.code.gson</groupid>
<artifactid>gson</artifactid>
<version>2.2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>org.apache.commons</groupid>
<artifactid>commons-lang3</artifactid>
<version>3.1</version>
</dependency>
<dependency>
<groupid>com.github.chrisbanes.pulltorefresh</groupid>
<artifactid>library</artifactid>
<version>2.1.1</version>
<type>apklib</type>
</dependency>
<dependency>
<groupid>com.novoda.imageloader</groupid>
<artifactid>imageloader-core</artifactid>
<version>1.5.8</version>
</dependency>
</dependencies>
<build>
<finalname>${project.artifactid}</finalname>
<sourcedirectory>src</sourcedirectory>
<plugins>
<plugin>
<groupid>com.jayway.maven.plugins.android.generation2</groupid>
<artifactid>android-maven-plugin</artifactid>
<version>3.6.2-snapshot</version>
<configuration>
<sdk>
<platform>17</platform>
</sdk>
<manifest>
<debuggable>true</debuggable>
</manifest>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
I've been stumped by this for hours (which is why I also added a bounty), but here's how I finally resolved it.
First of all, check your project's classpath dependancies using
mvn dependency:build-classpath
I could immediately see the problem in the output:
<home>/.m2\repository\android\extras\android-support\v4\android-support-v4.jar
<home>/.m2\repository\android\platforms\android\android-18\android-android-18.jar
<home>/.m2\repository\com\actionbarsherlock\actionbarsherlock\4.4.0\actionbarsherlock-4.4.0.apklib
<home>/.m2\repository\com\google\android\support-v4\r7\support-v4-r7.jar
<... more jars>
There are two support jars included, and the support-v4-r7.jar overrides my newer android-support-v4.jar.
The older one was being loaded by ActionBarSherlock in my project (in your project the culprit might be any of the apklib dependencies), so I excluded it in my project pom:
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.4.0</version>
<type>apklib</type>
<exclusions>
<exclusion>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
</exclusion>
</exclusions>
</dependency>
Hopefully this helps someone.
How can I create an executable jar with dependencies in sub folder in jar using Maven?
The following pom.xml will make a executable jar with the dependencies in the root but what if I wanted all the dependencies in a sub-folder in the jar so its easy if someone else would want to look in the jar. How can I change the following pom.xml file:
<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>org.xxxx</groupId>
<artifactId>DRBP</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DRBP</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.7</java-version>
<springframework-version>3.2.1.RELEASE</springframework-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework-version}</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework-version}</version>
</dependency>
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springframework-version}</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400-full</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>DRBP</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.xxxx.batch.MainBatch</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You want to look at the Maven Shade plugin.
If you want a full web app in a single jar there are a couple of options:
Do what DropWizard does which is an example maven shade + jetty.
The Tomcat version +2 Maven plugin
Winstone