wb.ouyang

毕竟几人真得鹿,不知终日梦为鱼

导航

解决eclipse部署maven项目无法导入lib的问题

eclipse版本为2018-12(4.10.0)

 

1、默认tomcat的server配置

 

  改成:

 

2、项目部署

按上面的配置,项目会部署到你配置的本地tomcat的webapps目录下。

 

 

 

 

 部署了项目jweb-jweb和jweb-jwebapi,发现其中一个项目确实lib目录,即第三方jar包没有进来,显然这样会导致启动失败,Class找不到。

 

3、比较两个项目的.classpath文件的不同,发现jweb-apiweb中多了这个配置:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>

 

以及把<attribute name="maven.pomderived" value="true"/>改成 <attribute name="owner.project.facets" value="java"/>,否则项目部署有lib目录,但仍然启动失败。

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

 

 4、配置出现问题的原因

  创建jweb-jweb项目时打包方式为jar,创建好后手动到pom文件中修改jar为war。而jweb-apiweb是直接eclpse创建maven工程时指定为war。

 

贴一下没问题时.classpath的内容,以作为对照:eclipse版本为2018-12(4.10.0)

<?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 excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <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"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

 

posted on 2019-06-20 15:38  wenbin_ouyang  阅读(2307)  评论(0)    收藏  举报