简体   繁体   English

如何在Eclipse中导入Maven EJB项目? (没有m2e)

[英]How do you import a maven EJB project in eclipse? (without m2e)

I made an EJB project through Maven using "org.codehaus.mojo.archetypes:ejb-jee5" lastest version. 我使用最新版本的“ org.codehaus.mojo.archetypes:ejb-jee5”通过Maven创建了一个EJB项目。

Then I typed "mvn install" and "mvn eclipse:eclipse". 然后输入“ mvn install”和“ mvn eclipse:eclipse”。

Finally I imported it as a general java project in eclipse but the project is not being recognised as being EJB capable. 最后,我将其作为eclipse中的常规Java项目导入,但是该项目未被认为具有EJB功能。

What did I do wrong? 我做错了什么?

Thanks 谢谢

EDIT 编辑

tried this as suggested by an awnser, doesn't work 根据遮阳篷的建议尝试了此操作,不起作用

<build>
    <plugins>   
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <buildcommands>
                    <buildcommand>org.eclipse.wst.common.project.facet.core.builder</buildcommand>
                    <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
                    <buildcommand>org.eclipse.wst.validation.validationbuilder</buildcommand>
                </buildcommands>
                <additionalProjectnatures>
                    <projectnature>org.eclipse.jem.workbench.JavaEMFNature</projectnature>
                    <projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
                    <projectnature>eclipse.jdt.core.javanature</projectnature>
                    <projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
                </additionalProjectnatures>
            </configuration>
        </plugin>
    </plugins>
</build>

EDIT 编辑

Apparently adding those builder and natures to your .project is not enougth, an xml file describing wich facet is enabled must be generated too, in order to do that I should add the following code betwen the '' tags 显然,将这​​些构建器和特性添加到您的.project中并不是一件容易的事,也必须生成一个描述了启用多面的xml文件,为此,我应该在''标记之间添加以下代码

<additionalProjectFacets>
    <jst.java>1.6</jst.java>
    <jst.ejb>3.0</jst.ejb>
</additionalProjectFacets>

However those 4 line generate a 'Build failure' 但是,这4行会产生“构建失败”

you can add the needed nature (thats how its named in eclipse world) in pom.xml 您可以在pom.xml中添加所需的性质(这就是它在eclipse世界中的命名方式)

See Adding project nature to your Maven pom to create an empty EJB project and see in .project how the nature is named (it might have more then one nature). 请参阅将项目性质添加到您的Maven pom中以创建一个空的EJB项目,并在.project中查看性质的命名方式(它可能具有多个性质)。

So I found out, as expected modifying the project natures is not enought, you also have to generate other file describing thing such as activated facets, etc. 因此,我发现,正如预期的那样,修改项目的性质是不够的,您还必须生成描述事物的其他文件,例如激活的构面等。

add this to your EJB project and it will be recognized as an EJB without m2e. 将其添加到您的EJB项目中,它将被识别为没有m2e的EJB。

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <additionalBuildcommands>
                        <buildCommand>
                            <name>org.eclipse.jdt.core.javabuilder</name>
                        </buildCommand>
                        <buildCommand>
                            <name>org.eclipse.wst.common.project.facet.core.builder</name>
                        </buildCommand>
                        <buildCommand>
                            <name>org.eclipse.wst.validation.validationbuilder</name>
                        </buildCommand>
                        <buildCommand>
                            <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
                            <arguments>
                                <LaunchConfigHandle>&lt;project&gt;/.settings/MavenBuilder.launch</LaunchConfigHandle>
                            </arguments>
                        </buildCommand>
                    </additionalBuildcommands>
                    <additionalProjectnatures>
                        <projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
                        <projectnature>org.eclipse.jdt.core.javanature</projectnature>
                        <projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature</projectnature>
                        <projectnature>org.eclipse.jem.workbench.JavaEMFNature</projectnature>
                    </additionalProjectnatures>
                    <additionalConfig>
                        <file>
                            <name>.settings/org.eclipse.wst.common.project.facet.core.xml</name>
                            <content>
                                <![CDATA[<faceted-project>
    <runtime name="my JBoss Runtime" />
    <fixed facet="jst.ejb" />
    <fixed facet="jst.java" />
    <installed facet="jst.java" version="6.0" />
    <installed facet="jst.ejb" version="3.0" />
</faceted-project>]]>
                            </content>
                        </file>
                        <file>
                            <name>.settings/org.eclipse.wst.common.component</name>
                            <content>
                                <![CDATA[
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="${project.artifactId}">
        <wb-resource deploy-path="/" source-path="/src/main/java" />
        <wb-resource deploy-path="/" source-path="/src/main/resources" />
        <property name="java-output-path" value="target/classes" />
    </wb-module>
</project-modules>]]>
                            </content>
                        </file>
                        <file>
                            <name>.checkstyle</name>
                            <content>
                                <![CDATA[<fileset-config file-format-version="1.2.0" simple-config="true">
    <fileset name="all" enabled="true" check-config-name="Myproject Checks" local="false">
        <file-match-pattern match-pattern="." include-pattern="true" />
    </fileset>
</fileset-config>]]>
                            </content>
                        </file>
                        <file>
                            <name>.settings/MavenBuilder.launch</name>
                            <content>
                                <![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="$${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; label=&quot;working set&quot; name=&quot;working set&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/acces-services/target/test-classes&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/acces-services/target/classes&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}" />
<booleanAttribute key="org.eclipse.debug.core.capture_output" value="false" />
<booleanAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON" value="false" />
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false" />
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="$${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; label=&quot;workingSet&quot; name=&quot;workingSet&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/acces-services/src/test/resources&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/acces-services/src/main/resources&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}" />
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${env.M2_HOME}\bin\mvn.bat" />
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean" />
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="resources:resources resources:testResources --offline" />
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true" />
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="$${workspace_loc:/acces-services}" />
</launchConfiguration>]]>
                            </content>
                        </file>
                    </additionalConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>

notice that We are defining wich Server runtime is being used, meaning you have to configure a server runtime before and put it's name inside. 请注意,我们正在定义正在使用的服务器运行时,这意味着您必须先配置服务器运行时并将其名称放入其中。

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

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