title: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
body: <p>I'm developing <code>Spring MVC Security Hibernate</code> example by taking a reference from <a href="http://www.mkyong.com/spring-security/spring-security-hibernate-annotation-example/" rel="nofollow">http://www.mkyong.com/spring-security/spring-security-hibernate-annotation-example/</a>. In this example, I updated maven dependencies to latest versions</p>
  
  <pre><code>&lt;properties&gt;
          &lt;jdk.version&gt;1.8&lt;/jdk.version&gt;
          &lt;spring.version&gt;4.2.4.RELEASE&lt;/spring.version&gt;
          &lt;spring.security.version&gt;3.2.9.RELEASE&lt;/spring.security.version&gt;
          &lt;jstl.version&gt;1.2&lt;/jstl.version&gt;
          &lt;mysql.connector.version&gt;5.1.38&lt;/mysql.connector.version&gt;
          &lt;logback.version&gt;1.1.2&lt;/logback.version&gt;
          &lt;slf4j.version&gt;1.7.6&lt;/slf4j.version&gt;
          &lt;hibernate.version&gt;4.2.11.Final&lt;/hibernate.version&gt;
          &lt;dbcp.version&gt;1.4&lt;/dbcp.version&gt;
      &lt;/properties&gt;
  </code></pre>
  
  <p>The compilation error for reference:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-security-hibernate-annotation: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -&gt; [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-security-hibernate-annotation: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
          at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
          at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
          at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
          at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
          at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
          at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  Caused by: org.apache.maven.plugin.MojoExecutionException: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
          at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:193)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
          ... 19 more
  Caused by: org.codehaus.plexus.archiver.ArchiverException: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
          at org.codehaus.plexus.archiver.war.WarArchiver.initZipOutputStream(WarArchiver.java:148)
          at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.createArchiveMain(AbstractZipArchiver.java:309)
          at org.codehaus.plexus.archiver.zip.AbstractZipArchiver.execute(AbstractZipArchiver.java:211)
          at org.codehaus.plexus.archiver.AbstractArchiver.createArchive(AbstractArchiver.java:897)
          at org.apache.maven.archiver.MavenArchiver.createArchive(MavenArchiver.java:582)
          at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:243)
          at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:177)
          ... 21 more
  [ERROR]
  [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/MojoExecutionException
  </code></pre>
  
  <p>Not sure what is wrong here. Pls help.
  SecurityConfig.java</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      @Qualifier("userDetailsService")
      private UserDetailsService userDetailsService;
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http.authorizeRequests().antMatchers("/admin/**")
          .access("hasRole('ROLE_ADMIN')").and().formLogin()
          .loginPage("/login").failureUrl("/login?error")
          .usernameParameter("username")
          .passwordParameter("password")
          .and().logout().logoutSuccessUrl("/login?logout")
          .and().csrf()
          .and().exceptionHandling().accessDeniedPage("/403");
      }
  
      @Bean
      public PasswordEncoder passwordEncoder(){
          PasswordEncoder encoder = new BCryptPasswordEncoder();
          return encoder;
      }
  }
  </code></pre>
  
  <p>AppConfig.java</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  @ComponentScan({ "com.mkyong.*" })
  @EnableTransactionManagement
  @Import({ SecurityConfig.class })
  public class AppConfig {
  
      @Bean
      public SessionFactory sessionFactory() {
          LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(dataSource());
          builder
          .scanPackages("com.mkyong.users.model")
          .addProperties(getHibernateProperties());
  
          return builder.buildSessionFactory();
      }
  
      private Properties getHibernateProperties() {
          Properties prop = new Properties();
          prop.put("hibernate.format_sql", "true");
          prop.put("hibernate.show_sql", "true");
          prop.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
          return prop;
      }
  
      @Bean(name = "dataSource")
      public BasicDataSource dataSource() {
          BasicDataSource ds = new BasicDataSource();
          ds.setDriverClassName("com.mysql.jdbc.Driver");
          ds.setUrl("jdbc:mysql://localhost:3306/test");
          ds.setUsername("root");
          ds.setPassword("root");
  
          return ds;
      }
  
      @Bean
      public HibernateTransactionManager txManager() {
          return new HibernateTransactionManager(sessionFactory());
      }
  
      @Bean
      public InternalResourceViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/pages/");
          viewResolver.setSuffix(".jsp");
  
          return viewResolver;
      }
  }
  </code></pre>
  
  <p>UserDao.java</p>
  
  <pre><code>public interface UserDao {
      User findByUserName(String username);
  }
  </code></pre>
  
  <p>SpringMvcInitializer.java</p>
  
  <pre><code>public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] { AppConfig.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return null;
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  }
  </code></pre>
  
  <p>SpringSecurityInitializer.java</p>
  
  <pre><code>public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
  
  }
  </code></pre>
  
  <p>UserDaoImpl.java</p>
  
  <pre><code>@Repository
  public class UserDaoImpl implements UserDao {
  
      @Autowired
      private SessionFactory sessionFactory;
  
      @SuppressWarnings("unchecked")
      public User findByUserName(String username) {
  
          List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  
          users = sessionFactory.getCurrentSession()
                  .createQuery("from User where username=?")
                  .setParameter(0, username).list();
  
          if (users.size() &gt; 0) {
              return users.get(0);
          } else {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Project Build:</p>
  
  <pre><code>&lt;build&gt;
          &lt;finalName&gt;SpringSecurity&lt;/finalName&gt;
          &lt;plugins&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${jdk.version}&lt;/source&gt;
                      &lt;target&gt;${jdk.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.9&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                      &lt;downloadJavadocs&gt;false&lt;/downloadJavadocs&gt;
                      &lt;wtpversion&gt;2.0&lt;/wtpversion&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  </code></pre>