精华内容
下载资源
问答
  • ant用法

    2011-07-20 22:57:47
    这是非常好的原文,你按照例子操作就知道结果了,就了解了...We want to separate the source from the generated files, so our java source files will be in src folder. All generated files should be under bu...

    这是非常好的原文,你按照例子操作就知道结果了,就了解了,但一定要操作试试,不懂的在仔细阅读英文文档,应该能读懂

    We want to separate the source from the generated files, so our java source files will be in src folder. All generated files should be under build, and there splitted into several subdirectories for the individual steps: classes for our compiled files and jar for our own JAR-file.

    We have to create only the src directory. (Because I am working on Windows, here is the win-syntax - translate to your shell):

    md src

    
    

    The following simple Java class just prints a fixed message out to STDOUT, so just write this code into src\oata\HelloWorld.java.

    package oata; public class HelloWorld {

     public static void main(String[] args) {

     System.out.println("Hello World");

    }

    }

    
    

    Now just try to compile and run that:

    md build\classes

     javac -sourcepath src -d build\classes src\oata\HelloWorld.java

     java -cp build\classes oata.HelloWorld

    
    

    which will result in

    Hello World

    
    

     

    Creating a jar-file is not very difficult. But creating a startable jar-file needs more steps: create a manifest-file containing the start class, creating the target directory and archiving the files.

    echo Main-Class: oata.HelloWorld>myManifest

    md build\jar

     jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .

    java -jar build\jar\HelloWorld.jar

    
    

    Note: Do not have blanks around the >-sign in the echo Main-Class instruction because it would falsify it!

    Four steps to a running application

    After finishing the java-only step we have to think about our build process. We have to compile our code, otherwise we couldn't start the program. Oh - "start" - yes, we could provide a target for that. We should package our application. Now it's only one class - but if you want to provide a download, no one would download several hundreds files ... (think about a complex Swing GUI - so let us create a jar file. A startable jar file would be nice ... And it's a good practise to have a "clean" target, which deletes all the generated stuff. Many failures could be solved just by a "clean build".

    By default Ant uses build.xml as the name for a buildfile, so our .\build.xml would be:

    <project>

      <target name="clean">

          <delete dir="build"/>

      </target>

      <target name="compile">

         <mkdir dir="build/classes"/>

        <javac srcdir="src" destdir="build/classes"/>

      </target>

     <target name="jar">

         <mkdir dir="build/jar"/>

         <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">

              <manifest> <attribute name="Main-Class" value="oata.HelloWorld"/> </manifest>

         </jar>

      </target>

       <target name="run"> <java jar="build/jar/HelloWorld.jar" fork="true"/> </target>

    </project>

    
    

    Now you can compile, package and run the application via

    ant compile

     ant jar

     ant run

    
    

    Or shorter with

    ant compile jar run

     

    Enhance the build file

    Now we have a working buildfile we could do some enhancements: many time you are referencing the same directories, main-class and jar-name are hard coded, and while invocation you have to remember the right order of build steps.

    The first and second point would be addressed with properties, the third with a special property - an attribute of the <project>-tag and the fourth problem can be solved using dependencies.

    <project name="HelloWorld" basedir="." default="main"> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="build/classes"/> <property name="jar.dir" value="build/jar"/> <property name="main-class" value="oata.HelloWorld"/> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/apache-ant.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="${jar.dir}/apache-ant.jar" fork="true"/> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project>

    
    

    Now it's easier, just do a ant and you will get

    Buildfile: build.xml clean: compile: [mkdir] Created dir: C:\...\build\classes [javac] Compiling 1 source file to C:\...\build\classes jar: [mkdir] Created dir: C:\...\build\jar [jar] Building jar: C:\...\build\jar\HelloWorld.jar run: [java] Hello World main: BUILD SUCCESSFUL

    
    

    Using external libraries

    Somehow told us not to use syso-statements. For log-Statements we should use a Logging-API - customizable on a high degree (including switching off during usual life (= not development) execution). We use Log4J for that, because

    • it is not part of the JDK (1.4+) and we want to show how to use external libs
    • it can run under JDK 1.2 (as Ant)
    • it's highly configurable
    • it's from Apache ;-)

     

    We store our external libraries in a new directory lib. Log4J can be downloaded [1] from Logging's Homepage. Create the lib directory and extract the log4j-1.2.9.jar into that lib-directory. After that we have to modify our java source to use that library and our buildfile so that this library could be accessed during compilation and run.

    Working with Log4J is documented inside its manual. Here we use the MyApp-example from the Short Manual [2]. First we have to modify the java source to use the logging framework:

    package oata;

    import org.apache.log4j.Logger;

    import org.apache.log4j.BasicConfigurator;

     public class HelloWorld {

          static Logger logger = Logger.getLogger(HelloWorld.class);

          public static void main(String[] args) {

           BasicConfigurator.configure();

           logger.info("Hello World"); // the old SysO-statement

       }

    }

    
    

    Most of the modifications are "framework overhead" which has to be done once. The blue line is our "old System-out" statement.

    Don't try to run ant - you will only get lot of compiler errors. Log4J is not inside the classpath so we have to do a little work here. But do not change the CLASSPATH environment variable! This is only for this project and maybe you would break other environments (this is one of the most famous mistakes when working with Ant). We introduce Log4J (or to be more precise: all libraries (jar-files) which are somewhere under .\lib) into our buildfile:

    <project name="HelloWorld" basedir="." default="main">

     ...

    <property name="lib.dir" value="lib"/>

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

    ...

       <target name="compile">

           <mkdir dir="${classes.dir}"/>

          <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/>

      </target>

    <target name="run" depends="jar">

        <java fork="true" classname="${main-class}">

           <classpath>

             <path refid="classpath"/>

              <path location="${jar.dir}/apache-ant.jar"/>

         </classpath>

      </java>

    </target> ... </project>

    
    

    In this example we start our application not via its Main-Class manifest-attribute, because we could not provide a jarname and a classpath. So add our class in the red line to the already defined path and start as usual. Running ant would give (after the usual compile stuff):

    [java] 0 [main] INFO oata.HelloWorld - Hello World

    
    

    What's that?

    • [java] Ant task running at the moment
    • 0 sorry don't know - some Log4J stuff
    • [main] the running thread from our application
    • INFO log level of that statement
    • oata.HelloWorld source of that statement
    • - separator
    • Hello World the message

    For another layout ... have a look inside Log4J's documentation about using other PatternLayout's.

     

     

    Configuration files

    Why we have used Log4J? "It's highly configurable"? No - all is hard coded! But that is not the debt of Log4J - it's ours. We had coded BasicConfigurator.configure(); which implies a simple, but hard coded configuration. More confortable would be using a property file. In the java source delete the BasicConfiguration-line from the main() method (and the related import-statement). Log4J will search then for a configuration as described in it's manual. Then create a new file src/log4j.properties. That's the default name for Log4J's configuration and using that name would make life easier - not only the framework knows what is inside, you too!

    log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%m%n

    
    

    This configuration creates an output channel ("Appender") to console named as stdout which prints the message (%m) followed by a line feed (%n) - same as the earlier System.out.println() :-) Oooh kay - but we haven't finished yet. We should deliver the configuration file, too. So we change the buildfile:

    ... <target name="compile"> <mkdir dir="${classes.dir}"/> <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/> <copy todir="${classes.dir}"> <fileset dir="src" excludes="**/*.java"/> </copy> </target> ...

    
    

    This copies all resources (as long as they haven't the suffix ".java") to the build directory, so we could start the application from that directory and these files will included into the jar.

    Configuration files

    Why we have used Log4J? "It's highly configurable"? No - all is hard coded! But that is not the debt of Log4J - it's ours. We had coded BasicConfigurator.configure(); which implies a simple, but hard coded configuration. More confortable would be using a property file. In the java source delete the BasicConfiguration-line from the main() method (and the related import-statement). Log4J will search then for a configuration as described in it's manual. Then create a new file src/log4j.properties. That's the default name for Log4J's configuration and using that name would make life easier - not only the framework knows what is inside, you too!

    log4j.rootLogger=DEBUG, stdout
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%m%n
    

    This configuration creates an output channel ("Appender") to console named as stdout which prints the message (%m) followed by a line feed (%n) - same as the earlier System.out.println() :-) Oooh kay - but we haven't finished yet. We should deliver the configuration file, too. So we change the buildfile:

        ...
        <target name="compile">
            <mkdir dir="${classes.dir}"/>
            <javac srcdir="src" destdir="${classes.dir}" classpathref="classpath"/>
            <copy todir="${classes.dir}">
                <fileset dir="src" excludes="**/*.java"/>
            </copy>
        </target>
        ...
    

    This copies all resources (as long as they haven't the suffix ".java") to the build directory, so we could start the application from that directory and these files will included into the jar.

    展开全文
  • 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 ...
  • numpy.sum(arr,axis,dtype,out):此函数...参数:arr : input array.axis: axis along which we want to calculate the sum value. Otherwise, it will consider arr to be flattened(works on all the axis). a...

    numpy.sum(arr,axis,dtype,out):此函数返回指定轴上的数组元素之和。

    参数:

    arr : input array.

    axis: axis along which we want to calculate the sum value. Otherwise, it will consider arr to be flattened(works on all the axis). axis = 0 means along the column and axis = 1 means working along the row.

    out : Different array in which we want to place the result. The array must have same dimensions as expected output. Default is None.

    initial: [scalar, optional] Starting value of the sum.

    返回: Sum of the array elements (a scalar value if axis is none) or array with sum values along the specified axis.

    代码1:

    # Python Program illustrating

    # numpy.sum() method

    import numpy as np

    # 1D array

    arr = [20, 2, .2, 10, 4]

    print("\nSum of arr:", np.sum(arr))

    print("Sum of arr(uint8):", np.sum(arr, dtype = np.uint8))

    print("Sum of arr(float32):", np.sum(arr, dtype = np.float32))

    print ("\nIs np.sum(arr).dtype == np.uint:",

    np.sum(arr).dtype == np.uint)

    print ("Is np.sum(arr).dtype == np.uint:",

    np.sum(arr).dtype == np.float)

    输出:

    Sum of arr: 36.2

    Sum of arr(uint8): 36

    Sum of arr(float32): 36.2

    Is np.sum(arr).dtype == np.uint: False

    Is np.sum(arr).dtype == np.uint: True

    代码2:

    # Python Program illustrating

    # numpy.sum() method

    import numpy as np

    # 2D array

    arr = [[14, 17, 12, 33, 44],

    [15, 6, 27, 8, 19],

    [23, 2, 54, 1, 4,]]

    print("\nSum of arr:", np.sum(arr))

    print("Sum of arr(uint8):", np.sum(arr, dtype = np.uint8))

    print("Sum of arr(float32):", np.sum(arr, dtype = np.float32))

    print ("\nIs np.sum(arr).dtype == np.uint:",

    np.sum(arr).dtype == np.uint)

    print ("Is np.sum(arr).dtype == np.uint:",

    np.sum(arr).dtype == np.float)

    输出:

    Sum of arr: 279

    Sum of arr(uint8): 23

    Sum of arr(float32): 279.0

    Is np.sum(arr).dtype == np.uint: False

    Is np.sum(arr).dtype == np.uint: False

    代码3:

    # Python Program illustrating

    # numpy.sum() method

    import numpy as np

    # 2D array

    arr = [[14, 17, 12, 33, 44],

    [15, 6, 27, 8, 19],

    [23, 2, 54, 1, 4,]]

    print("\nSum of arr:", np.sum(arr))

    print("Sum of arr(axis = 0):", np.sum(arr, axis = 0))

    print("Sum of arr(axis = 1):", np.sum(arr, axis = 1))

    print("\nSum of arr (keepdimension is True):\n",

    np.sum(arr, axis = 1, keepdims = True))

    输出:

    Sum of arr: 279

    Sum of arr(axis = 0): [52 25 93 42 67]

    Sum of arr(axis = 1): [120 75 84]

    Sum of arr (keepdimension is True):

    [[120]

    [ 75]

    [ 84]]

    展开全文
  • 配置文件类型用法

    2019-03-12 04:17:16
    <p>I was thinking since .env file is static, if I want to put config like this <pre><code>var currentDate = time.Now() var currentDateFormat = currentDate.Format("2006-01-02") var logPath = dir + "/...
  • # This class provides the functionality we want. You only need to look at# this if you want to know how this ... It only needs to be defined# once, no need to muck around with its internals.class s...

    # This class provides the functionality we want. You only need to look at

    # this if you want to know how this works. It only needs to be defined

    # once, no need to muck around with its internals.

    class switch(object):

    def __init__(self, value):

    self.value = value

    self.fall = False

    def __iter__(self):

    """Return the match method once, then stop"""

    yield self.match

    raise StopIteration

    def match(self, *args):

    """Indicate whether or not to enter a case suite"""

    if self.fall or not args:

    return True

    elif self.value in args: # changed for v1.5, see below

    self.fall = True

    return True

    else:

    return False

    # The following example is pretty much the exact use-case of a dictionary,

    # but is included for its simplicity. Note that you can include statements

    # in each suite.

    v = 'ten'

    for case in switch(v):

    if case('one'):

    print 1

    break

    if case('two'):

    print 2

    break

    if case('ten'):

    print 10

    break

    if case('eleven'):

    print 11

    break

    if case(): # default, could also just omit condition or 'if True'

    print "something else!"

    # No need to break here, it'll stop anyway

    展开全文
  • I already encountered these problems before with some systems at work and it drove me nuts to the point where eventually tons of fixes had to be applied through the whole codebase to at least some of...
  • SQL With Ties 用法

    千次阅读 2009-12-06 11:57:00
    原文链接:http://thomaszae.wordpress.com/2008/03/10/with-ties-on-sql-server-2005/SQL Server 2005 has the functionality to select the top records but let’s say I want the same amount also will be ...

    原文链接:http://thomaszae.wordpress.com/2008/03/10/with-ties-on-sql-server-2005/

    SQL Server 2005 has the functionality to select the top records but let’s say I want the same amount also will be loaded. For example, I’d like to select the top 5 currency rate records from a table, but if one of the records has the same value, don’t make it count as top 5. For illustrations you could see below example.

    select top 5 * from batch where module = ‘CA’ order by curyrate desc

    BatNbr CuryRate
    000345 9900
    000350 9900
    000351 9900
    000400 9800
    000450 9750

    If you look at that one, you will see that 9900 was loaded 3 times, let’s see if I run by below scripts.

    select top 5 with ties * from batch where module = ‘CA’ order by CuryRate desc

    BatNbr CuryRate
    000345 9900
    000350 9900
    000351 9900
    000400 9800
    000450 9750
    000451 9750
    000475 9500
    000456 9400

    Could you see the difference?

     

    下面的应用场景就可以考虑用with ties

    StudentNo  Grade

    1                 99

    2                  100

    3                  80

    4                  99

    5                  98

     

    查出前三名的学生,结果集如下:

    1    100

    2    99

    4    99

    5    98

    展开全文
  • 产品中Ajax的用法

    2010-07-12 04:40:21
    The product management team want to make the product cost effective (right through the maintenance phase) <p>Now assume that the technical team gets to make the call (i wish :)) whether to give the...
  • <p>I want to be able to set the <code>Usage</code> line to specify that an argument NEEDS to be passed if the help function is invoked on the cobra command in Go. <p>This is what the regular help ...
  • But all I want to do is just pull the last couple of tweets from my account - I don't need to post anything, it's just readonly access to the user timeline. I've seen a couple of posts showing how to...
  • 可接受的Memcached用法

    2012-07-01 10:54:41
    <p>I'm having a bit of trouble with Memcached.... ...<p>I want to check if an object exists that was created by memcached and use it if it exists.. but if it doesn't, set it. </div>
  • Rails 2.2 i18n用法介绍

    2009-07-09 16:20:12
    Localizing your Rails 2.2 Application Ok, so rant over, let’s see how you do it: ...First thing you want to do is set what your default language will be. In environment.rb set the f...
  • I want to create a class which could be used inside different Applications and their APIs to create UIs. Therefor I created a module called ui.py. Inside this module is the following:from PyQt4 import...
  • AndroidViewClient AndroidViewClient was originally conceived as an extension to monkeyrunner but lately ...Want to learn more? Detailed information can be found in the AndroidViewClient/culebra wiki
  • * @param filed the field you want to validate. */ ValidationFramework.validateField = function(field) { var depends = field.getDepends(); var retStr = "OK"; for (var i = 0; i ; i++) { if ...
  • This is where I want to leverage pointers. <p>I can represent the JSON API response by two structs in Go, <code>func searchImages()</code> mimics the fake API: <pre><code>package main import "fmt...
  • What can the REG.EXE command do in Windows XP? REG.EXE does almost everything Regedt32 can do, but it allows you to do it from a command line. This can be useful when you want to quickly make a c
  • <p>I know that I should use channels, when I want to wait for a resource and yield the current processor. However I can't find an explanation of the difference of waiting for a channel and calling ...
  • A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in ...
  • <p>Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will ...
  • Follow these steps if you want to build LLVM yourself. First, download LLVM's sources (these instructions use the latest 11.0 release) D:\> git clone --depth 1 --branch llvmorg-11.0.0 ...
  • <p>But why would you want to use these left and right shift operators instead of just typing out the number, where does using these operators actually have a benefit. <p>I see a lot of answers on ...
  • I am new with Propel and want to use it. Please, if there is someone with expirience to help me. I am using MySQL. The code is just standart: <pre><code> // setup the autoloading require_once '../...
  • 边看电影,边学英语 电影小视频:date视频例句1:-If you want me to help you with your midterms, come by my lab. I'll text you the address. -Yes, yes, that would be great. Tomorrow? -It's a date. No, no,...
  • <p>Now what I want is to use the <strong>postLists</strong> post structure in my page for three different categories and here I am stuck because when I pass variable to component like this - <code>{ %...
  • <p>Lets assume that I have decode the json array correctly back as object, otherwise there will be way too much code to frustrate with. <p>Maybe just some insight will help, but I do not want to ...
  • building the thing, you want to run some simulations first to make sure everything will work as designed. For this phase of the project, you will be simulating part of the aiming system which uses ...
  • If you don’t want to deal with source code and just want to use the tool, here is Revit Lookup 2018.msi, an installer for the compiled and signed DLL ready, courtesy of Boost Your BIM. Harry's ...
  • 仅仅做为个人笔记使用 ... 主要是参考该主页上,这一段的用法 ...I want to set up virtual host routing by domain Virtual hosts can be configured by the proxy reading linked container env

空空如也

空空如也

1 2 3
收藏数 60
精华内容 24
关键字:

be用法towant