java - ANT build JAR with Log4j -


i have wrote simple program using eclipse, output log in console log4j2. when running on eclipse, everything's fine, log output in eclipse's console, below: enter image description here

but when use ant build program jar, , running on command line, output logging cannot print out exact file name , line number, below: enter image description here

it didn't show error message during ant process. why output logging cannot print out exact file name , line number?

my project's structure is:

enter image description here

here's class code:

package p1;  import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger; import javafx.application.application; import javafx.stage.stage;  public class mymain extends application {   private static logger logger = logmanager.getlogger(mymain.class);    public static void main(string[] s){     for(int i=1; i<=10; i++){       logger.info("this logging");           }     launch(s);   }    @override   public void start(stage primarystage) throws exception{     system.exit(0);   } } 

here's log4j2.xml content:

<?xml version="1.0" encoding="utf-8"?> <configuration status="error">      <appenders>         <console name="stdout" target="system_out">             <patternlayout pattern="%d %-5p [%t] %c{2} (%f:%l) - %m%n"/>         </console>     </appenders>      <loggers>          <logger name="p1" level="trace" additivity="false">             <appenderref ref="stdout" />         </logger>          <root level="trace">             <appenderref ref="stdout" />         </root>     </loggers>  </configuration> 

the last ant build.xml content:

<?xml version="1.0" encoding="utf-8"?> <project name="my_project_packager" default="build" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">      <property name="source.dir" value="../src" />     <property name="srclib.dir" value="../lib" />     <property name="out.dir" value="bin" />     <property name="outlib.dir" value="libs" />     <property name="app.jar.name" value="myproject.jar" />     <property name="mp.ver" value="1.0" />     <property name="javahome" value="c:\program files\java\jdk1.8.0_91" />     <property name="resoure" value="d:/eclipse/workspaces/gms/myproject" />     <path id="lib_classpath">         <pathelement location="${javahome}\lib\ant-javafx.jar"/>         <pathelement location="${outlib.dir}\log4j-api-2.5.jar"/>         <pathelement location="${outlib.dir}\log4j-core-2.5.jar"/>         <pathelement location="${javahome}\jre\lib\jfxrt.jar"/>     </path>      <property name="libs.class.path" value="                 libs/log4j-api-2.5.jar                 libs/log4j-core-2.5.jar" />      <target name="create_folders">         <echo message="create new folders..." />         <delete dir="${out.dir}" />         <delete dir="${outlib.dir}" />         <mkdir dir="${out.dir}" />         <mkdir dir="${outlib.dir}" />     </target>      <target name="copy_libraries" depends="create_folders">         <echo message="coping libraries..." />         <copy todir="${outlib.dir}" flatten="true"  verbose="true" overwrite="true">             <fileset dir="${srclib.dir}">                 <include name="**/*.jar" />             </fileset>         </copy>     </target>      <target name="compile" depends="create_folders, copy_libraries">         <echo message="doing compile target..." />         <javac srcdir="${source.dir}" destdir="${out.dir}" source="1.8" target="1.8" includeantruntime="true">             <classpath refid="lib_classpath"/>         </javac>         <copy todir="${out.dir}">             <fileset dir="${source.dir}">                 <include name="**/*.xml" />             </fileset>         </copy>     </target>      <target id="mypj" name="build" depends="compile">         <echo message="doing build target..." />          <taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant">             <classpath refid="lib_classpath"/>         </taskdef>          <fx:application id="mypj" name="myproject" mainclass="p1.mymain" />         <fx:jar destfile="${app.jar.name}">             <fx:application refid="mypj" />             <manifest>                 <attribute name="class-path" value="." />                 <attribute name="javafx-version" value="8.0" />                 <attribute name="javafx-application-class" value="p1.mymain" />                 <attribute name="javafx-class-path" value="${libs.class.path}" />                 <attribute name="main-class" value="com.javafx.main.main" />                 <attribute name="implementation-vendor" value="m.c.yab" />                 <attribute name="implementation-title" value="myproject" />                 <attribute name="implementation-version" value="${mp.ver}" />             </manifest>              <fileset dir="${out.dir}">                 <exclude name="**/.svn/*" />             </fileset>         </fx:jar>     </target>  </project> 

it seems like, when use ant compile source code .class file, , build jar file these .class file, cannot point out exact file name , line number in logging message when run it. if dont use ant compile source code, use ant build jar file .class file builded eclipse in eclipse's project bin file, when run jar in cmd, can point out exact file name , line number, below: enter image description here

the new's ant build.xml file below:

<property name="source.dir" value="../src" /> <property name="srclib.dir" value="../lib" /> <property name="out.dir" value="bin" /> <property name="outlib.dir" value="libs" /> <property name="app.jar.name" value="myproject.jar" /> <property name="mp.ver" value="1.0" /> <property name="javahome" value="c:\program files\java\jdk1.8.0_91" /> <property name="resoure" value="d:/eclipse/workspaces/gms/myproject" /> <path id="lib_classpath">     <pathelement location="${javahome}\lib\ant-javafx.jar"/>     <pathelement location="${outlib.dir}\log4j-api-2.5.jar"/>     <pathelement location="${outlib.dir}\log4j-core-2.5.jar"/>     <pathelement location="${javahome}\jre\lib\jfxrt.jar"/> </path>  <property name="libs.class.path" value="             libs/log4j-api-2.5.jar             libs/log4j-core-2.5.jar" />  <target name="create_folders">     <echo message="create new folders..." />     <delete dir="${out.dir}" />     <delete dir="${outlib.dir}" />     <mkdir dir="${out.dir}" />     <mkdir dir="${outlib.dir}" /> </target>  <target name="copy_libraries" depends="create_folders">     <echo message="coping libraries..." />     <copy todir="${outlib.dir}" flatten="true"  verbose="true" overwrite="true">         <fileset dir="${srclib.dir}">             <include name="**/*.jar" />         </fileset>     </copy> </target>  <target name="compile" depends="create_folders, copy_libraries">     <echo message="doing compile target..." />     <javac srcdir="${source.dir}" destdir="${out.dir}" source="1.8" target="1.8" includeantruntime="true">         <classpath refid="lib_classpath"/>     </javac>     <copy todir="${out.dir}">         <fileset dir="${source.dir}">             <include name="**/*.xml" />         </fileset>     </copy> </target>  <target id="mypj" name="build" depends="compile">     <echo message="doing build target..." />      <taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant">         <classpath refid="lib_classpath"/>     </taskdef>      <fx:application id="mypj" name="myproject" mainclass="p1.mymain" />     <fx:jar destfile="${app.jar.name}">         <fx:application refid="mypj" />         <manifest>             <attribute name="class-path" value="." />             <attribute name="javafx-version" value="8.0" />             <attribute name="javafx-application-class" value="p1.mymain" />             <attribute name="javafx-class-path" value="${libs.class.path}" />             <attribute name="main-class" value="com.javafx.main.main" />             <attribute name="implementation-vendor" value="m.c.yab" />             <attribute name="implementation-title" value="myproject" />             <attribute name="implementation-version" value="${mp.ver}" />         </manifest>          <fileset dir="${resoure}/bin">             <exclude name="**/.svn/*" />         </fileset>     </fx:jar> </target> 

compare old build.xml, new's 1 little modified in "build" target

from

<fileset dir="${out.dir}">     <exclude name="**/.svn/*" /> </fileset> 

to

<fileset dir="${resoure}/bin">     <exclude name="**/.svn/*" /> </fileset> 

is there difference between .class file build ant javac , .class file build eclipse??? have difference, because when use file explorer compares these .class files, they're difference file size, eclipse build 1 larger, below(the left 1 build ant javac, right 1 build eclipse): enter image description here

but when decompile these .class files, contents same.

package p1;  import javafx.application.application; import javafx.stage.stage; import org.apache.logging.log4j.logmanager; import org.apache.logging.log4j.logger;  public class mymain extends application {      public mymain()     {     }      public static void main(string s[])     {         for(int = 1; <= 10; i++)             logger.info("this logging");          launch(s);     }      public void start(stage primarystage)         throws exception     {         system.exit(0);     }      private static logger logger = logmanager.getlogger(p1/mymain);  } 

can explain why happens? in advanced!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -