简体   繁体   English

请帮助开始使用Eclipse,Spring,Maven创建一个简单项目

[英]Please help get started with creating a simple project using eclipse, spring, maven

  1. I installed maven and configured based on their 5 minute tutorial 我安装了maven并根据其5分钟的教程进行了配置
  2. Created a eclipse project using Maven 使用Maven创建了一个eclipse项目
  3. Installed Maven Integration for eclipse by going to eclipse market place 通过前往日食市场安装了Maven Integration for eclipse
  4. Added dependencies (spring, log4j) to pom.xml by getting the xml snippet from mvnrepository.com 通过从mvnrepository.com获取xml代码段,将依赖项(spring,log4j)添加到pom.xml
  5. right click on pom.xml and run as Maven Install. 右键单击pom.xml并以Maven Install的身份运行。

I was not able to use the new jar files immediately, had to do mvn install several times and finally all the jar files are showed up in the project. 我无法立即使用新的jar文件,不得不多次安装mvn,最后所有的jar文件都显示在项目中。

what could be the problem? 可能是什么问题呢? Is it not updating the class path correctly? 它不能正确更新类路径吗?

My questions are: 我的问题是:

  1. Are my steps above correct? 我上面的步骤正确吗?
  2. I see all the dependent jar files in the main folder. 我在主文件夹中看到所有相关的jar文件。 I want to place these jar files under lib folder. 我想将这些jar文件放在lib文件夹下。 How do i do that? 我怎么做?
  3. How can i add external jar file to the repository, these are not in mvnrepository 我如何将外部jar文件添加到存储库中,这些不在mvnrepository中
  4. How do i generate ear file to be deployed to weblogic? 如何生成要部署到Weblogic的Ear文件?

Edit: Attached the screenshot of the repository 编辑:附加存储库的屏幕快照 资料库

Edit2: i picked the wrong project type. Edit2:我选择了错误的项目类型。 Once i picked webapp archetype, it puts all dependencies in "Maven Dependencies". 一旦我选择了webapp原型,它将所有依赖项放入“ Maven依赖关系”中。 This is related to my second question. 这与我的第二个问题有关。

For your question 3 : You can add any public maven repositories in to your pom file which contains your required jar files. 对于您的问题3:可以将任何公共Maven存储库添加到包含所需jar文件的pom文件中。
http://forum.springsource.org/showthread.php?63612-Maven-repository-location http://forum.springsource.org/showthread.php?63612-Maven-repository-location

or else if you have that jar file in your local machine you can manually install it into maven repository. 否则,如果本地计算机中有该jar文件,则可以将其手动安装到maven存储库中。

mvn install:install-file -Dfile=<path-to-file> -DgroupId=group-id  
    -DartifactId=artifact-id -Dversion=version -Dpackaging=packaging

As per the Guide to installing 3rd party JARs . 按照安装第三方JAR指南

For your 2nd question you can use: 对于第二个问题,您可以使用:

http://maven.apache.org/plugins/maven-dependency-plugin/ http://maven.apache.org/plugins/maven-dependency-plugin/

If you are using m2eclipse, be sure to right click on the project, select Maven and then "Update project configuration". 如果您使用的是m2eclipse,请确保右键单击该项目,选择Maven,然后选择“更新项目配置”。 That should be enough. 那应该足够了。 I assume that you added the Maven project nature already. 我假设您已经添加了Maven项目性质。

After you create project use can use this command 创建项目使用后,可以使用此命令

mvn eclipse:eclipse -Dwtpversion=2.0

then install m2eclipse from eclipse marketplace. 然后从eclipse市场安装m2eclipse What I am doing generally is right click eclipse, import/import new maven project and choose my new maven project. 我通常做的是右键单击Eclipse,导入/导入新的Maven项目,然后选择我的新Maven项目。 Afer import if you dont see your jar folder under Libraries node of project tree, then right click build path/libraries/add class path and choose related folder. 导入后,如果在项目树的Libraries节点下看不到jar文件夹,则右键单击build path / libraries / add class path并选择相关文件夹。

If your library not available in current repository you can use another external repository with below tag: (jboss and java.net repos are very common) 如果您的库在当前存储库中不可用,则可以使用带有以下标记的另一个外部存储库:(jboss和java.net存储库很常见)

<repositories>
        <repository>
            <id>java.net2</id>
            <url>https://repository.jboss.org/nexus.</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
        </repository>
</repositories>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM