问:
Java InvocationTargetException & NoSuchMethodError for hbase shaded client (or commons)
I'm getting a bunch of errors regarding HBase connection, but it's related to a missing string library or something wrong with my pom.xml.

I cut a lot of errors out but:

java.io.IOException: java.lang.reflect.InvocationTargetException
          at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240) ~[hbase-shaded-client-1.2.3.jar!/:1.2.3]

.. further down

```<code>at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72-internal]
Caused by: java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_72-internal]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_72-internal]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_72-internal]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_72-internal]
        at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238) ~[hbase-shaded-client-1.2.3.jar!/:1.2.3]
        ... 98 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.apache.hadoop.util.StringUtils.toLowerCase(Ljava/lang/String;)Ljava/lang/String;
        at org.apache.hadoop.hdfs.server.common.HdfsServerConstants$RollingUpgradeStartupOption.getAllOptionString(HdfsServerConstants.java:80) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.server.namenode.NameNode.<clinit>(NameNode.java:264) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:176) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:678) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:619) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:149) ~[hadoop-hdfs-2.7.3.jar!/:na]
</code>```

..

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.sp</groupId>
    <artifactId>sp-bootapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>My great SpringBootApp</name>
    <description>Jst a really cool app</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath />
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.4-1200-jdbc4</version>
                <scope>runtime</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                    </exclusion>
                </exclusions>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.1.2</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.13</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.13</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.5.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.7.2</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.7.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-shaded-client</artifactId>
            <version>1.2.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.13</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.20</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

</project>
</code>```

答: I fixed it, but I think it was Guava 16.0 that was required by something, and Guava 21.0 had deprecated util.toLowerCase or something.</p>

Body:
I'm getting a bunch of errors regarding HBase connection, but it's related to a missing string library or something wrong with my pom.xml.

I cut a lot of errors out but:

java.io.IOException: java.lang.reflect.InvocationTargetException
          at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:240) ~[hbase-shaded-client-1.2.3.jar!/:1.2.3]

.. further down

at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72-internal]
Caused by: java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_72-internal]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_72-internal]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_72-internal]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_72-internal]
        at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238) ~[hbase-shaded-client-1.2.3.jar!/:1.2.3]
        ... 98 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.apache.hadoop.util.StringUtils.toLowerCase(Ljava/lang/String;)Ljava/lang/String;
        at org.apache.hadoop.hdfs.server.common.HdfsServerConstants$RollingUpgradeStartupOption.getAllOptionString(HdfsServerConstants.java:80) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.server.namenode.NameNode.<clinit>(NameNode.java:264) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:176) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:678) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:619) ~[hadoop-hdfs-2.7.3.jar!/:na]
        at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:149) ~[hadoop-hdfs-2.7.3.jar!/:na]

..

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.sp</groupId>
    <artifactId>sp-bootapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>My great SpringBootApp</name>
    <description>Jst a really cool app</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath />
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.4-1200-jdbc4</version>
                <scope>runtime</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                    </exclusion>
                </exclusions>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>21.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.13</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.13</version>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.5.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.7.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.7.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-shaded-client</artifactId>
            <version>1.2.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.13</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.20</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

</project>


来源: stackexchange

问:
How to save text file as variable in IOS
I am sending some images via socket and I would like to create text file with information about the images to send over the network as well.  I right now I can send the images no problem by creating a variable for the image data like so

```<code>let imageData = UIImageJPEGRepresentation(someUIImage, 1.0)
</code>```

How do create a variable with the data of the text file?

```<code>let textData = someTextFileAsData.....
</code>```

答:
Expanding a bit on Anthonin C.'s answer:

Each file in iOS is identified by a URL (just like a webpage, but this is a URL referring to the iOS filesystem). There are a few places in the system where you can save files, most of which you can get the URLs for by reading

```<code>FileManager.default.urls(for: SearchPathDirectory, in: SearchPathDomainMask)
</code>```

(FileManager class reference).

For instance, to save in the user's personal "documents" directory, you would do:

```<code>let fileName = "socketLog.txt"

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  //build full path to file
  let path = dir.appendingPathComponent(fileName)

  do {
      try text.write(to: path, atomically: false, encoding: String.Encoding.utf8)
  }
  catch {/* error handling here */}
}
</code>```

where text would be the string data you want to save.

ContentLicense: CC BY-SA 3.0

Body:
I am sending some images via socket and I would like to create text file with information about the images to send over the network as well.  I right now I can send the images no problem by creating a variable for the image data like so

let imageData = UIImageJPEGRepresentation(someUIImage, 1.0)

How do create a variable with the data of the text file?

let textData = someTextFileAsData.....

Body:
Expanding a bit on Anthonin C.'s answer:

Each file in iOS is identified by a URL (just like a webpage, but this is a URL referring to the iOS filesystem). There are a few places in the system where you can save files, most of which you can get the URLs for by reading

FileManager.default.urls(for: SearchPathDirectory, in: SearchPathDomainMask)

(FileManager class reference).

For instance, to save in the user's personal "documents" directory, you would do:

let fileName = "socketLog.txt"

if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  //build full path to file
  let path = dir.appendingPathComponent(fileName)

  do {
      try text.write(to: path, atomically: false, encoding: String.Encoding.utf8)
  }
  catch {/* error handling here */}
}

where text would be the string data you want to save.


问:
How to check the amount of time between two NSDates?
I'm making a kind of challenge based app that requires that the user comes back every day. If he misses one day, he has to start all over again.
My problem is my dateChanged()-function; the first thing is, that it doesn't work very reliable, the second is that I just check if the date changed, I accordingly don't know if there were one or two days between using the app.
Here's my current function:

```<code>public func changeDays()
{
    myFormatter.dateStyle = .short
    myFormatter.locale = Locale(identifier: "de_DE")

    oldDate = defaults.string(forKey: "oldDate")!
    let newDate = Date()
    let newDateString = myFormatter.string(from: newDate)

    if newDateString == oldDate
    {
        NumberOfDaysInARow.text = "\(days) / 30"
    }
    else if newDateString != oldDate
    {
        days += 1
        NumberOfDaysInARow.text = "\(days) / 30"
        defaults.set(days, forKey: "days")
    }

    oldDate = newDateString
    defaults.set(oldDate, forKey: "oldDate")

}
</code>```

Just today it started giving me a fatal error when starting the app on my iPhone, did not happen in the simulator though... weird.
How do I have to change my function to make it a 100% reliable (and working) while also being able to check the amount of time between the two dates?

Thank you for having a look! Have a great day

答:
If you look in the documentation you will see that Date has a method whose sole purpose is too determine the interval between two dates timeIntervalSince(_:).

If you set the old date to always be 11:59PM on the day it was last used you only have to see if the interval is greater than 24 hours worth of seconds (60 seconds * 60 minutes * 24 hours).

You may want to look at the docs for DateComponents for help creating a date that uses the current date but with a specific time.

Body:
I'm making a kind of challenge based app that requires that the user comes back every day. If he misses one day, he has to start all over again.
My problem is my dateChanged()-function; the first thing is, that it doesn't work very reliable, the second is that I just check if the date changed, I accordingly don't know if there were one or two days between using the app.
Here's my current function:

public func changeDays()
{
    myFormatter.dateStyle = .short
    myFormatter.locale = Locale(identifier: "de_DE")

    oldDate = defaults.string(forKey: "oldDate")!
    let newDate = Date()
    let newDateString = myFormatter.string(from: newDate)

    if newDateString == oldDate
    {
        NumberOfDaysInARow.text = "\(days) / 30"
    }
    else if newDateString != oldDate
    {
        days += 1
        NumberOfDaysInARow.text = "\(days) / 30"
        defaults.set(days, forKey: "days")
    }

    oldDate = newDateString
    defaults.set(oldDate, forKey: "oldDate")

}

Just today it started giving me a fatal error when starting the app on my iPhone, did not happen in the simulator though... weird.
How do I have to change my function to make it a 100% reliable (and working) while also being able to check the amount of time between the two dates?

Thank you for having a look! Have a great day


问:
Trying to get property on non-object with Laravel 5.1 and Vue 2
I have a url loading with data passed on from Laravel.  I place the data in the vue data using blade syntax like this:

```<code>data: {
    id: "{!! ($header->id) !!}",
    vendor: '{!! $header->vendor_name !!}',
    orderDate: '{!! $header->orderDate !!}',
    list: [],
}
</code>```

So far so good. The data is set properly.

Then there is a method that triggers when a row in the table is clicked:

```<code>methods: {
   findInventoryItem: function(rowId) {
       var header = this.id;
       url = '{!! url('part-order/find-inventory') !!}' + '?headerId=' + header + '&rowId=' + rowId;
       window.location.href = url;
   }
</code>```

The url is setup properly.

The error happens when I click the table row.  This error pops up.

```<code>Trying to get property of non-object (View: /code/zone/resources/views/parts/part-order.blade.php)
</code>```

Notice that the error is not with the requested url but with the existing url.

The error is triggered by this line:

```<code>id: "{!! ($header->id) !!}",
</code>```

Any ideas as to what is going on here?

答:
Okay, this is a rookie mistake but I found the issue.  The worst part is that I have made this mistake before.  It had nothing to do with Laravel or Vue.  Sometimes explaining your problem and discussing it with someone helps to identify and figure out what you did wrong.  Thanks @Laerte for discussing with me.  It helped me find the solution.

The problem was in the routes.  The following route was interfering.

```<code>Route::get('part-order/{id}', 'PartOrderController@showOrder');
</code>```

and my requested route was

```<code>Route::get('part-order/find-inventory', 'PartOrderController@findInventoryNumber');
</code>```

Since my first route had a variable in the second segment, I couldn't use the other route without adding a third segment.  Because the second segment was interpreted as a variable and so never reached it in my request.

I fixed the route like this:

```<code>Route::get('part-order/find-inventory/inv', 'PartOrderController@findInventoryNumber');
</code>```

Body:
I have a url loading with data passed on from Laravel.  I place the data in the vue data using blade syntax like this:

data: {
    id: "{!! ($header->id) !!}",
    vendor: '{!! $header->vendor_name !!}',
    orderDate: '{!! $header->orderDate !!}',
    list: [],
}

So far so good. The data is set properly.

Then there is a method that triggers when a row in the table is clicked:

methods: {
   findInventoryItem: function(rowId) {
       var header = this.id;
       url = '{!! url('part-order/find-inventory') !!}' + '?headerId=' + header + '&rowId=' + rowId;
       window.location.href = url;
   }

The url is setup properly.

The error happens when I click the table row.  This error pops up.

Trying to get property of non-object (View: /code/zone/resources/views/parts/part-order.blade.php)

Notice that the error is not with the requested url but with the existing url.

The error is triggered by this line:

id: "{!! ($header->id) !!}",

Any ideas as to what is going on here?

Body:
Okay, this is a rookie mistake but I found the issue.  The worst part is that I have made this mistake before.  It had nothing to do with Laravel or Vue.  Sometimes explaining your problem and discussing it with someone helps to identify and figure out what you did wrong.  Thanks @Laerte for discussing with me.  It helped me find the solution.

The problem was in the routes.  The following route was interfering.

Route::get('part-order/{id}', 'PartOrderController@showOrder');

and my requested route was

Route::get('part-order/find-inventory', 'PartOrderController@findInventoryNumber');

Since my first route had a variable in the second segment, I couldn't use the other route without adding a third segment.  Because the second segment was interpreted as a variable and so never reached it in my request.

I fixed the route like this:

Route::get('part-order/find-inventory/inv', 'PartOrderController@findInventoryNumber');


问:
Why does my progressbar not change as the data is loading?
I am using the progressbarjs library with my Meteor application. I have a helper function which calculates the length of a list and returns a percentage number. My circular progress bar has a "data-parent" attribute which has a value generated by the helper function.

The value is valid and is changing as data is being processed so I know that the helper function is not the issue. I also noticed that if I go into inspect element and manually edit the data-parent attribute, the progress bar does not change value.

Could someone assist me in finding out why the progress bar does not change reactively?

HTML

```<code> <template name="Preset_settings">
    <div id="container2" data-parent="{{calcPercent}}"></div>
</template>
</code>```

JS

```<code>Template.Preset_settings.onRendered(function fabSettingOnRendered() {

    var ProgressBar = require('progressbar.js')
    var line = new ProgressBar.Line('#container2');

    var dataid = document.getElementById('container2');

    var bar = new ProgressBar.Circle(container2, {
        strokeWidth: 6,
        easing: 'easeInOut',
        color: '#FFEA82',
        trailColor: '#eee',
        trailWidth: 1,
        svgStyle: null
    });

    bar.animate(dataid.dataset.parent);
});

Template.Preset_settings.helpers({

    calcPercent: function() {
        const instance = Template.instance();
        var readyList = instance.state.get("readyList");
        return (readyList.length / 12);
    }

});
</code>```

答:
I'm no ProgressBar.js expert, but after reading through the API and playing around with it I don't see anywhere that states the progress bar uses any data attributes at all.

It seems you have 2 options when using this library.

Animate the progress bar using the .animate(progress, [options], [cb]) function which animates the progress bar from the previous value (starting at 0) to the progress value you provided.  Successive calls to .animate() will continue to move the progress bar forward (assuming you pass in incrementally larger progress values)

Use the .set(progress) method to manually set the progress of the progress bar, which causes the progress bar to advance to the way it will look at that progress value (without animation).

So in order to get this to work in Meteor, you must make successive calls to either of the above functions to incrementally progress your bar (currently you are calling .animate() once).

It looks like you might been trying to do that with your data-parent attribute approach, but at the end of the day, your current code is only ever calling .animate() once (remember the onRendered callback is only called once when the template is rendered).

Here is how I would do it.

```<code>Template.Preset_settings.onRendered(function fabSettingOnRendered() {
  // initialize your progress bar
  var ProgressBar = require('progressbar.js')
  var bar = new ProgressBar.Circle(container2, {
      strokeWidth: 6,
      easing: 'easeInOut',
      color: '#FFEA82',
      trailColor: '#eee',
      trailWidth: 1,
      svgStyle: null
  });

  // setup a reactive computation to update the progress bar
  // this will re-run everytime your reactive datasource is updated
  this.autorun(function() {
    var readyList = this.state.get("readyList");
    bar.animate(readyList.length / 12);
  });
});
</code>```

Basically, I am using .autorun() to animate the progress bar each time your reactive data source changes.  Note, I am assuming (based on your code) that you have a defined some reactive data source (e.g. ReactiveVar, ReactiveDict, or something else) called state in your template's onCreated callback.

You also won't have a need for your calcPercent helper and can remove it.

Body:
I am using the progressbarjs library with my Meteor application. I have a helper function which calculates the length of a list and returns a percentage number. My circular progress bar has a "data-parent" attribute which has a value generated by the helper function.

The value is valid and is changing as data is being processed so I know that the helper function is not the issue. I also noticed that if I go into inspect element and manually edit the data-parent attribute, the progress bar does not change value.

Could someone assist me in finding out why the progress bar does not change reactively?

HTML

 <template name="Preset_settings">

</template>

JS

Template.Preset_settings.onRendered(function fabSettingOnRendered() {

    var ProgressBar = require('progressbar.js')
    var line = new ProgressBar.Line('#container2');

    var dataid = document.getElementById('container2');

    var bar = new ProgressBar.Circle(container2, {
        strokeWidth: 6,
        easing: 'easeInOut',
        color: '#FFEA82',
        trailColor: '#eee',
        trailWidth: 1,
        svgStyle: null
    });

    bar.animate(dataid.dataset.parent);
});

Template.Preset_settings.helpers({

    calcPercent: function() {
        const instance = Template.instance();
        var readyList = instance.state.get("readyList");
        return (readyList.length / 12);
    }

});

Body:
I'm no ProgressBar.js expert, but after reading through the API and playing around with it I don't see anywhere that states the progress bar uses any data attributes at all.

It seems you have 2 options when using this library.

Animate the progress bar using the .animate(progress, [options], [cb]) function which animates the progress bar from the previous value (starting at 0) to the progress value you provided.  Successive calls to .animate() will continue to move the progress bar forward (assuming you pass in incrementally larger progress values)

Use the .set(progress) method to manually set the progress of the progress bar, which causes the progress bar to advance to the way it will look at that progress value (without animation).

So in order to get this to work in Meteor, you must make successive calls to either of the above functions to incrementally progress your bar (currently you are calling .animate() once).

It looks like you might been trying to do that with your data-parent attribute approach, but at the end of the day, your current code is only ever calling .animate() once (remember the onRendered callback is only called once when the template is rendered).

Here is how I would do it.

Template.Preset_settings.onRendered(function fabSettingOnRendered() {
  // initialize your progress bar
  var ProgressBar = require('progressbar.js')
  var bar = new ProgressBar.Circle(container2, {
      strokeWidth: 6,
      easing: 'easeInOut',
      color: '#FFEA82',
      trailColor: '#eee',
      trailWidth: 1,
      svgStyle: null
  });

  // setup a reactive computation to update the progress bar
  // this will re-run everytime your reactive datasource is updated
  this.autorun(function() {
    var readyList = this.state.get("readyList");
    bar.animate(readyList.length / 12);
  });
});

Basically, I am using .autorun() to animate the progress bar each time your reactive data source changes.  Note, I am assuming (based on your code) that you have a defined some reactive data source (e.g. ReactiveVar, ReactiveDict, or something else) called state in your template's onCreated callback.

You also won't have a need for your calcPercent helper and can remove it.


问:
Python: os.walk to specific directory and file
I have a file structure that looks like:

```<code>|num_1

|----|dir1

|--------|dir2

|------------|dcm

|----------------\file_1

|----------------\file_2

|----------------\file_n

|num_2

|----|dir1

|--------|dcm

|------------\file_1

|------------\file_n

|num_n
</code>```

I want to us os.walk (or something more appropriate?) to traverse the tree until it finds the directory "dcm". dcm can be at varying levels of the tree

This is what I have. Thanks!

```<code>import dicom
import re
import os

dcm = []
PATH = "C:\foo"

#find the directory we want to get to, save path
for path, dirs in os.walk(PATH):
    for dirname in dirs:
        fullpath = os.path.join(path,dirname)
        if "dcm" in dirname:
            #copied this first_file line - just want a fast and easy way to grab ONE file in the dcm directory
            #without reading any of the others (for time reasons)
            first_file = next((join(path, f) for f in os.listdir(path) if isfile(join(path, f))),"none")
            fullpath = os.path.join(fullpath,first_file)
            dcm.append(fullpath)
</code>```

答:
I went ahead with the "lazy" way and used listdir to read out all of the files under the dcm directory - decided that the resource cost wasn't too high.
That being said, I think that pulling out a single random file from a directory without reading all of those files is an interesting query that someone more Python oriented than I should answer!

For reference, my final solution was... do excuse the inefficiencies in iterator usage! I am new and needed a quick solution

```<code>for path, dirs, filename in os.walk(rootDir): #omit files, loop through later
    for dirname in dirs:
        fullpath = os.path.join(path,dirname)
        if "dcm" in dirname:
            dcm.append(fullpath)

final = []
uni = 0
final.append(dcm[0])
for i in range(len(dcm)):
    if len(os.listdir(dcm[i])) < 10:
        pass
    elif dcm[i][16:19] != final[uni][16:19]:
        final.append(dcm[i])
        uni += 1

tags = ((0x8, 0x70)),((0x8, 0x1090)), ((0x18, 0x1020))
values = []
printout = []
for p in range(len(final)):
    file = os.path.join(final[p],os.listdir(final[p])[0])
    ds = dicom.read_file(file)
    printout.append([final[p]])
    for k in range(len(tags)):
        printout.append([ds[tags[k]]])
</code>```

Body:
I have a file structure that looks like:

|num_1

|----|dir1

|--------|dir2

|------------|dcm

|----------------\file_1

|----------------\file_2

|----------------\file_n

|num_2

|----|dir1

|--------|dcm

|------------\file_1

|------------\file_n

|num_n

I want to us os.walk (or something more appropriate?) to traverse the tree until it finds the directory "dcm". dcm can be at varying levels of the tree

This is what I have. Thanks!

import dicom
import re
import os

dcm = []
PATH = "C:\foo"

#find the directory we want to get to, save path
for path, dirs in os.walk(PATH):
    for dirname in dirs:
        fullpath = os.path.join(path,dirname)
        if "dcm" in dirname:
            #copied this first_file line - just want a fast and easy way to grab ONE file in the dcm directory
            #without reading any of the others (for time reasons)
            first_file = next((join(path, f) for f in os.listdir(path) if isfile(join(path, f))),"none")
            fullpath = os.path.join(fullpath,first_file)
            dcm.append(fullpath)

Body:
I went ahead with the "lazy" way and used listdir to read out all of the files under the dcm directory - decided that the resource cost wasn't too high.
That being said, I think that pulling out a single random file from a directory without reading all of those files is an interesting query that someone more Python oriented than I should answer!

For reference, my final solution was... do excuse the inefficiencies in iterator usage! I am new and needed a quick solution

for path, dirs, filename in os.walk(rootDir): #omit files, loop through later
    for dirname in dirs:
        fullpath = os.path.join(path,dirname)
        if "dcm" in dirname:
            dcm.append(fullpath)

final = []
uni = 0
final.append(dcm[0])
for i in range(len(dcm)):
    if len(os.listdir(dcm[i])) < 10:
        pass
    elif dcm[i][16:19] != final[uni][16:19]:
        final.append(dcm[i])
        uni += 1

tags = ((0x8, 0x70)),((0x8, 0x1090)), ((0x18, 0x1020))
values = []
printout = []
for p in range(len(final)):
    file = os.path.join(final[p],os.listdir(final[p])[0])
    ds = dicom.read_file(file)
    printout.append([final[p]])
    for k in range(len(tags)):
        printout.append([ds[tags[k]]])


问:
Generate list files with CMake
I hope this is a simple question and I'm just missing something fundamental.

I'm trying to emulate a binary build manager for an embedded Cortex-M0 target using a CMake project. I'm having some trouble figuring out how to generate list files for each dependency of my executable target.

The current build system, when building a file called main.c passes -Wa,-alh=.\CortexM0\ARM_GCC_493\Debug/main.lst as an argument to gcc. I can't figure out how to get CMake to use the current filename without the extension to save the file.

I've looked at the get_filename_component command, but it appears only to get the filename of the output:

```<code>add_executable(TestExe main.c)
get_filename_component(curr_name TestExe NAME_WM)
message(${curr_name})
</code>```

As expected, this prints TestExe instead of the hoped for main

Is there a simple variable I'm overlooking that I could put in my toolchain file's CMAKE_C_FLAGS like -Wa,-alh=${CURR_SOURCE}.lst? Or some other method that I'm not seeing?

System info:

Windows 10

Msys shell

CMake 3.7.2

arm-none-eabi-gcc v4.9.3

答:
You can use Expansion Rules and extend CMAKE_C_COMPILE_OBJECT:

```<code>set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT} -Wa,-alh=<OBJECT>.lst")
</code>```

But there is unfortunately

no Expansion Rule that does give the current source file without path and extension

so you will get in the above example main.c.o.lst as an output name

Footnote: In CMake generated makefile projects, if you just need the assembly file can just do make main.s or for the pre-processed file make main.i.

Title: Generate list files with CMake

Body:
I hope this is a simple question and I'm just missing something fundamental.

I'm trying to emulate a binary build manager for an embedded Cortex-M0 target using a CMake project. I'm having some trouble figuring out how to generate list files for each dependency of my executable target.

The current build system, when building a file called main.c passes -Wa,-alh=.\CortexM0\ARM_GCC_493\Debug/main.lst as an argument to gcc. I can't figure out how to get CMake to use the current filename without the extension to save the file.

I've looked at the get_filename_component command, but it appears only to get the filename of the output:

add_executable(TestExe main.c)
get_filename_component(curr_name TestExe NAME_WM)
message(${curr_name})

As expected, this prints TestExe instead of the hoped for main

Is there a simple variable I'm overlooking that I could put in my toolchain file's CMAKE_C_FLAGS like -Wa,-alh=${CURR_SOURCE}.lst? Or some other method that I'm not seeing?

System info:

Windows 10

Msys shell

CMake 3.7.2

arm-none-eabi-gcc v4.9.3

Body:
You can use Expansion Rules and extend CMAKE_C_COMPILE_OBJECT:

set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT} -Wa,-alh=<OBJECT>.lst")

But there is unfortunately

no Expansion Rule that does give the current source file without path and extension

so you will get in the above example main.c.o.lst as an output name

Footnote: In CMake generated makefile projects, if you just need the assembly file can just do make main.s or for the pre-processed file make main.i.


问:
Change CakePHP database configuration globally
I have two databases used for my CakePHP project, respectively named project and project_dev. The database project is used in production and because since the version 3, the CakePHP remove the table prefix option, I choose to use two separated databases.

Extract from my /config/app.php :

```<code>'Datasources' => [
    'dev' => [...],
    'prod' => [...]
]
</code>```

The problem is that I need to use the dev database... for development; so I need to tell Cake to use the dev configuration by default during development.

To do that, I tried to create an AppTable.php, a class inherited by all my *Table.php files, with the following function :

```<code>/**
 * Define the connection name based on the debug config value
 * @return string the connection name
 */
public static function defaultConnectionName(): string {
    return Configure::read('debug') ? 'dev' : 'prod';
}
</code>```

The problem for a few tasks, such as unit tests, Cake is trying to use the default database config.

I'm afraid that my AppTable.php hack is not efficient and I think that tweaking the configuration on load directly in app.php like this :

```<code>$config = [
    [...],
    'Datasources' => [
        'dev' => [...],
        'prod' => [...]
    ],
    'UseDatasourcesConfig' => 'dev',
    [...],
];

$config['Datasources']['default'] = $config['Datasources']['UseDatasourcesConfig'];

return $config;
</code>```

...sounds, like a hack too.

Is this second method viable? Or does a more formal/proper way to set the database config globally exist?

答:
Providing configuration depending on the environment is a pretty common task, and there's quite a few other ways to handle this.

Environment variables

In case the environment allows it, you could use environment variables. You could easily provide DB configuration via the DATABASE_URL variable in form of a DSN connection string like

mysql://user:pass@localhost/production?encoding=utf8&timezone=UTC&cacheMetadata=true
```
<p><strong>Cookbook > Configuration > Environment Variables</strong></p>
<h2>Additional config files</h2>
<p>Another option is to load separate/additional config files based on the current environment, so that you can deploy only those files that are actually required for a specific environment.</p>
```Configure::load('app', 'default', false);
// $enviroment needs to be validated /sanitzied in order to
// avoid loading arbitrary files from the config directory
Configure::load($enviroment, 'default', true);
```
<p><strong>Cookbook > Configuration > Loading Additional Configuration Files</strong></p>
<h2>Connection aliasing</h2>
<p>And there's also connection aliasing, CakePHP does that automatically in the test environment. Say you have a <code>default</code> and a <code>production</code> confiuration, you could then alias the <code>production</code> connection as <code>default</code> in your production environment, so that everywhere your code tries to use the <code>default</code> connection, it will actually use the <code>production</code> one.</p>
```\Cake\DataSource\ConnectionManager::alias('production', 'default');
```

API > \Cake\DataSource\ConnectionManager::alias()

Body:
I have two databases used for my CakePHP project, respectively named project and project_dev. The database project is used in production and because since the version 3, the CakePHP remove the table prefix option, I choose to use two separated databases.

Extract from my /config/app.php :

'Datasources' => [
    'dev' => [...],
    'prod' => [...]
]

The problem is that I need to use the dev database... for development; so I need to tell Cake to use the dev configuration by default during development.

To do that, I tried to create an AppTable.php, a class inherited by all my *Table.php files, with the following function :

/**
 * Define the connection name based on the debug config value
 * @return string the connection name
 */
public static function defaultConnectionName(): string {
    return Configure::read('debug') ? 'dev' : 'prod';
}

The problem for a few tasks, such as unit tests, Cake is trying to use the default database config.

I'm afraid that my AppTable.php hack is not efficient and I think that tweaking the configuration on load directly in app.php like this :

$config = [
    [...],
    'Datasources' => [
        'dev' => [...],
        'prod' => [...]
    ],
    'UseDatasourcesConfig' => 'dev',
    [...],
];

$config['Datasources']['default'] = $config['Datasources']['UseDatasourcesConfig'];

return $config;

...sounds, like a hack too.

Is this second method viable? Or does a more formal/proper way to set the database config globally exist?

Body:
Providing configuration depending on the environment is a pretty common task, and there's quite a few other ways to handle this.

Environment variables

In case the environment allows it, you could use environment variables. You could easily provide DB configuration via the DATABASE_URL variable in form of a DSN connection string like

mysql://user:pass@localhost/production?encoding=utf8&timezone=UTC&cacheMetadata=true

Cookbook > Configuration > Environment Variables

Additional config files

Another option is to load separate/additional config files based on the current environment, so that you can deploy only those files that are actually required for a specific environment.

Configure::load('app', 'default', false);
// $enviroment needs to be validated /sanitzied in order to
// avoid loading arbitrary files from the config directory
Configure::load($enviroment, 'default', true);

Cookbook > Configuration > Loading Additional Configuration Files

Connection aliasing

And there's also connection aliasing, CakePHP does that automatically in the test environment. Say you have a default and a production confiuration, you could then alias the production connection as default in your production environment, so that everywhere your code tries to use the default connection, it will actually use the production one.

\Cake\DataSource\ConnectionManager::alias('production', 'default');

API > \Cake\DataSource\ConnectionManager::alias()


问:
Parsing error on app.yaml with AppEngine Maven plugin
I am trying to run  a local (developer machine) Java AppEngine Standard Env server using the new Maven plugin (com.google.cloud.tools:appengine-maven-plugin:1.2.1) with Google Cloud SDK [148.0.1]. The command is mvn appengine:run -Dmaven.test.skip=true

When I do that, I get TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'.

```<code>  --- appengine-maven-plugin:1.2.1:run (default-cli) @ tradeos ---
Mar 28, 2017 2:18:45 PM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: C:\python27_x64\python.exe c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\bin\dev_appserver.py F:\freightos-maven\tradeos\target\tradeos-0.0.1-SNAPSHOT --dev_appserver_log_level=debug
 GCLOUD: Traceback (most recent call last):
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 101, in <module>
 GCLOUD:     _run_file(__file__, globals())
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 97, in _run_file
 GCLOUD:     execfile(_PATHS.script_file(script_name), globals_)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1041, in <module>
 GCLOUD:     main()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1037, in main
 GCLOUD:     dev_server.stop()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 845, in stop
 GCLOUD:     metrics.GetMetricsLogger().Stop()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\metrics.py", line 117, in Stop
 GCLOUD:     total_run_time = int((Now() - self._start_time).total_seconds())
 GCLOUD: TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'
</code>```

The SDK code shows  that this happens when trying to stop the metrics module after it failed to initialize. So, I edited the SDK to give hard-coded values to let the dev_appserver continue and so expose the actual error.

That's when I started getting a parsing error while reading appengine-web.xml. See below.

```<code><<< appengine-maven-plugin:1.2.1:run (default-cli) < package @ tradeos <<<
 --- appengine-maven-plugin:1.2.1:run (default-cli) @ tradeos ---
Mar 28, 2017 12:10:34 PM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: C:\python27_x64\python.exe c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\bin\dev_appserver.py F:\freightos-maven\tradeos\target\tradeos-0.0.1-SNAPSHOT --dev_appserver_log_level=debug
 GCLOUD: Traceback (most recent call last):
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 101, in <module>
 GCLOUD:     _run_file(__file__, globals())
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 97, in _run_file
 GCLOUD:     execfile(_PATHS.script_file(script_name), globals_)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1041, in <module>
 GCLOUD:     main()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1029, in main
 GCLOUD:     dev_server.start(options)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 754, in start
 GCLOUD:     env_variables=parsed_env_variables)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 851, in __init__
 GCLOUD:     env_variables)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 131, in __init__
 GCLOUD:     self._config_path)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 438, in _parse_configuration
 GCLOUD:     config, files = self._parse_java_configuration(configuration_path)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 485, in _parse_java_configuration
 GCLOUD:     config = appinfo.LoadSingleAppInfo(app_yaml_str)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\appinfo.py", line 2369, in LoadSingleAppInfo
 GCLOUD:     listener.Parse(app_info)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 227, in Parse
 GCLOUD:     self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 173, in _HandleEvents
 GCLOUD:     for event in events:
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 213, in _GenerateEventParameters
 GCLOUD:     raise yaml_errors.EventListenerYAMLError(e)
 GCLOUD: google.appengine.api.yaml_errors.EventListenerYAMLError: while scanning for the next token
 GCLOUD: found character '\t' that cannot start any token
 GCLOUD:   in "<string>", line 11929, column 1:
</code>```

What I tried:

Older versions of the Maven plugin (1.0.0). same results

I downloaded the sample app guestbook and tried running it, it worked
fine. My app has the same structure as the sample.

Copied the appengine-web.xml from the sample into my project, still
the same errors.

The server is working fine with the old Maven plugin delivered with the Java SDK com.google.appengine:com.google.appengine:1.9.50

pom.xml follows:

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion><!-- REQUIRED -->

    <parent>
        <groupId>com.tradeos</groupId>
        <artifactId>freightos-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../freightos-parent/pom.xml</relativePath>
    </parent>
    <artifactId>tradeos</artifactId>
    <packaging>war</packaging><!-- REQUIRED -->

    <properties>
        <appengine.maven.plugin.version>1.2.1</appengine.maven.plugin.version>
        <gcloud.plugin.version>2.0.9.133.v201611104</gcloud.plugin.version>
        <failOnMissingWebXml>false</failOnMissingWebXml><!-- REQUIRED -->
    </properties>

    <prerequisites><!-- Optional, but suggested -->
        <maven>3.3.9</maven><!-- Recommended minimum maven version -->
    </prerequisites>

    <build>
        <!-- for hot reload of the web application-->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/java/UnitTests.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!-- Used to add additional sources -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>lib/gwt</source>
                                <source>lib/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <!--Override compiler and java version -->
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <compilerId>jdt</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <!-- Use java jdt compiler instead of maven java compiler(javac) -->
                        <groupId>org.eclipse.tycho</groupId>
                        <artifactId>tycho-compiler-jdt</artifactId>
                        <version>${jdt.compiler.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <!-- GWT maven plugin to do GWT compile -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwtVersion}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceLevel>1.7</sourceLevel>
                    <style>OBF</style>
                    <localWorkers>3</localWorkers>
                    <extraJvmArgs>-Xmx3072m</extraJvmArgs>
                    <modules>
                        <module>com.tradeos.Tradeos</module>
                    </modules>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <webResources>
                        <resource>
                            <directory>${project.basedir}/lib/libs</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>easypost-java-2.0.9.jar</include>
                                <include>gwt-servlet-deps.jar</include>
                                <include>org.moxieapps.gwt.highcharts-1.5.0.jar</include>
                                <include>poi-3.14-20160629.jar</include>
                                <include>gwt-visualization.jar</include>
                                <include>pdfcrowd.jar</include>
                                <include>ip2c.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.maven.plugin.version}</version>
                 <configuration><!--
                    <jvmFlags>-XX:+UseG1GC -Xmx2G -XX:MaxPermSize=1G</jvmFlags>
                    <maxModuleInstances>1</maxModuleInstances>
                    <port>8888</port>
                    <startSuccessTimeout>0</startSuccessTimeout> -->
                    <devAppserverLogLevel>debug</devAppserverLogLevel>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.1.v20170120</version>
                <configuration>
                    <httpConnector>
                        <host>localhost</host>
                        <port>8888</port>
                    </httpConnector>
                    <webAppSourceDirectory>${project.build.directory}/${project.artifactId}-${project.version}</webAppSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-mockito-release-full</artifactId>
            <version>1.6.4</version>
            <classifier>full</classifier>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.tradeos</groupId>
            <artifactId>pdfcrowd</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/pdfcrowd.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.tradeos</groupId>
            <artifactId>gails</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.3.2</version>
        </dependency>

        <dependency>
            <groupId>com.allen-sauer.gwt.dnd</groupId>
            <artifactId>gwt-dnd</artifactId>
            <version>3.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.1</version>
        </dependency>

        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.20.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-cloudmonitoring</artifactId>
            <version>v2beta2-rev42-1.21.0</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>

        <!-- Add itextpdf java jar -->
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava-gwt</artifactId>
            <version>18.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/guava-gwt-18.0.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>net.sf.advanced-gwt</groupId>
            <artifactId>advanced-components</artifactId>
            <version>2.0.7</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/advanced-components-2.0.7.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>org.moxieapps.gwt</groupId>
            <artifactId>org.moxieapps.gwt.highcharts</artifactId>
            <version>1.5.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/org.moxieapps.gwt.highcharts-1.5.0.jar</systemPath>
        </dependency>

        <!-- POI library version 3.14 modified to be compatible with appengine -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>poi-3.14-20160629</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/poi-3.14-20160629.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>easypost</groupId>
            <artifactId>easypost-java</artifactId>
            <version>2.0.9</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/easypost-java-2.0.9.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>gwt.servlet.deps</groupId>
            <artifactId>gwt-servlet-deps</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/gwt-servlet-deps.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-maps3</artifactId>
            <version>0.1a</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/gwt-maps3-0.1a.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.19.1</version>
        </dependency>

        <dependency>
            <groupId>net.spy</groupId>
            <artifactId>spymemcached</artifactId>
            <version>2.11.6</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.19.1</version>
        </dependency>

    </dependencies>
</project>
</code>```

答:
I am also having the same error with google app engine using cmd,
for this error is itself in the app.yaml file only.

you could either check for any changes in leading slashes in url

for me removing application: application_name did the job...although that may

be required if you are not deploying app locally

I am too looking forward for an alternative solution.

Body:
I am trying to run  a local (developer machine) Java AppEngine Standard Env server using the new Maven plugin (com.google.cloud.tools:appengine-maven-plugin:1.2.1) with Google Cloud SDK [148.0.1]. The command is mvn appengine:run -Dmaven.test.skip=true

When I do that, I get TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'.

  --- appengine-maven-plugin:1.2.1:run (default-cli) @ tradeos ---
Mar 28, 2017 2:18:45 PM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: C:\python27_x64\python.exe c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\bin\dev_appserver.py F:\freightos-maven\tradeos\target\tradeos-0.0.1-SNAPSHOT --dev_appserver_log_level=debug
 GCLOUD: Traceback (most recent call last):
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 101, in <module>
 GCLOUD:     _run_file(__file__, globals())
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 97, in _run_file
 GCLOUD:     execfile(_PATHS.script_file(script_name), globals_)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1041, in <module>
 GCLOUD:     main()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1037, in main
 GCLOUD:     dev_server.stop()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 845, in stop
 GCLOUD:     metrics.GetMetricsLogger().Stop()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\metrics.py", line 117, in Stop
 GCLOUD:     total_run_time = int((Now() - self._start_time).total_seconds())
 GCLOUD: TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'

The SDK code shows  that this happens when trying to stop the metrics module after it failed to initialize. So, I edited the SDK to give hard-coded values to let the dev_appserver continue and so expose the actual error.

That's when I started getting a parsing error while reading appengine-web.xml. See below.

<<< appengine-maven-plugin:1.2.1:run (default-cli) < package @ tradeos <<<
 --- appengine-maven-plugin:1.2.1:run (default-cli) @ tradeos ---
Mar 28, 2017 12:10:34 PM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: C:\python27_x64\python.exe c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\bin\dev_appserver.py F:\freightos-maven\tradeos\target\tradeos-0.0.1-SNAPSHOT --dev_appserver_log_level=debug
 GCLOUD: Traceback (most recent call last):
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 101, in <module>
 GCLOUD:     _run_file(__file__, globals())
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\dev_appserver.py", line 97, in _run_file
 GCLOUD:     execfile(_PATHS.script_file(script_name), globals_)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1041, in <module>
 GCLOUD:     main()
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 1029, in main
 GCLOUD:     dev_server.start(options)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 754, in start
 GCLOUD:     env_variables=parsed_env_variables)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 851, in __init__
 GCLOUD:     env_variables)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 131, in __init__
 GCLOUD:     self._config_path)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 438, in _parse_configuration
 GCLOUD:     config, files = self._parse_java_configuration(configuration_path)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 485, in _parse_java_configuration
 GCLOUD:     config = appinfo.LoadSingleAppInfo(app_yaml_str)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\appinfo.py", line 2369, in LoadSingleAppInfo
 GCLOUD:     listener.Parse(app_info)
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 227, in Parse
 GCLOUD:     self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 173, in _HandleEvents
 GCLOUD:     for event in events:
 GCLOUD:   File "c:\users\user\appdata\local\google\cloud sdk\google-cloud-sdk\platform\google_appengine\google\appengine\api\yaml_listener.py", line 213, in _GenerateEventParameters
 GCLOUD:     raise yaml_errors.EventListenerYAMLError(e)
 GCLOUD: google.appengine.api.yaml_errors.EventListenerYAMLError: while scanning for the next token
 GCLOUD: found character '\t' that cannot start any token
 GCLOUD:   in "<string>", line 11929, column 1:

What I tried:

Older versions of the Maven plugin (1.0.0). same results

I downloaded the sample app guestbook and tried running it, it worked
fine. My app has the same structure as the sample.

Copied the appengine-web.xml from the sample into my project, still
the same errors.

The server is working fine with the old Maven plugin delivered with the Java SDK com.google.appengine:com.google.appengine:1.9.50

pom.xml follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.tradeos</groupId>
        <artifactId>freightos-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../freightos-parent/pom.xml</relativePath>
    </parent>
    <artifactId>tradeos</artifactId>
    <packaging>war</packaging>

    <properties>
        <appengine.maven.plugin.version>1.2.1</appengine.maven.plugin.version>
        <gcloud.plugin.version>2.0.9.133.v201611104</gcloud.plugin.version>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <prerequisites>
        <maven>3.3.9</maven>
    </prerequisites>

    <build>

        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/java/UnitTests.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>lib/gwt</source>
                                <source>lib/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>

                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <compilerId>jdt</compilerId>
                </configuration>
                <dependencies>
                    <dependency>

                        <groupId>org.eclipse.tycho</groupId>
                        <artifactId>tycho-compiler-jdt</artifactId>
                        <version>${jdt.compiler.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwtVersion}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sourceLevel>1.7</sourceLevel>

                    <localWorkers>3</localWorkers>
                    <extraJvmArgs>-Xmx3072m</extraJvmArgs>
                    <modules>
                        <module>com.tradeos.Tradeos</module>
                    </modules>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <webResources>
                        <resource>
                            <directory>${project.basedir}/lib/libs</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>easypost-java-2.0.9.jar</include>
                                <include>gwt-servlet-deps.jar</include>
                                <include>org.moxieapps.gwt.highcharts-1.5.0.jar</include>
                                <include>poi-3.14-20160629.jar</include>
                                <include>gwt-visualization.jar</include>
                                <include>pdfcrowd.jar</include>
                                <include>ip2c.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.maven.plugin.version}</version>
                 <configuration>
                    <devAppserverLogLevel>debug</devAppserverLogLevel>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.1.v20170120</version>
                <configuration>
                    <httpConnector>
                        <host>localhost</host>
                        <port>8888</port>
                    </httpConnector>
                    <webAppSourceDirectory>${project.build.directory}/${project.artifactId}-${project.version}</webAppSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-mockito-release-full</artifactId>
            <version>1.6.4</version>
            <classifier>full</classifier>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.tradeos</groupId>
            <artifactId>pdfcrowd</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/pdfcrowd.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.tradeos</groupId>
            <artifactId>gails</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.3.2</version>
        </dependency>

        <dependency>
            <groupId>com.allen-sauer.gwt.dnd</groupId>
            <artifactId>gwt-dnd</artifactId>
            <version>3.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.1</version>
        </dependency>

        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.20.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-cloudmonitoring</artifactId>
            <version>v2beta2-rev42-1.21.0</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava-gwt</artifactId>
            <version>18.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/guava-gwt-18.0.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>net.sf.advanced-gwt</groupId>
            <artifactId>advanced-components</artifactId>
            <version>2.0.7</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/advanced-components-2.0.7.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>org.moxieapps.gwt</groupId>
            <artifactId>org.moxieapps.gwt.highcharts</artifactId>
            <version>1.5.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/org.moxieapps.gwt.highcharts-1.5.0.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>poi-3.14-20160629</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/poi-3.14-20160629.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>easypost</groupId>
            <artifactId>easypost-java</artifactId>
            <version>2.0.9</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/easypost-java-2.0.9.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>gwt.servlet.deps</groupId>
            <artifactId>gwt-servlet-deps</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/libs/gwt-servlet-deps.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-maps3</artifactId>
            <version>0.1a</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/gwt/gwt-maps3-0.1a.jar</systemPath>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.19.1</version>
        </dependency>

        <dependency>
            <groupId>net.spy</groupId>
            <artifactId>spymemcached</artifactId>
            <version>2.11.6</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.19.1</version>
        </dependency>

    </dependencies>
</project>


问:
Error importing SQL Server function in Entity Framework ADO.NET Entity Data Model
My project is based on ADO.NET Entity Data Model and I use Entity Framework 6.0.

Well, I received this error when I import function in my project:

Error 6046: Unable to generate function import return type of the store function 'fn_PWDCOMPARE'. The store function will be ignored and the function import will not be generated.

I don't get an error if I import a procedure.

The function is:

```<code>CREATE FUNCTION fn_PWDCOMPARE (@pwd NVARCHAR(MAX),@pwdhash NVARCHAR(MAX))
RETURNS BIT
BEGIN
  RETURN PWDCOMPARE(@pwd, @pwdhash)
END
</code>```

答:
EF 6.1.3 still doesn't generate code for Scalar Functions. That said, you can extend the your DbContext class and add your own implementation to your function. Afterwards, you can call your function as any other object inside your EF model.

Create a file containing a [partial class] on the same [namespace] as your DB model, and with your same models context name. And add this code:

```<code>public partial class YourDBContext : DbContext
{
    public System.Data.Entity.Core.Objects.ObjectContext AsObjectContext()
    {
        return (this as System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext;
    }

    [DbFunction("YourDBModel.Store", "fn_PWDCOMPARE")]
    public bool fn_PWDCOMPARE(string pwd, string pwdhash)
    {
        var paramList = new ObjectParameter[]
        {
            new ObjectParameter("pwd", pwd),
            new ObjectParameter("pwdhash", pwdhash)
        };

        return this.AsObjectContext().CreateQuery<bool>("YourDBModel.Store.fn_PWDCOMPARE", paramList).Execute(MergeOption.NoTracking).FirstOrDefault();
    }
</code>```

Then you just call this new function from your code:

bool retVal = YourDBContext.fn_PWDCOMPARE(pass, hash);

Body:
My project is based on ADO.NET Entity Data Model and I use Entity Framework 6.0.

Well, I received this error when I import function in my project:

Error 6046: Unable to generate function import return type of the store function 'fn_PWDCOMPARE'. The store function will be ignored and the function import will not be generated.

I don't get an error if I import a procedure.

The function is:

CREATE FUNCTION fn_PWDCOMPARE (@pwd NVARCHAR(MAX),@pwdhash NVARCHAR(MAX))
RETURNS BIT
BEGIN
  RETURN PWDCOMPARE(@pwd, @pwdhash)
END

Body:
EF 6.1.3 still doesn't generate code for Scalar Functions. That said, you can extend the your DbContext class and add your own implementation to your function. Afterwards, you can call your function as any other object inside your EF model.

Create a file containing a [partial class] on the same [namespace] as your DB model, and with your same models context name. And add this code:

public partial class YourDBContext : DbContext
{
    public System.Data.Entity.Core.Objects.ObjectContext AsObjectContext()
    {
        return (this as System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext;
    }

    [DbFunction("YourDBModel.Store", "fn_PWDCOMPARE")]
    public bool fn_PWDCOMPARE(string pwd, string pwdhash)
    {
        var paramList = new ObjectParameter[]
        {
            new ObjectParameter("pwd", pwd),
            new ObjectParameter("pwdhash", pwdhash)
        };

        return this.AsObjectContext().CreateQuery<bool>("YourDBModel.Store.fn_PWDCOMPARE", paramList).Execute(MergeOption.NoTracking).FirstOrDefault();
    }

Then you just call this new function from your code:

bool retVal = YourDBContext.fn_PWDCOMPARE(pass, hash);


问:
Android Studio: Creating user types
I'm writing to ask for some advice for my application. I've only ever created an application whereby a user registers and logs in.

However, I'm trying to create an app where there are two user types: landlord and tenant. The only way I can think to do this is to create two different databases and with two different login screens to allow the user to access the correct activity. I can't help but feel this way of doing it is a long and arduous one.

I was wondering if anyone could point me into a better direction in terms of logging in with unique user types?

Edits
Figure 1

```<code>public boolean validateUser(String username, String password){
    Cursor c = getReadableDatabase().rawQuery(
            "SELECT * FROM " + TABLE_USERS + " WHERE "
                    + KEY_USERS + "='" + username +"'AND "+KEY_PASS+"='"+password+"'" ,  null);
    if (c.getCount() > 0) {
        return true;
    }
    else{return false;}

}
</code>```

答:
Your question is a little bit "general" or in other words I don't have a good idea of what exactly is your app supposed to do. Anyways. I would suggest the following:
You can create a field (let's call this field "TYPE") in your database that will hold a value (e.g true/false or whatever serves your purpose) that will differentiate between the 2 types of users. In your login activity you will access the user and check the "TYPE" field and according to the value in the field you will start the appropriate activity.

For Example:

User logs in ->

If value == true -> Start tenant activity

Else ->
Start landlord activity

Title: Android Studio: Creating user types

Body:
I'm writing to ask for some advice for my application. I've only ever created an application whereby a user registers and logs in.

However, I'm trying to create an app where there are two user types: landlord and tenant. The only way I can think to do this is to create two different databases and with two different login screens to allow the user to access the correct activity. I can't help but feel this way of doing it is a long and arduous one.

I was wondering if anyone could point me into a better direction in terms of logging in with unique user types?

Edits
Figure 1

public boolean validateUser(String username, String password){
    Cursor c = getReadableDatabase().rawQuery(
            "SELECT * FROM " + TABLE_USERS + " WHERE "
                    + KEY_USERS + "='" + username +"'AND "+KEY_PASS+"='"+password+"'" ,  null);
    if (c.getCount() > 0) {
        return true;
    }
    else{return false;}

}