Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Tuesday, June 23, 2015

java exception : Expected org.codehaus.plexus.components.io.resources.PlexusIoArchivedResourceCollection, got org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection

Running maven command with maven assembly plugin
  1. mvn clean compile assembly:single
may some times throw:

Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (default-cli) on project : Failed to create assembly: Error adding file-set for to archive: Expected org.codehaus.plexus.components.io.resources.PlexusIoArchivedResourceCollection, got org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection -> [Help 1]

This may happen if by any chances maven project structure is not standard.For example: if it misses src/main/java

Non-standard structure:
src->com->company->package->files
Standard structure:
src->main->java->com->company->package->files

Solution:

  1. #navigate to project dir where pom.xml exists
  2. cd PROJECT_DIR
  3. cd src
  4. #create directories
  5. mkdir main/
  6. mkdir main/java/
  7. #move source packages & files into src/main/java directory.
  8. mv com/ main/java/

Sunday, June 22, 2014

CentOS : Maven install Script(.sh)

  1. #download maven tar
  2. wget http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
  3. #untar
  4. tar xzf apache-maven-3.0.5-bin.tar.gz -C /usr/local/
  5. #delete unnecessary back-up
  6. rm -f apache-maven-3.0.5-bin.tar.gz
  7. #install
  8. cd /usr/local
  9. #create symlink
  10. ln -s apache-maven-3.0.5 maven
  11. #create environment vars
  12. export M2_HOME=/usr/local/maven
  13. export PATH=${M2_HOME}/bin:${PATH}
  14. #check installation
  15. mvn -version
Download CentOS Maven Install Script(.sh) from Here.

Wednesday, May 28, 2014

Running maven web project with maven tomcat7 plugin

With maven tomcat7 plugin you won't have download,install and configure Tomcat server seperately.Maven can do it for you.Just run:
mvn tomcat7:run
with a tomcat7 maven plugin enabled project and browse to localhost:port/path
In your pom.xml simply put this plugin:
  1. <plugin>
  2. <groupId>org.apache.tomcat.maven</groupId>
  3. <artifactId>tomcat7-maven-plugin</artifactId>
  4. <version>2.0</version>
  5. <configuration>
  6. <server>tomcat-development-server</server>
  7. <port>9966</port> <!--make sure port doesnt conflict with others -->
  8. <path>/SpringMVC</path><!--http://localhost:9966/SpringMVC/ -->
  9. </configuration>
  10. </plugin>

Example spring maven hello world web project pom.xml:
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2.      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3.     <modelVersion>4.0.0</modelVersion>
  4.     <groupId>com.mohi</groupId>
  5.     <artifactId>SpringMVC</artifactId>
  6.     <packaging>war</packaging>
  7.     <version>1.0-SNAPSHOT</version>
  8.     <name>SpringMVC Maven Webapp</name>
  9.     <url>http://maven.apache.org</url>
  10.     <dependencies>
  11.         <dependency>
  12.             <groupId>org.springframework</groupId>
  13.             <artifactId>spring-webmvc</artifactId>
  14.             <version>4.0.3.RELEASE</version>
  15.         </dependency>
  16.     </dependencies>
  17.     <build>
  18.         <plugins>
  19.             <plugin>
  20.                 <groupId>org.apache.maven.plugins</groupId>
  21.                 <artifactId>maven-compiler-plugin</artifactId>
  22.                 <version>2.3.2</version>
  23.             </plugin>
  24.             <plugin>
  25.                 <groupId>org.apache.tomcat.maven</groupId>
  26.                 <artifactId>tomcat7-maven-plugin</artifactId>
  27.                 <version>2.0</version>
  28.                 <configuration>
  29.                     <server>tomcat-development-server</server>
  30.                     <port>9966</port>
  31.                     <path>/SpringMVC</path>
  32.                 </configuration>
  33.             </plugin>
  34.         </plugins>
  35.     </build>
  36. </project>

Sample code:
Here is a Spring Helloworld maven with tomcat7 plugin example project SpringHelloworldMavenTomcat7PluginExample.zip
Download ,unzip and run:
mvn clean install tomcat7:run
Browse to localhost:9966/SpringMVC/welcome

Sunday, May 04, 2014

Spring 3 Hibernate 4 Annotations Entity Manager PostgreSQL maven standalone example

Create the sample postgresql database at first in PgAdmin :
  1. CREATE DATABASE "TESTS"
  2. WITH OWNER = postgres
  3. ENCODING = 'UTF8'
  4. TABLESPACE = pg_default
  5. CONNECTION LIMIT = -1;

Then create the table in databse 'TESTS':
  1. CREATE TABLE USERS (
  2. ID serial NOT NULL,
  3. USERNAME text NOT NULL,
  4. NAME text NOT NULL
  5. );

Download the example from github.Build(mvn clean install) And run Main.java