将简单Java应用程序转换为动态web项目

将简单Java应用程序转换为动态web项目,java,web-project,Java,Web Project,很抱歉问这个愚蠢的问题,我一直在绞尽脑汁,但仍然不知道如何将一个简单的项目转换为动态web项目 我正在使用WebSphereApplicationServer,我想在这里运行我的简单应用程序 这是应用程序的项目结构,当我右键单击并作为java应用程序运行时,它运行平稳。我应该在何处进行更改,以便能够在WebSphereApplicationServer上运行它 SampleProject --src | |--main | | |--java | | --com | |

很抱歉问这个愚蠢的问题,我一直在绞尽脑汁,但仍然不知道如何将一个简单的项目转换为动态web项目

我正在使用WebSphereApplicationServer,我想在这里运行我的简单应用程序

这是应用程序的项目结构,当我右键单击并作为java应用程序运行时,它运行平稳。我应该在何处进行更改,以便能够在WebSphereApplicationServer上运行它

SampleProject

--src
|  |--main
|  |   |--java
|  |     --com
|  |       --mykong
|  |         --core
|  |            --App.java
|  |            --HelloWorld.java       
|  |
|  |   |--resouces
|  |      --SpringBeans.xml
|  |
|  |--test
|     |--java
|         --com
|          --mykong
|             --core
|               --AppTest.java
|
|--target
|--.classpath
|--.project
|--.pom.xml
App.java

package com.mkyong.core;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "SpringBeans.xml");

        HelloWorld obj = (HelloWorld) context.getBean("helloBean");
        obj.printHello();
    }
}
package com.mkyong.core;

/**
 * Spring bean
 * 
 */
public class HelloWorld {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public void printHello() {
        System.out.println("Spring 3 : Hello ! " + name);
    }
}
package com.mkyong.core;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}
HelloWorld.java

package com.mkyong.core;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "SpringBeans.xml");

        HelloWorld obj = (HelloWorld) context.getBean("helloBean");
        obj.printHello();
    }
}
package com.mkyong.core;

/**
 * Spring bean
 * 
 */
public class HelloWorld {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public void printHello() {
        System.out.println("Spring 3 : Hello ! " + name);
    }
}
package com.mkyong.core;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}
SpringBeans.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="helloBean" class="com.mkyong.core.HelloWorld">
        <property name="name" value="Mkyong" />
    </bean>

</beans>

感谢您的帮助….

因为您已经在使用Maven,最简单的方法可能是在中进行配置。并在项目上运行以下操作:

mvn eclipse:eclipse

另一个选项是安装。

您是使用m2e插件还是maven eclipse插件来创建eclipse项目?我没有使用任何插件,我从mykong网站下载了此示例。我已经在类路径中手动添加了依赖项JAR。