新之助meow

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

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

2017年7月12日 507点热度 3人点赞 0条评论

参考文档

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年7月12日

tjccn_wx@hotmail.com

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 10 月
  • 2024 年 2 月
  • 2023 年 7 月
  • 2023 年 1 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 6 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2019 年 10 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 4 月
  • 2017 年 3 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 9 月
  • 2016 年 8 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 5 月
  • 2016 年 4 月
  • 2016 年 3 月
  • 2015 年 12 月
  • 2015 年 8 月

分类

  • android
  • mysql
  • nethunter
  • proxmark
  • 未分类

COPYRIGHT © 2026 新之助meow. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang