【经验】java项目开发问题总结及解决方案(更新)

1、maven项目在install时,报错

  • 报错信息:

-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable

  • 解决方案

1.添加M2_HOME的环境变量
2.Preference->Java->Installed JREs->Edit 选择一个jdk,
添加 -Dmaven.multiModuleProjectDirectory=$M2_HOME

【经验】java项目开发问题总结及解决方案(更新)_第1张图片

-Dmaven.multiModuleProjectDirectory=$M2_HOME



2、eclipse启动慢卡

  • 关闭不必要的启动项:window——Preferences——General——Startup and Shutdown 中,把Plug-ins activated on startup下面不用的都不要勾选。
【经验】java项目开发问题总结及解决方案(更新)_第2张图片
  • eclipse.ini配置文件的修改(这个应该懂吧)。



3、用maven创建不了项目

  • 首先查看maven是否成功安装以及配置

  • 将生成的.m2文件删掉,再创建项目(默认路径一般是:C:\Users\14065.m2)



4、maven编码gbk不可映射字符

  • 是由于Eclipse等编辑器与本地编码格式不一致所导致。

安装系统之后,一般中文系统默认字符集是GBK。我们安装的软件一般都继承使用操作系统的默认字符集。所以当在中文XP或者win7系统开发,在使用maven(mvn compile)编译项目的时候,就会出现“编码 gbk 的不可映射字符”: 这个是由于代码使用的UTF-8,而maven编译的时候使用的GBK的缘故。 可以通过修改项目的pom文件,可以告诉maven这个项目使用UTF-8编码来编译。在项目的pom.xml文件中添加下面的配置:

   
  
  UTF-8  
 



5、SpringMVC项目运行时找不到DispatcherServlet映射

  • 问题:

No mapping found for HTTP request with URI [/courses/view3] in DispatcherServlet with name 'mvc-dispatcher-servlet'

  • 原因一:查看对应的配置文件 mvc-dispatcher-servlet.xml 配置的路径是否有误


    

  • 原因二:查看 web.xml 的配置是否有误

  
        mvc-dispatcher
         org.springframework.web.servlet.DispatcherServlet
        
        
          contextConfigLocation
          /WEB-INF/configs/spring/mvc-dispatcher-servlet.xml
        
        1


        mvc-dispatcher
        
        /



6、如何用maven下载源代码

  • 路径:window——Preferences——Maven中:勾选Download Artifact Sources
【经验】java项目开发问题总结及解决方案(更新)_第3张图片
Maven下载源码



7、eclipse项目上初现红叉

  • 将所有的jar包重新导入,包括tomcat、jre。

  • 可能是eclipse默认使用的服务器不是你自己配置的,修改为自己配置的即可:右键项目——Properties——Targeted Runtimes 中选择你自己的tomcat服务器(要仔细,比如系统默认的是Apache Tomcat 7,而你自己的是Tomcat 7 Server)

  • 更多类似问题参考



8、maven项目上有一个小红叉

  • 报错信息

Description Resource Path Location Type
Project configuration is not up-to-date with pom.xml. Run project configuration update rdc line 1 Maven Configuration Problem

  • 解决方案

右键项目,【Maven】--》【Update Project Configuration...】即可

【经验】java项目开发问题总结及解决方案(更新)_第4张图片
解决方案



8、普通java项目出现小红叉

  • 解决方案

右键项目——>properties——>project facets

【经验】java项目开发问题总结及解决方案(更新)_第5张图片
解决方案

右键项目——>properties——>java Compiler

【经验】java项目开发问题总结及解决方案(更新)_第6张图片
解决方案



9、修改maven的本地仓库地址

【经验】java项目开发问题总结及解决方案(更新)_第7张图片
配置为自己的maven地址
【经验】java项目开发问题总结及解决方案(更新)_第8张图片
配置自己的本地仓库



10、Eclipse智能提示没用了

  • 解决方案

    • 1、window->Preferences->Java->Editor->content assist 把 Enable auto activation 选项打上勾 :

      【经验】java项目开发问题总结及解决方案(更新)_第9张图片
      并且在点后面加上.abcdefghijklmnopqrstuvwxyz
      此时重启了eclipse还不成功,之后接着第二步骤

    • 2、window->Preferences->[Java] ->Editor->Content Assist->Advanced 把该勾选的斗勾选起来

【经验】java项目开发问题总结及解决方案(更新)_第10张图片
自动提示



11、Eclipse中创建maven web项目后报错

  • 问题描述

web.xml is missing and is set to true

  • 解决方案

在webapp目录下创建"WEB-INF",在"WEB-INF"下创建web.xml即可。



12、在启动maven项目时,报错Please ensure you are using JDK 1.4 or above and not a JRE

  • 报错信息

Please ensure you are using JDK 1.4 or above and not a JRE

  • 报错原因

eclipse默认是使用jre作为运行环境,而maven编译需要jdk作为运行环境

  • 解决方案

window -> preferences -> Java -> installed jres,点击add->选择Standard VM,新加一个环境,设为默认环境,注意location选择为你的jdk目录。

【经验】java项目开发问题总结及解决方案(更新)_第11张图片
解决方案

如果还是不行,就在你的项目上右击,build path -> configure build path,编辑JRE System Library,选择刚才新建的默认环境

【经验】java项目开发问题总结及解决方案(更新)_第12张图片



13、tomcat启动maven项目报错:A child container failed during start

  • 报错信息

严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
...
严重: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
...

  • 报错原因

自己添加的 servlet.api包和tomcat的这个jar包冲突。

  • 解决方案
  • 删掉servlet-api包
  • 在该依赖的配置中添加节点

    javax.servlet
    servlet-api
    2.5
    provided



14、maven项目无法加载静态的Xml,html,tsl

  • 报错信息
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'bookServiceImpl': 
Unsatisfied dependency expressed through field 'bookDao'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'bookDao' defined in file 
[C:\Tools\develop\developer\idea\project\SSMFrame\target\classes\com\ssm\frame\dao\BookDao.class]:
 Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory';
 nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in class path resource
 [spring/spring-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: 
Could not resolve resource location pattern [classpath:com/ssm/frame/dao/mapper/**Mapper.xml]: 
class path resource [com/ssm/frame/dao/mapper/] cannot be resolved to URL because it does not exist

Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'bookDao' defined in file 
[C:\Tools\develop\developer\idea\project\SSMFrame\target\classes\com\ssm\frame\dao\BookDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-dao.xml]:Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; 
nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ssm/frame/dao/mapper/**Mapper.xml]:
 class path resource [com/ssm/frame/dao/mapper/] cannot be resolved to URL because it does not exist

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-dao.xml]: Initialization of bean failed;nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ssm/frame/dao/mapper/**Mapper.xml]: 
class path resource [com/ssm/frame/dao/mapper/] cannot be resolved to URL because it does not exist

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; 
nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ssm/frame/dao/mapper/**Mapper.xml]: class path resource [com/ssm/frame/dao/mapper/] cannot be resolved to URL because it does not exist

Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ssm/frame/dao/mapper/**Mapper.xml]: class path resource [com/ssm/frame/dao/mapper/] cannot be resolved to URL because it does not exist

  • 错误分析
  • 此时,你可以去项目的工作空间里看看,你会惊讶的发现并没有生成 .xml等文件,或者生成的.class,文件并不是和你编写的.xml、.java源文件的文件内容一致的,有可能你新加的一些方法或参数都不在其中,比如:我的BookEntityMapper.xml文件中的pojo引用为"com.ssm.frame.entity.BookEntity",但是在生成的BookEntityMapper.class文件中是"com.ssm.frame.entity.Book"等错误。
  • 是因为你是用的是maven项目,maven项目都是依赖于jar配置,即依赖于pom.xml的配置,它不会自动的为你加载静态.Xml,html,tsl 等文件,所以导致无法生成相应的.class文件。
  • 解决方案


            
                src/main/resources
                
                    **/*.properties
                    **/*.xml
                    **/*.tld
                    **/*.jsp
                
                true
            

            
                src/main/java
                
                    **/*.properties
                    **/*.xml
                    **/*.tld
                
                true
            



15、Spring加载时报错: org.springframework.beans.factory.UnsatisfiedDependencyException

  • 报错信息
org.springframework.beans.factory.UnsatisfiedDependencyException
  • 错误分析

Spring 的自动注入所依赖的jar包,缺少任何一个都无法成功通过Spring进行注入

  • 解决方案

        
            org.aspectj
            aspectjrt
            1.6.12
        
        
            aspectj
            aspectjweaver
            1.5.3
        



16、springMVC项目启动时JNDI NameNotFoundException

  • 错误信息
 [org.springframework.jndi.JndiLocatorDelegate] - Converted JNDI name [java:comp/env/spring.liveBeansView.mbeanDomain] not found - trying original name [spring.liveBeansView.mbeanDomain]. javax.naming.NameNotFoundException:
  • 解决方案


        spring.profiles.active
        dev
    
    
        spring.profiles.default
        dev
    
    
        spring.liveBeansView.mbeanDomain
        dev
    



17、当数据库中时间为“0000-00-00 00:00:00”时,加载到页面时报错

  • 解决方案
 jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false


18、通过maven搭建的javaweb项目pom文件报错

  • 错误信息
Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-resources-plugin:2.6:resources: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.sonatype.plexus.build.incremental.BuildContext.newScanner(Ljava/io/File;Z)Lorg/codehaus/plexus/util/Scanner;" the class loader (instance of org/codehaus/plexus/classworlds/realm/ClassRealm) of the current class, org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for the method's defining class, org/sonatype/plexus/build/incremental/BuildContext, have different Class objects for the type org/codehaus/plexus/util/Scanner used in the signature
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-resources-plugin:2.6
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar
urls[1] = file:/C:/Develop/Tools/Maven/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[2] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
urls[3] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/shared/maven-filtering/1.1/maven-filtering-1.1.jar
urls[4] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.13/plexus-interpolation-1.13.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------
 (org.apache.maven.plugins:maven-resources-plugin:2.6:resources:default-resources:process-resources)

org.apache.maven.plugin.PluginExecutionException: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-resources-plugin:2.6:resources: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.sonatype.plexus.build.incremental.BuildContext.newScanner(Ljava/io/File;Z)Lorg/codehaus/plexus/util/Scanner;" the class loader (instance of org/codehaus/plexus/classworlds/realm/ClassRealm) of the current class, org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for the method's defining class, org/sonatype/plexus/build/incremental/BuildContext, have different Class objects for the type org/codehaus/plexus/util/Scanner used in the signature
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-resources-plugin:2.6
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar
urls[1] = file:/C:/Develop/Tools/Maven/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[2] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
urls[3] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/shared/maven-filtering/1.1/maven-filtering-1.1.jar
urls[4] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.13/plexus-interpolation-1.13.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:183)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360)
    at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52)
    at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:137)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:172)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1$1.call(MavenBuilder.java:115)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:105)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)
    at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:142)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:232)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
Caused by: org.apache.maven.plugin.PluginContainerException: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-resources-plugin:2.6:resources: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.sonatype.plexus.build.incremental.BuildContext.newScanner(Ljava/io/File;Z)Lorg/codehaus/plexus/util/Scanner;" the class loader (instance of org/codehaus/plexus/classworlds/realm/ClassRealm) of the current class, org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for the method's defining class, org/sonatype/plexus/build/incremental/BuildContext, have different Class objects for the type org/codehaus/plexus/util/Scanner used in the signature
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-resources-plugin:2.6
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar
urls[1] = file:/C:/Develop/Tools/Maven/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[2] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
urls[3] = file:/C:/Develop/Tools/Maven/.m2/repository/org/apache/maven/shared/maven-filtering/1.1/maven-filtering-1.1.jar
urls[4] = file:/C:/Develop/Tools/Maven/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.13/plexus-interpolation-1.13.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:181)
    ... 31 more
Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.sonatype.plexus.build.incremental.BuildContext.newScanner(Ljava/io/File;Z)Lorg/codehaus/plexus/util/Scanner;" the class loader (instance of org/codehaus/plexus/classworlds/realm/ClassRealm) of the current class, org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for the method's defining class, org/sonatype/plexus/build/incremental/BuildContext, have different Class objects for the type org/codehaus/plexus/util/Scanner used in the signature
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources(DefaultMavenResourcesFiltering.java:221)
    at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:301)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 31 more
  • 解决方案

在pom.xml中添加maven-resources-plugin配置项

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
             
            
                org.apache.maven.plugins
                maven-resources-plugin
                2.4.3
            

        
    

你可能感兴趣的:(【经验】java项目开发问题总结及解决方案(更新))