繁体   English   中英

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

[英]Convert simple Java application to Dynamic web project

很抱歉问这个愚蠢的问题,我一直在努力,但是仍然不知道如何将一个简单的项目转换为动态Web项目。

我正在使用WebSphere Application Server,我想在其中运行我的简单应用程序。

这是应用程序的项目结构,当我右键单击并作为Java应用程序运行时,它运行平稳。 我在哪里进行更改,以便可以在WebSphere Application Server上运行它。

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();
    }
}

HelloWorld.java

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);
    }
}

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>

AppTest.java

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 );
    }
}

谢谢你的帮助.....

由于您已经在使用Maven,最简单的方法可能是在maven-eclipse-plugin中配置wtpversion 并在项目上运行以下命令:

mvn eclipse:eclipse

另一个选择是安装Maven Integration for Eclipse WTP

暂无
暂无

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

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