eclipse 普通java项目 转换为maven项目

参考文档

http://www.cnblogs.com/liuning8023/p/4726822.html

首先,右键选择 JavaDemo,选择“Configure –> Convert to Maven Project”, 填写“Group ID”和“Artifact Id”都为“JavaDemo”。

在文件系统下,在 src 目录下建立 main 和 test 子目录,并在它们下再分别建立 java 子目录。也就是,src/main/java,src/test/java。然后修改 .classpath 文件,或用一个现成的 Maven .classpath 文件覆盖它即可。



<?xml version="1.0" encoding="UTF-8"?>

<classpath>

    <classpathentry kind="src" output="target/classes" path="src">

        <attributes>

            <attribute name="optional" value="true"/>

            <attribute name="maven.pomderived" value="true"/>

        </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="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="output" path="target/classes"/>

</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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">

        <attributes>

            <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="output" path="target/classes"/>

</classpath>

然后把代码都挪到src/main/java下面

刷新或者重开eclipse即可

打开pom.xml

在dependencies添加依赖库

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.54</version>
</dependency>
</dependencies>

在build添加一个默认build方法

<build>
<defaultGoal></defaultGoal>

配置一个maven打包插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>Test</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

 

 

另外

打开maven项目报错
Maven:Could not get the value for parameter encoding for plugin execution default-resources
解决
关闭IDE,删除Maven仓库(C:\Users\Leon.m2\repository)里的所有文件

© 2017, 新之助meow. 原创文章转载请注明: 转载自http://www.xinmeow.com

0.00 avg. rating (0% score) - 0 votes
点赞