温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

项目中没有build path如何解决

发布时间:2021-01-20 14:25:08 来源:亿速云 阅读:485 作者:Leah 栏目:开发技术

项目中没有build path如何解决?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

问题1

通过eclipse的svn资源库添加的项目,显示的方式和直接创建的不一样,且没有Java Build Path,无法添加jre和jar包。

原因是,在项目里面找到.project ,写入

<natures>
 <nature>org.eclipse.jdt.core.javanature</nature> 
</natures>

natures是标志项目是属于什么类型的项目的。

加完之后就可以build path了,切换了jdk版本。

问题2

只有jdk,不能识别maven项目。应该如下图有三个,但是我进入之后只有JRE。

解决

将.m2下的所有jar包全部删掉了,让项目重新去下载,问题解决。

.project文件的属性:

1.工程名:<name></name>

2.工程注释描述:<comment></comment>

3.Eclipse插件:<natures></natures>

4.加载方式:<buildSpec></buildSpec>

关于里面能有哪些值,我这里就不多介绍了。而org.eclipse.jdt.core.javanature 是Java Development Toolkit 的插件,很多JAVA API 等信息,都需要这个进行关联。

项目里面还有.classpath 文件,包含了你需要的jar包,eclipse 会遍历里面内容,属性有:

1.源文件位置:src

2.核心包:con

3.jar 位置:lib

4.输出class位置:output

补充:创建的maven工程没有build path

修改前:

项目中没有build path如何解决

修改后:

项目中没有build path如何解决

首先存在第一个问题:创建完成之后没有.classpath文件 所以需要新建一个.classpath文件 内容如下

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" output="target/classes" path="src/main/java">
  <attributes>
   <attribute name="optional" value="true"/>
   <attribute name="maven.pomderived" value="true"/>
  </attributes>
 </classpathentry>
 
 <classpathentry kind="src" output="target/test-classes" path="src/test/java">
  <attributes>
   <attribute name="optional" value="true"/>
   <attribute name="maven.pomderived" value="true"/>
  </attributes>
 </classpathentry>
 
 <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
  <attributes>
   <attribute name="maven.pomderived" value="true"/>
  </attributes>
 </classpathentry>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 <classpathentry kind="output" path="target/classes"/>
</classpath>

第二个问题:.project 文件内容缺失

修改前:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>hongxing-shanji</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
 <buildCommand>
 <name>org.eclipse.m2e.core.maven2Builder</name>
 <arguments>
 </arguments>
 </buildCommand>
 </buildSpec>
 <natures>
 <nature>org.eclipse.m2e.core.maven2Nature</nature>
 </natures>
</projectDescription>

修改之后正确的:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>ms-navigation-api</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
 <buildCommand>
 <name>org.eclipse.jdt.core.javabuilder</name>
 <arguments>
 </arguments>
 </buildCommand>
 <buildCommand>
 <name>org.eclipse.wst.common.project.facet.core.builder</name>
 <arguments>
 </arguments>
 </buildCommand>
 <buildCommand>
 <name>org.eclipse.wst.validation.validationbuilder</name>
 <arguments>
 </arguments>
 </buildCommand>
 <buildCommand>
 <name>org.eclipse.m2e.core.maven2Builder</name>
 <arguments>
 </arguments>
 </buildCommand>
 </buildSpec>
 <natures>
 <nature>org.eclipse.m2e.core.maven2Nature</nature>
 <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
 <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
 <nature>org.eclipse.jdt.core.javanature</nature>
 <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
 <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
 </natures>
</projectDescription>

关于项目中没有build path如何解决问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI