Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Logging AspectJ+;蚂蚁(伐木)_Logging_Ant_Aop_Aspectj - Fatal编程技术网

Logging AspectJ+;蚂蚁(伐木)

Logging AspectJ+;蚂蚁(伐木),logging,ant,aop,aspectj,Logging,Ant,Aop,Aspectj,我是aspectj的新手。我需要用aspectj实现登录ant项目。我在网上看过很多教程,我试着做一些非常简单的事情,但不起作用。也许我什么都没注意到 我有两个ant模块——HelloWorld和AspectModule,它们非常简单。 HelloWorld.java: package oata; public class HelloWorld { public void doSmth() { System.out.println("do smth"); }

我是aspectj的新手。我需要用aspectj实现登录ant项目。我在网上看过很多教程,我试着做一些非常简单的事情,但不起作用。也许我什么都没注意到

我有两个ant模块——HelloWorld和AspectModule,它们非常简单。 HelloWorld.java:

package oata;

public class HelloWorld {

    public void doSmth() {
      System.out.println("do smth");
    }

    public static void main(String[] args) {
        System.out.println("Hello World!!!");
        HelloWorld hw = new HelloWorld();
        hw.doSmth();
        hw.doSmth();
    }
}
以及AspectModule中的LogAspect.aj:

import java.util.logging.Logger;

public aspect LogAspect {
    private static Logger LOGGER = Logger.getLogger(LogAspect.class.getName());

    pointcut logMethod() :
            execution(* oata.HelloWorld.*(..));

    before() : logMethod() {
        LOGGER.info("HELLO FROM ASPECTJ!!!");
        System.out.println("HELLO FROM ASPECTJ!!!");
    }

}
编译和构建两个模块,但当我运行HelloWorld时,LogAspect没有输出。 我做错了什么

非常感谢您提前给出答案

UPD: 方面模块(AspectsModule)的build.xml


HelloWorld模块的build.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Train" basedir="." default="build">
    <property name="build.dir" value="${basedir}/.build"/>
    <property name="build.classes.dir" value="${basedir}/.build/classes"/>
    <property name="main-class" value="oata.HelloWorld"/>
    <property name="lib.dir" value="lib"/>
    <property name="modules.dir" value=".."/>

    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="build.aspects">
        <ant dir="${modules.dir}/AspectsModule" inheritall="true" />
    </target>

    <target name="init">
       <antcall target="build.aspects"/>
    </target>

    <target name="compile" depends="init">
        <mkdir dir="${build.classes.dir}"/>
        <javac srcdir="src" destdir="${build.classes.dir}" classpathref="classpath"/>
    </target>

    <target name="build" depends="compile">
        <mkdir dir="${build.dir}/jar"/>
        <jar destfile="${build.dir}/jar/${ant.project.name}.jar" basedir="${build.classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="oata.HelloWorld"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="build">
        <java fork="true" classname="${main-class}">
        <classpath>
            <path refid="classpath"/>
            <path location="${build.dir}/jar/${ant.project.name}.jar"/>
        </classpath>
        </java>
    </target>

</project> 


解决方案是在一个ant模块中添加所有组件:)

在构建过程中,我收到警告:“与此类型名称不匹配:oata.HelloWorld”。如果它在另一个ant模块中,如何指定这个类型名?你能帮我解决这个问题吗
<?xml version="1.0" encoding="UTF-8"?>
<project name="Train" basedir="." default="build">
    <property name="build.dir" value="${basedir}/.build"/>
    <property name="build.classes.dir" value="${basedir}/.build/classes"/>
    <property name="main-class" value="oata.HelloWorld"/>
    <property name="lib.dir" value="lib"/>
    <property name="modules.dir" value=".."/>

    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="build.aspects">
        <ant dir="${modules.dir}/AspectsModule" inheritall="true" />
    </target>

    <target name="init">
       <antcall target="build.aspects"/>
    </target>

    <target name="compile" depends="init">
        <mkdir dir="${build.classes.dir}"/>
        <javac srcdir="src" destdir="${build.classes.dir}" classpathref="classpath"/>
    </target>

    <target name="build" depends="compile">
        <mkdir dir="${build.dir}/jar"/>
        <jar destfile="${build.dir}/jar/${ant.project.name}.jar" basedir="${build.classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="oata.HelloWorld"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="build">
        <java fork="true" classname="${main-class}">
        <classpath>
            <path refid="classpath"/>
            <path location="${build.dir}/jar/${ant.project.name}.jar"/>
        </classpath>
        </java>
    </target>

</project>