Ant 2.2.0 官方HelloWorld

1【Java EE】【ANT专辑 一】ANT在Web项目中的应用--工具介绍

+官方HelloWorld

  1.build.xml

 

 

<!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.    
-->
<project name="hello-ivy" default="run" xmlns:ivy="antlib:org.apache.ivy.ant">
    <!-- some variables used -->
    <property name="lib.dir" value="lib" />
    <property name="build.dir" value="build" />
    <property name="src.dir" value="src" />
    
    <!-- paths used for compilation and run  -->
    <path id="lib.path.id">
        <fileset dir="${lib.dir}" />
	  </path>
    <path id="run.path.id">
    		<!--引用jar包路径-->
        <path refid="lib.path.id" />
        <!--引用二进制文件路径-->
        <path location="${build.dir}" />
    </path>
    
    <!-- ================================= 
          target: resolve              
         ================================= -->
    <target name="resolve" description="--> retreive dependencies with ivy">
        <ivy:retrieve/>
    </target>    
    
    <!-- ================================= 
          target: report              
         ================================= -->
    <target name="report" depends="resolve" description="--> generates a report of dependencies">
        <ivy:report todir="${build.dir}"/>
    </target>

    <!-- ================================= 
          target: run
         ================================= -->
    <target name="run" depends="resolve" description="--> compile and run the project">
        <!--创建文件夹-->
        <mkdir dir="${build.dir}" />
        <!--编译的只需要引用jar包,classpathref=lib.path.id 下的jar包-->
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id" />
    	  <property name="msg" value="hello ivy !"/>
        <!--跑java code , 这是时候引用的外部jar包是 class文件+ jar包-->
        <java classpathref="run.path.id" classname="example.Hello">
        	<arg value="-message"/>
        	<arg value="${msg}"/>
    	  </java>
    </target>

    <!-- ================================= 
          target: clean              
         ================================= -->
    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true">
        	<!-- fileSet 顾名思义就是file 集合。-->
            <fileset dir="${basedir}">
            	<exclude name="src/**" />
            	<exclude name="build.xml" />
              <exclude name="ivy.xml" />
        	</fileset>
    	</delete>
    </target>
	
    <!-- ================================= 
          target: clean-cache              
         ================================= -->
	<target name="clean-cache" description="--> clean the ivy cache">
		<ivy:cleancache />
	</target>
</project>
 

 

因为加了中文,所以用UE保存为UTF-8就不会报:Invalid byte 2 of 2-byte UTF-8 sequence.异常

2.ivy.xml

 

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0"/>
    </dependencies>
</ivy-module>
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring中整合MyBatis并输出"Hello World",可以按照以下步骤: 1. 添加必要的依赖关系。在pom.xml中添加以下依赖项: ```xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.3.4</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> ``` 2. 创建一个包含MyBatis配置的XML文件。例如,可以在src/main/resources目录下创建一个名为"mybatis-config.xml"的文件,并添加以下内容: ```xml <configuration> <settings> <setting name="cacheEnabled" value="true" /> </settings> <mappers> <!-- 添加自己的mapper文件 --> </mappers> </configuration> ``` 3. 创建一个Mapper接口和一个对应的Mapper XML文件,用于定义"Hello World"查询。例如,在src/main/resources/mapper目录下创建一个名为"HelloMapper.xml"的文件,并添加以下内容: ```xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.mapper.HelloMapper"> <select id="getHello" resultType="java.lang.String"> select 'Hello World' </select> </mapper> ``` 在src/main/java目录下创建一个名为"HelloMapper.java"的接口,并添加以下内容: ```java package com.example.mapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @Mapper public interface HelloMapper { @Select("select 'Hello World'") String getHello(); } ``` 4. 创建一个Service类来调用Mapper接口。在src/main/java目录下创建一个名为"HelloService.java"的类,并添加以下内容: ```java package com.example.service; import com.example.mapper.HelloMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class HelloService { @Autowired private HelloMapper helloMapper; public String getHello() { return helloMapper.getHello(); } } ``` 5. 创建一个Controller类来处理请求并调用Service类。在src/main/java目录下创建一个名为"HelloController.java"的类,并添加以下内容: ```java package com.example.controller; import com.example.service.HelloService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @Autowired private HelloService helloService; @GetMapping("/hello") public String hello() { return helloService.getHello(); } } ``` 6. 运行应用程序并测试。运行应用程序并访问"http://localhost:8080/hello",应该会返回"Hello World"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值