问:
How to run maven web application with jetty server in eclipse
I have to created maven project to run with jetty server this project is comfortably running using command line the same project if going to run in eclipse project getting build failure whats the problem

Error

```<code>------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.910 s
[INFO] Finished at: 2017-07-06T15:58:41+05:30
[INFO] Final Memory: 11M/204M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\abc\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
</code>```

pom.xml

```<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.infonex.edunex</groupId>
    <artifactId>school-managment-app</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>school-management</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <servlet.port>8080</servlet.port>
        <jersey.version>2.25.1</jersey.version>
        <struts2.version>2.3.14.3</struts2.version>
        <spring.version>3.1.0.RELEASE</spring.version>
        <hibernate.version>4.1.0.Final</hibernate.version>
        <sl4j.version>1.7.2</sl4j.version>
        <hsqldb.version>2.2.9</hsqldb.version>
        <mysql.connector.java.version>5.1.25</mysql.connector.java.version>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
        <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>

        <repository>
            <id>wso2</id>
            <url>http://dist.wso2.org/maven2</url>
        </repository>
    </repositories>

    <dependencies>
        <!-- other dependencies-->

        <dependency>
            <groupId>org.owasp.esapi</groupId>
            <artifactId>esapi</artifactId>
            <version>2.1.0.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/captcha.simplecaptcha/simplecaptcha -->
        <dependency>
            <groupId>captcha.simplecaptcha</groupId>
            <artifactId>simplecaptcha</artifactId>
            <version>1.2.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.11</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-excelant -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-excelant</artifactId>
            <version>3.11</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.jfree/jfreechart -->
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.19</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.5.5</version>
        </dependency>

        <!-- end other dependencies -->

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-dojo-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-embeddedjsp-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-jfreechart-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-tiles-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.struts.xwork/xwork-core -->
        <dependency>
            <groupId>org.apache.struts.xwork</groupId>
            <artifactId>xwork-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

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

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.24.1</version>
        </dependency>

        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Struts 2 + Spring 3 need this jar, ContextLoaderListener -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Struts 2 + Spring integration plugins -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.3.4</version>
        </dependency>

        <!-- Mockito -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>

        <!-- Hibernate -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.17.1-GA</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.connector.java.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <!-- h2 database -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.172</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>javax.servlet</artifactId>
            <version>3.0.0.v201112011016</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>javax.mail.glassfish</artifactId>
            <version>1.4.1.v201005082020</version>
        </dependency>

        <!-- Jersey core Servlet 2.x implementation -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Jersey JSON Jackson (2.x) entity providers support module -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.8</version>
                    <configuration>
                        <additionalClasspathElements>
                            <additionalClasspathElement>test/resources</additionalClasspathElement>
                        </additionalClasspathElements>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.8</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>1.4.2</version>
                    <configuration>
                        <configuration>
                            <properties>
                                <cargo.servlet.port>${servlet.port}</cargo.servlet.port>
                            </properties>
                        </configuration>
                        <deployables>
                            <!--
                              The project's artifact is automatically deployed if no deployable
                              is defined. However, we define it here so that we can specify the
                              context (we don't want the version to be included in the context).
                              -->
                            <deployable>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>${project.artifactId}</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sql-maven-plugin</artifactId>

                    <dependencies>
                        <!-- specify the dependent jdbc driver here -->
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>${mysql.connector.java.version}</version>
                        </dependency>
                    </dependencies>

                    <configuration>
                        <driver>org.gjt.mm.mysql.Driver</driver>
                        <url>jdbc:mysql://localhost/cookbook</url>
                        <username>root</username>
                        <password>root</password>
                        <srcFiles>
                          <srcFile>src/test/resources/schema.sql</srcFile>
                          <srcFile>src/test/resources/test-data.sql</srcFile>
                        </srcFiles>
                        <!--all executions are ignored if -Dmaven.test.skip=true-->
                        <skip>${maven.test.skip}</skip>

                    </configuration>

                    <executions>

                        <!--  It creates integration test data before running the tests -->
                        <execution>
                            <id>create-integration-test-data</id>
                            <phase>process-test-resources</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <orderFile>ascending</orderFile>
                                <fileset>
                                    <basedir>/</basedir>
                                    <includes>
                                        <include>schema.sql</include>
                                        <include>test-data.sql</include>
                                    </includes>
                                </fileset>
                            </configuration>
                        </execution>
                    </executions>

                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <!-- <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.2.v20120308</version> -->
                <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.4.6-SNAPSHOT</version>
                <configuration>
                    <jettyXml>src/main/resources/jetty/jetty.xml</jettyXml>
                    <stopKey/>
                    <stopPort/>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>perform-integration</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <systemProperties>
                                <property>
                                    <name>servlet.port</name>
                                    <value>${servlet.port}</value>
                                </property>
                            </systemProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify-integration</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-cargo</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-cargo</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
</code>```

答:
You can run the following command from the same folder as your pom.xml file

mvn jetty:run

This starts Jetty and serves up your project on http://localhost:8080/.

Jetty will continue to run until you stop it. While it runs it periodically scans for changes to your project files If you save changes and recompile your class files, Jetty redeploys your webapp, and you can instantly test the changes that were just made.

Body:
I have to created maven project to run with jetty server this project is comfortably running using command line the same project if going to run in eclipse project getting build failure whats the problem

Error

------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.910 s
[INFO] Finished at: 2017-07-06T15:58:41+05:30
[INFO] Final Memory: 11M/204M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\abc\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

pom.xml

<?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.infonex.edunex</groupId>
    <artifactId>school-managment-app</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>school-management</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <servlet.port>8080</servlet.port>
        <jersey.version>2.25.1</jersey.version>
        <struts2.version>2.3.14.3</struts2.version>
        <spring.version>3.1.0.RELEASE</spring.version>
        <hibernate.version>4.1.0.Final</hibernate.version>
        <sl4j.version>1.7.2</sl4j.version>
        <hsqldb.version>2.2.9</hsqldb.version>
        <mysql.connector.java.version>5.1.25</mysql.connector.java.version>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
        <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>

        <repository>
            <id>wso2</id>
            <url>http://dist.wso2.org/maven2</url>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>org.owasp.esapi</groupId>
            <artifactId>esapi</artifactId>
            <version>2.1.0.1</version>
        </dependency>

        <dependency>
            <groupId>captcha.simplecaptcha</groupId>
            <artifactId>simplecaptcha</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-excelant</artifactId>
            <version>3.11</version>
        </dependency>

        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.19</version>
        </dependency>

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

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-dojo-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-embeddedjsp-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-jfreechart-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-tiles-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts.xwork</groupId>
            <artifactId>xwork-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

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

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.24.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.3.4</version>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.17.1-GA</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.connector.java.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.172</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>javax.servlet</artifactId>
            <version>3.0.0.v201112011016</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty.orbit</groupId>
            <artifactId>javax.mail.glassfish</artifactId>
            <version>1.4.1.v201005082020</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.8</version>
                    <configuration>
                        <additionalClasspathElements>
                            <additionalClasspathElement>test/resources</additionalClasspathElement>
                        </additionalClasspathElements>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.8</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>1.4.2</version>
                    <configuration>
                        <configuration>
                            <properties>
                                <cargo.servlet.port>${servlet.port}</cargo.servlet.port>
                            </properties>
                        </configuration>
                        <deployables>

                            <deployable>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <type>war</type>
                                <properties>
                                    <context>${project.artifactId}</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sql-maven-plugin</artifactId>

                    <dependencies>

                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>${mysql.connector.java.version}</version>
                        </dependency>
                    </dependencies>

                    <configuration>
                        <driver>org.gjt.mm.mysql.Driver</driver>
                        <url>jdbc:mysql://localhost/cookbook</url>
                        <username>root</username>
                        <password>root</password>
                        <srcFiles>
                          <srcFile>src/test/resources/schema.sql</srcFile>
                          <srcFile>src/test/resources/test-data.sql</srcFile>
                        </srcFiles>

                        <skip>${maven.test.skip}</skip>

                    </configuration>

                    <executions>

                        <execution>
                            <id>create-integration-test-data</id>
                            <phase>process-test-resources</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <orderFile>ascending</orderFile>
                                <fileset>
                                    <basedir>/</basedir>
                                    <includes>
                                        <include>schema.sql</include>
                                        <include>test-data.sql</include>
                                    </includes>
                                </fileset>
                            </configuration>
                        </execution>
                    </executions>

                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>

                <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.4.6-SNAPSHOT</version>
                <configuration>
                    <jettyXml>src/main/resources/jetty/jetty.xml</jettyXml>
                    <stopKey/>
                    <stopPort/>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>perform-integration</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <systemProperties>
                                <property>
                                    <name>servlet.port</name>
                                    <value>${servlet.port}</value>
                                </property>
                            </systemProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify-integration</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-cargo</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-cargo</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>


来源: stackexchange

问:
Is JINI at all active anymore?
Everyone I talk to who knows (knew) about it claims it was the greatest thing since sliced bread.  Why did it fail?  Or, if it didn't fail, who's using it now?</p>

答:
Things have definitely quited down for the idea.  Which is strange since you'd think its goals are even more relevant now.

http://www.jini.org/wiki/Category:News

OwnerDisplayName: jodonnell

ContentLicense: CC BY-SA 2.5

Title: Is JINI at all active anymore?

LastEditorDisplayName: Matt Sheppard

OwnerDisplayName: allain


问:
Density Value for each Return
I have a dataframe "foo" looking like this

```<code>Date       Return
1998-01-01  0.02
1998-01-02  0.04
1998-01-03 -0.02
1998-01-04 -0.01
1998-01-05  0.02
...
1998-02-01  0.1
1998-02-02 -0.2
1998-02-03 -0.1
etc.
</code>```

I would like to add to this dataframe a new column showing me the density value of the corresponding return. I tried:

```<code>foo$density <- for(i in 1:length(foo$Return)) density(foo$Return,
from = foo$Return[i], to = foo$Return[i], n = 1)$y
</code>```

But it didn't work. I really have difficulty applying a "function" to each row. But maybe there is also another way to do it, not using density()?

What I essentially would like to do is to extract the fitted density values from density() to the returns in foo. If I just do plot(density(foo$Return)) it gives me the curve, however I would like to have the density values attached to the returns.

@Joris:

```<code>foo$density <- density(foo$Return, n=nrow(foo$Return))$y
</code>```

calculates something, however seems to return wrong density values.

Thank you for helping me out!
Dani

答:
An alternative to sm.density is to evaluate the density on a finer grid than default, and use approx or approxfun to give the interpolated values of the density at the Returns you want. Here is an example with dummy data:

```<code>set.seed(1)
foo <- data.frame(Date = seq(as.Date("2010-01-01"), as.Date("2010-12-31"),
                             by = "days"),
                  Returns = rnorm(365))
head(foo)
## compute the density, on fin grid (512*8 points)
dens <- with(foo, density(Returns, n = 512 * 8))
</code>```

At this point, we could use approx() to interpolate the x and y components of the returned density, but I prefer approxfun() which does the same thing, but returns a function which we can then use to do the interpolation. First, generate the interpolation function:

```<code>## x and y are components of dens, see str(dens)
BAR <- with(dens, approxfun(x = x, y = y))
</code>```

Now you can use BAR() to return the interpolated density at any point you wish, e.g. for the first Returns:

```<code>> with(foo, BAR(Returns[1]))
[1] 0.3268715
</code>```

To finish the example, add the density for each datum in Returns:

```<code>> foo <- within(foo, Density <- BAR(Returns))
> head(foo)
        Date    Returns   Density
1 2010-01-01 -0.6264538 0.3268715
2 2010-01-02  0.1836433 0.3707068
3 2010-01-03 -0.8356286 0.2437966
4 2010-01-04  1.5952808 0.1228251
5 2010-01-05  0.3295078 0.3585224
6 2010-01-06 -0.8204684 0.2490127
</code>```

To see how well the interpolation is doing, we can plot the density and the interpolated version and compare. Note we have to sort Returns because to achieve the effect we want, lines needs to see the data in increasing order:

```<code>plot(dens)
with(foo, lines(sort(Returns), BAR(sort(Returns)), col = "red"))
</code>```

Which gives something like this:

As long as the density is evaluated at sufficiently fine a set of points (512*8 in the above example) you shouldn't have any problems and will be hard pushed to tell the difference between the interpolated version and the real thing. If you have "gaps" in the values of your Returns then you might find that, as lines() just joins the points you ask it to plot, that straight line segments might not follow the black density at the locations of the gaps. This is just an artefact of the gaps and how lines() works, not a problem with the interpolation.

ContentLicense: CC BY-SA 3.0

Title: Density Value for each Return

Body:
I have a dataframe "foo" looking like this

Date       Return
1998-01-01  0.02
1998-01-02  0.04
1998-01-03 -0.02
1998-01-04 -0.01
1998-01-05  0.02
...
1998-02-01  0.1
1998-02-02 -0.2
1998-02-03 -0.1
etc.

I would like to add to this dataframe a new column showing me the density value of the corresponding return. I tried:

foo$density <- for(i in 1:length(foo$Return)) density(foo$Return,
from = foo$Return[i], to = foo$Return[i], n = 1)$y

But it didn't work. I really have difficulty applying a "function" to each row. But maybe there is also another way to do it, not using density()?

What I essentially would like to do is to extract the fitted density values from density() to the returns in foo. If I just do plot(density(foo$Return)) it gives me the curve, however I would like to have the density values attached to the returns.

@Joris:

foo$density <- density(foo$Return, n=nrow(foo$Return))$y

calculates something, however seems to return wrong density values.

Thank you for helping me out!
Dani

Body:
An alternative to sm.density is to evaluate the density on a finer grid than default, and use approx or approxfun to give the interpolated values of the density at the Returns you want. Here is an example with dummy data:

set.seed(1)
foo <- data.frame(Date = seq(as.Date("2010-01-01"), as.Date("2010-12-31"),
                             by = "days"),
                  Returns = rnorm(365))
head(foo)
## compute the density, on fin grid (512*8 points)
dens <- with(foo, density(Returns, n = 512 * 8))

At this point, we could use approx() to interpolate the x and y components of the returned density, but I prefer approxfun() which does the same thing, but returns a function which we can then use to do the interpolation. First, generate the interpolation function:

## x and y are components of dens, see str(dens)
BAR <- with(dens, approxfun(x = x, y = y))

Now you can use BAR() to return the interpolated density at any point you wish, e.g. for the first Returns:

> with(foo, BAR(Returns[1]))
[1] 0.3268715

To finish the example, add the density for each datum in Returns:

> foo <- within(foo, Density <- BAR(Returns))
> head(foo)
        Date    Returns   Density
1 2010-01-01 -0.6264538 0.3268715
2 2010-01-02  0.1836433 0.3707068
3 2010-01-03 -0.8356286 0.2437966
4 2010-01-04  1.5952808 0.1228251
5 2010-01-05  0.3295078 0.3585224
6 2010-01-06 -0.8204684 0.2490127

To see how well the interpolation is doing, we can plot the density and the interpolated version and compare. Note we have to sort Returns because to achieve the effect we want, lines needs to see the data in increasing order:

plot(dens)
with(foo, lines(sort(Returns), BAR(sort(Returns)), col = "red"))

Which gives something like this:

As long as the density is evaluated at sufficiently fine a set of points (512*8 in the above example) you shouldn't have any problems and will be hard pushed to tell the difference between the interpolated version and the real thing. If you have "gaps" in the values of your Returns then you might find that, as lines() just joins the points you ask it to plot, that straight line segments might not follow the black density at the locations of the gaps. This is just an artefact of the gaps and how lines() works, not a problem with the interpolation.


问:
How to access constants from a java class through other variable?
I have java class which has all constants as given below:

```<code>public final class CategoryIDs {

  public static final String Extraction_of_natural_gas = "1111";
  public static final String Mining_of_hard_coal = "2222";
  public static final String Mining_of_iron_ores = "3333";
  public static final String Mining_of_lignite = "4444";

}
</code>```

Now I want to access these constants in some other class through a variable which holds name of the variable.

For example:

```<code>String temp = "Extraction_of_natural_gas";
</code>```

Using this temp variable I want to access constants from above class. But I can't do  CategoryIDs.temp as it isn't allowed. So what is the best way to achieve this?

答:
I think you are looking for introspection. This is the "read only" part of reflection, in which you can retrieve the value of an object.

The code would be as follows, pieced for ease of understanding:

```<code>    Object value = null;
    String constName = "Bar";
    Field constant = Foo.class.getField( constName );

    if ( constant != null ) {
        value = constant.get( null );
    }

    if ( value != null ) {
        System.out.println( value );
    } else {
        System.out.println( "Constant " + constName + " was not found." );
    }
</code>```

Interestingly, you can access the value from the Field object calling get(), and you pass null because the constant is static, and thus you don't have an instance to extract the value from.

You can find the whole code here: http://ideone.com/v4fcvH

Hope this helps.

Body:
I have java class which has all constants as given below:

public final class CategoryIDs {

  public static final String Extraction_of_natural_gas = "1111";
  public static final String Mining_of_hard_coal = "2222";
  public static final String Mining_of_iron_ores = "3333";
  public static final String Mining_of_lignite = "4444";

}

Now I want to access these constants in some other class through a variable which holds name of the variable.

For example:

String temp = "Extraction_of_natural_gas";

Using this temp variable I want to access constants from above class. But I can't do  CategoryIDs.temp as it isn't allowed. So what is the best way to achieve this?

Body:
I think you are looking for introspection. This is the "read only" part of reflection, in which you can retrieve the value of an object.

The code would be as follows, pieced for ease of understanding:

    Object value = null;
    String constName = "Bar";
    Field constant = Foo.class.getField( constName );

    if ( constant != null ) {
        value = constant.get( null );
    }

    if ( value != null ) {
        System.out.println( value );
    } else {
        System.out.println( "Constant " + constName + " was not found." );
    }

Interestingly, you can access the value from the Field object calling get(), and you pass null because the constant is static, and thus you don't have an instance to extract the value from.

You can find the whole code here: http://ideone.com/v4fcvH

Hope this helps.


问:
Eclipse DDMS not showing anything but adb, ddms are working!
The eclipse DDMS perspective is not detecting any attached devices or even the emulator. I have tried using adb and ddms from the command line and both are working! What gives?</p>

答: I too faced this issue, DDMS was not launching. At last, in Android Studio -> Terminal, entered command DDMS and press Enter. Then DDMS started working.</p>


问:
Odoo - Hide button for specific user
I am using odoo 10 enterpeise . I want to show buttons to specific users not to groups because there would be many users in a group and i want to only show below button who have the previlige to reject/approve a object.
Here is button

```<code><xpath expr="//sheet" position="before">
          <header>
            <button name="update_approve" attrs="{'invisible':[('first_approve', '=', uid)]}" string="Approve" type="object" class="oe_highlight"/>
              <button name="update_reject" attrs="{'invisible':[('second_approve', '=', uid)]}" string="Reject" type="object" class="btn-danger"/>
          </header>
      </xpath>
</code>```

I tried to do this using uid but uid is not available in xml

first_approve and second_approve are the fields in my model based on which i want to show button only to users which are assigned in first_approve/second_approve

答:
I have understood that you have a fixed list of users who will be able to approve and other fixed list of users who will be able to reject. In spite of being a few users, I would create two groups and use groups attribute on your buttons, but if even so you do not want to create a couple of groups for them, you can do this:

```<code>from openerp import models, api
import json
from lxml import etree

FIRST_APPROVE = []  # Fill this list with the IDs of the users who can update approve
SECOND_APPROVE = []  # Fill this list with the IDs of the users who can update reject

class YourClass(models.Model):
    _inherit = 'your.class'

    def update_json_data(self, json_data=False, update_data={}):
        ''' It updates JSON data. It gets JSON data, converts it to a Python
        dictionary, updates this, and converts the dictionary to JSON data
        again. '''
        dict_data = json.loads(json_data) if json_data else {}
        dict_data.update(update_data)
        return json.dumps(dict_data, ensure_ascii=False)

    def set_modifiers(self, element=False, modifiers_upd={}):
        ''' It updates the JSON modifiers with the specified data to indicate
        if a XML tag is readonly or invisible or not. '''
        if element is not False:  # Do not write only if element:
            modifiers = element.get('modifiers') or {}
            modifiers_json = self.update_json_data(
                modifiers, modifiers_upd)
            element.set('modifiers', modifiers_json)

    @api.model
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
                        submenu=False):
        res = super(YourClass, self).fields_view_get(
            view_id=view_id, view_type=view_type, toolbar=toolbar,
            submenu=submenu)

        doc = etree.XML(res['arch'])

        if view_type == 'form':
            if self.env.uid in FIRST_APPROVE:
                upd_approve_btn_search = doc.xpath("//button[@name='update_approve']")
                upd_approve_btn = upd_approve_btn_search[0] \
                    if upd_approve_btn_search else False
                if upd_approve_btn:
                    self.set_modifiers(upd_approve_btn, {'invisible': False, })

            if self.env.uid in SECOND_APPROVE:
                upd_reject_btn_search = doc.xpath("//button[@name='update_reject']")
                upd_reject_btn = upd_reject_btn_search[0] \
                    if upd_reject_btn_search else False
                if upd_reject_btn:
                    self.set_modifiers(upd_reject_btn, {'invisible': False, })

        res['arch'] = etree.tostring(doc)
        return res
</code>```

FIRST APPROVE and SECOND_APPROVE will be const in which you must introduce the fixed IDS of the users who can perform the respective action (for example: FIRST APPROVE = [2, 7, 9]).

YourClass must be the class in which you have declared the methods of your buttons (the one in which you have declared update_approve and update_reject).

IMPORTANT: with this code, your buttons must be always invisible (write invisible="1" at your XML view), because after loading the XML code, the fields_view_get will overwrite the invisible value to set 0.

This is an uncommon way to manage your purpose, but unfortunately I think it is the simplest one if you do not want to create groups. I hope it helps you and other users!

Title: Odoo - Hide button for specific user

Body:
I am using odoo 10 enterpeise . I want to show buttons to specific users not to groups because there would be many users in a group and i want to only show below button who have the previlige to reject/approve a object.
Here is button

<xpath expr="//sheet" position="before">

            <button name="update_approve" attrs="{'invisible':[('first_approve', '=', uid)]}" string="Approve" type="object" class="oe_highlight"/>
              <button name="update_reject" attrs="{'invisible':[('second_approve', '=', uid)]}" string="Reject" type="object" class="btn-danger"/>

      </xpath>

I tried to do this using uid but uid is not available in xml

first_approve and second_approve are the fields in my model based on which i want to show button only to users which are assigned in first_approve/second_approve

Body:
I have understood that you have a fixed list of users who will be able to approve and other fixed list of users who will be able to reject. In spite of being a few users, I would create two groups and use groups attribute on your buttons, but if even so you do not want to create a couple of groups for them, you can do this:

from openerp import models, api
import json
from lxml import etree

FIRST_APPROVE = []  # Fill this list with the IDs of the users who can update approve
SECOND_APPROVE = []  # Fill this list with the IDs of the users who can update reject

class YourClass(models.Model):
    _inherit = 'your.class'

    def update_json_data(self, json_data=False, update_data={}):
        ''' It updates JSON data. It gets JSON data, converts it to a Python
        dictionary, updates this, and converts the dictionary to JSON data
        again. '''
        dict_data = json.loads(json_data) if json_data else {}
        dict_data.update(update_data)
        return json.dumps(dict_data, ensure_ascii=False)

    def set_modifiers(self, element=False, modifiers_upd={}):
        ''' It updates the JSON modifiers with the specified data to indicate
        if a XML tag is readonly or invisible or not. '''
        if element is not False:  # Do not write only if element:
            modifiers = element.get('modifiers') or {}
            modifiers_json = self.update_json_data(
                modifiers, modifiers_upd)
            element.set('modifiers', modifiers_json)

    @api.model
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
                        submenu=False):
        res = super(YourClass, self).fields_view_get(
            view_id=view_id, view_type=view_type, toolbar=toolbar,
            submenu=submenu)

        doc = etree.XML(res['arch'])

        if view_type == 'form':
            if self.env.uid in FIRST_APPROVE:
                upd_approve_btn_search = doc.xpath("//button[@name='update_approve']")
                upd_approve_btn = upd_approve_btn_search[0] \
                    if upd_approve_btn_search else False
                if upd_approve_btn:
                    self.set_modifiers(upd_approve_btn, {'invisible': False, })

            if self.env.uid in SECOND_APPROVE:
                upd_reject_btn_search = doc.xpath("//button[@name='update_reject']")
                upd_reject_btn = upd_reject_btn_search[0] \
                    if upd_reject_btn_search else False
                if upd_reject_btn:
                    self.set_modifiers(upd_reject_btn, {'invisible': False, })

        res['arch'] = etree.tostring(doc)
        return res

FIRST APPROVE and SECOND_APPROVE will be const in which you must introduce the fixed IDS of the users who can perform the respective action (for example: FIRST APPROVE = [2, 7, 9]).

YourClass must be the class in which you have declared the methods of your buttons (the one in which you have declared update_approve and update_reject).

IMPORTANT: with this code, your buttons must be always invisible (write invisible="1" at your XML view), because after loading the XML code, the fields_view_get will overwrite the invisible value to set 0.

This is an uncommon way to manage your purpose, but unfortunately I think it is the simplest one if you do not want to create groups. I hope it helps you and other users!


问:
Calling apply with an array
I found an article that use the following nodeJs function:

```<code>var path = require('path');

var _root = path.resolve(__dirname, '..');

function root(args) {
    args = Array.prototype.slice.call(arguments, 0);
    return path.join.apply(path, [_root].concat(args));
}

exports.root = root;
</code>```

As I didn't know how to use call and apply, I did some tests/researches, but there's still something I don't get: the return statement.

I tried to replace it by

```<code>return path.join([_root].concat(args))
</code>```

But I got:

throw new TypeError('Path must be a string. Received ' +
  inspect(path));

Okay, so the argument passed to path.join must be a string, fair enough, but the apply function passes it as an array, so how could it work?

To verify this, I created this simple function:

```<code>function foo (arg) { console.log(arg); }
</code>```

And I called it this way:

```<code>foo.apply(foo, ["plop", "plip"])
</code>```

But I just get "plop", so I don't understand how path.join is working if it only gets the first item of the array. I also try to display arguments, but then I got an array, not a string.

Basically, I don't understand how come that the array passed as an argument gets accepted as a string while it's not when I directly call path.join.

答:
Suppose you have an array of const arr = [ 'a', 'b', 'c' ].

When you call path.join.apply( path, arr ) it gets spread and would be the same as calling

path.join( 'a', 'b', 'c' ).

.apply spreads the arguments. So your function should look something like function foo( arg1, arg2 ) { /* ... */ }

If you want all arguments passed to a function in one variable, use arguments like so:

```<code>function test( arg1, arg2 ) {
  console.log( arg1, arg2 );
  console.log( arguments );
}

test.apply( null, [ 'a', 'b' ] );
</code>```

.call on the other hand just calls a function with separated arguments.
So in our example here you'd do test.call( null, 'a', 'b' );

So why should I use call or apply? Well, there might be a lot more reasons than I'm going to mention here, but

you can call function dynamically, deciding which one to call based on a variable.

you can define another context. The first argument is the context you can pass which is represented as this inside the function body.

Here are the document pages for apply and call.

Title: Calling apply with an array

Body:
I found an article that use the following nodeJs function:

var path = require('path');

var _root = path.resolve(__dirname, '..');

function root(args) {
    args = Array.prototype.slice.call(arguments, 0);
    return path.join.apply(path, [_root].concat(args));
}

exports.root = root;

As I didn't know how to use call and apply, I did some tests/researches, but there's still something I don't get: the return statement.

I tried to replace it by

return path.join([_root].concat(args))

But I got:

throw new TypeError('Path must be a string. Received ' +
  inspect(path));

Okay, so the argument passed to path.join must be a string, fair enough, but the apply function passes it as an array, so how could it work?

To verify this, I created this simple function:

function foo (arg) { console.log(arg); }

And I called it this way:

foo.apply(foo, ["plop", "plip"])

But I just get "plop", so I don't understand how path.join is working if it only gets the first item of the array. I also try to display arguments, but then I got an array, not a string.

Basically, I don't understand how come that the array passed as an argument gets accepted as a string while it's not when I directly call path.join.

Body:
Suppose you have an array of const arr = [ 'a', 'b', 'c' ].

When you call path.join.apply( path, arr ) it gets spread and would be the same as calling

path.join( 'a', 'b', 'c' ).

.apply spreads the arguments. So your function should look something like function foo( arg1, arg2 ) { /* ... */ }

If you want all arguments passed to a function in one variable, use arguments like so:

function test( arg1, arg2 ) {
  console.log( arg1, arg2 );
  console.log( arguments );
}

test.apply( null, [ 'a', 'b' ] );

.call on the other hand just calls a function with separated arguments.
So in our example here you'd do test.call( null, 'a', 'b' );

So why should I use call or apply? Well, there might be a lot more reasons than I'm going to mention here, but

you can call function dynamically, deciding which one to call based on a variable.

you can define another context. The first argument is the context you can pass which is represented as this inside the function body.

Here are the document pages for apply and call.


问:
Have to find a count of rows from my postgresql query
Hi I tried to get a count of rows from my below query:

```<code>        select count(substring(wsresult_question FROM '[0-9]+') as pumporder) AS totals,
            job_id,
            job_siteid,
            job_completed
            from webserviceresults w, jobs s
            where job_siteid = '1401'
            and job_id = wsresult_jobid
            and job_completed is not null
            and wsresult_question LIKE 'job.job_site_data.site_meters.pump.%'
            and wsresult_category = 'Job'
            group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
</code>```

I tried this and i got the error like

```<code>There was an SQL error:
ERROR: syntax error at or near "as" LINE 1: ... count(substring(wsresult_question FROM '[0-9]+') as pumpord... ^
</code>```

In this line substring(wsresult_question FROM '[0-9]+') as pumporder I just tired to get only a number from some concatenate strings. The concatenate string  is being like

1.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtofast

2.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtoslow

3.job.job_site_data.site_meters.pump.1.meter_calibration_record.meter_adjustedtofast

So substring(wsresult_question FROM '[0-9]+') as pumporder is return the numbers like 0,1 in array. I need to total the count of rows now. So Kindly help me on this.

Please let me know if you have any queries.

Thanks in advance!

答:
your error means you should not create an alias for the function - only for the column, so if you remove as pumporder from count(substring(wsresult_question FROM '[0-9]+') as pumporder) , error will go away

Your approach though is very doubtful. If you want to count number of rows with substring(wsresult_question FROM '[0-9]+'), you better instead:

```<code>    select count(1) AS totals,
        job_id,
        job_siteid,
        job_completed
        from webserviceresults w, jobs s
        where job_siteid = '1401'
        and job_id = wsresult_jobid
        and job_completed is not null
        and wsresult_question  ~ '^(job.job_site_data.site_meters.pump.)[0-9]'
        and wsresult_category = 'Job'
        group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
</code>```

and lastly the string job.job_site_data.site_meters.pump.0 looks like json path, so it would be more appropriate using json array length function, not count on rows

Body:
Hi I tried to get a count of rows from my below query:

        select count(substring(wsresult_question FROM '[0-9]+') as pumporder) AS totals,
            job_id,
            job_siteid,
            job_completed
            from webserviceresults w, jobs s
            where job_siteid = '1401'
            and job_id = wsresult_jobid
            and job_completed is not null
            and wsresult_question LIKE 'job.job_site_data.site_meters.pump.%'
            and wsresult_category = 'Job'
            group by pumporder,job_id,job_siteid,job_completed order by job_completed desc

I tried this and i got the error like

There was an SQL error:
ERROR: syntax error at or near "as" LINE 1: ... count(substring(wsresult_question FROM '[0-9]+') as pumpord... ^

In this line substring(wsresult_question FROM '[0-9]+') as pumporder I just tired to get only a number from some concatenate strings. The concatenate string  is being like

1.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtofast

2.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtoslow

3.job.job_site_data.site_meters.pump.1.meter_calibration_record.meter_adjustedtofast

So substring(wsresult_question FROM '[0-9]+') as pumporder is return the numbers like 0,1 in array. I need to total the count of rows now. So Kindly help me on this.

Please let me know if you have any queries.

Thanks in advance!

Body:
your error means you should not create an alias for the function - only for the column, so if you remove as pumporder from count(substring(wsresult_question FROM '[0-9]+') as pumporder) , error will go away

Your approach though is very doubtful. If you want to count number of rows with substring(wsresult_question FROM '[0-9]+'), you better instead:

    select count(1) AS totals,
        job_id,
        job_siteid,
        job_completed
        from webserviceresults w, jobs s
        where job_siteid = '1401'
        and job_id = wsresult_jobid
        and job_completed is not null
        and wsresult_question  ~ '^(job.job_site_data.site_meters.pump.)[0-9]'
        and wsresult_category = 'Job'
        group by pumporder,job_id,job_siteid,job_completed order by job_completed desc

and lastly the string job.job_site_data.site_meters.pump.0 looks like json path, so it would be more appropriate using json array length function, not count on rows


问:
sql:invalid number

The data is classified so that I could only upload a picture. Sorry about that.
The sql statement comes up with "invalid number", I think it is probably wrong in the first line to_number(2016-(substr(cust_no,8,4))), the cust_no is varchar2(25), how could I fix it? Thank you

答:
Try to use </p>

```<code>SELECT 2016-to_number(substr(cust_no,8,4)) FROM dual;
</code>```

Title: sql:invalid number

Body:
Try to use

SELECT 2016-to_number(substr(cust_no,8,4)) FROM dual;


问:
inter processes shared memory and pthread_barrier: how to be safe?
I wanted a simple solution for inter processes barrier. Here a solution: solution

But I am totally lost with mmap... With my first try, it fails one out of ten times (segfault or deadlock).

I understand my problem comes from a synchronization issue, but I can't find it. I found an example to set up mmaped memory (example), but I am not sure it is good for a mmaped pthread_barrier.

Here an extract of my code:

```<code>#define MMAP_FILE "/tmp/mmapped_bigdft.bin"

void init_barrier() {
  pthread_barrier_t *shared_mem_barrier;
  pthread_barrierattr_t barattr;
  pthread_barrierattr_setpshared(&barattr, PTHREAD_PROCESS_SHARED);

  hbcast_fd = open(MMAP_FILE, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
  result = lseek(hbcast_fd, sizeof(pthread_barrier_t)-1, SEEK_SET);
  result = write(hbcast_fd, "", 1);
  shared_mem_barrier = (pthread_barrier_t*) mmap(0, sizeof(pthread_barrier_t), PROT_READ | PROT_WRITE, MAP_SHARED, hbcast_fd, 0);
  if (mpi_rank == 0) {
    int err = pthread_barrier_init(shared_mem_barrier, &barattr, host_size);
  }
  MPI_Barrier(some_communicator);
}
</code>```

Questions:

do I miss something in mmap initialization?

which operation should be performed by all processes, and which should be by only one?

New question

Which is safier for managing pthread barrier? Or are they based on the same mechanism?

shmget

shm_open

mmap

another one

答:
As Charles has mentioned, it looks like the truncation is what's getting you. Also, you should initialise the attributes using pthread_barrierattr_init.

As for the other question, just one process should do the initialisation, and then all processes should call pthread_barrier_wait (just like with MPI).

I saw your other question, so I know why you don't want to use MPI. So you'd probably do just a single MPI barrier to initialise your pthread barriers, like so:

```<code>if (rank == 0)
{
  /* Create the shared memory segment, initialise the barrier. */
}
MPI_Barrier(communicator);
if (rank != 0)
{
  /* Load the shared memory segment, cast it to a pthread_barrier_t* and store.
   * It's already initialised */
}
</code>```

Body:
I wanted a simple solution for inter processes barrier. Here a solution: solution

But I am totally lost with mmap... With my first try, it fails one out of ten times (segfault or deadlock).

I understand my problem comes from a synchronization issue, but I can't find it. I found an example to set up mmaped memory (example), but I am not sure it is good for a mmaped pthread_barrier.

Here an extract of my code:

#define MMAP_FILE "/tmp/mmapped_bigdft.bin"

void init_barrier() {
  pthread_barrier_t *shared_mem_barrier;
  pthread_barrierattr_t barattr;
  pthread_barrierattr_setpshared(&barattr, PTHREAD_PROCESS_SHARED);

  hbcast_fd = open(MMAP_FILE, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
  result = lseek(hbcast_fd, sizeof(pthread_barrier_t)-1, SEEK_SET);
  result = write(hbcast_fd, "", 1);
  shared_mem_barrier = (pthread_barrier_t*) mmap(0, sizeof(pthread_barrier_t), PROT_READ | PROT_WRITE, MAP_SHARED, hbcast_fd, 0);
  if (mpi_rank == 0) {
    int err = pthread_barrier_init(shared_mem_barrier, &barattr, host_size);
  }
  MPI_Barrier(some_communicator);
}

Questions:

do I miss something in mmap initialization?

which operation should be performed by all processes, and which should be by only one?

New question

Which is safier for managing pthread barrier? Or are they based on the same mechanism?

shmget

shm_open

mmap

another one

Body:
As Charles has mentioned, it looks like the truncation is what's getting you. Also, you should initialise the attributes using pthread_barrierattr_init.

As for the other question, just one process should do the initialisation, and then all processes should call pthread_barrier_wait (just like with MPI).

I saw your other question, so I know why you don't want to use MPI. So you'd probably do just a single MPI barrier to initialise your pthread barriers, like so:

if (rank == 0)
{
  /* Create the shared memory segment, initialise the barrier. */
}
MPI_Barrier(communicator);
if (rank != 0)
{
  /* Load the shared memory segment, cast it to a pthread_barrier_t* and store.
   * It's already initialised */
}


问:
How to get all the names in dropzone in reactjs
I'm having difficulty on getting all the file name I dropped; I only get the first dropped item name but I needed all the names so i can upload it all. Here is the sample of my dropzone:

```<code>onDrop(acceptedFiles) {
    debugger
    console.log('Received files: ', acceptedFiles);
    this.setState({files: acceptedFiles});
    let {form} = this.props.timeline;

        acceptedFiles.map(file =>  {
            form.Name=file.name
        });

}
</code>```

and here is what happens in the dropzone debugged

答:
Your acceptedFiles already contains all the filenames but the filename is encapsulated inside the object which also seems to contain the TimelineKeyas well.

If you only want the filenames then you need to modify your code a bit:

const filenames = acceptedFiles.map(file => (file.name))

Then you have the collection of filenames and you can do what ever you want with it.

Body:
I'm having difficulty on getting all the file name I dropped; I only get the first dropped item name but I needed all the names so i can upload it all. Here is the sample of my dropzone:

onDrop(acceptedFiles) {
    debugger
    console.log('Received files: ', acceptedFiles);
    this.setState({files: acceptedFiles});
    let {form} = this.props.timeline;

        acceptedFiles.map(file =>  {
            form.Name=file.name
        });

}

and here is what happens in the dropzone debugged


问:
Showing total count for bar chart in c3js tooltip title
I have a bar chart similar to the one shown in this link.

I wanted to add two features to this bar chart

Instead of numbers, I want the tooltip title to display the sum of the count displayed by the bars at the given cordinate.

I wanted to display the % in the tooltip instead of the actual count.

Could someone please help me with this?

答:
This can be done by configuring tooltip.format.title:

```<code>   tooltip: {
      format: {
        title: function (index) {
          return totals[index]
        }
</code>```

and tooltip.format.value:

```<code>        value: function (value, ratio, id, index) {
          return d3.format("%")(value / totals[index])
        }
     }
  }
</code>```

And as you can see above, you need to calculate total values of your data groups:

```<code>var totals = [390, 500, 500, 900, 550, 550]
</code>```

See example.

Body:
This can be done by configuring tooltip.format.title:

   tooltip: {
      format: {
        title: function (index) {
          return totals[index]
        }

and tooltip.format.value:

        value: function (value, ratio, id, index) {
          return d3.format("%")(value / totals[index])
        }
     }
  }

And as you can see above, you need to calculate total values of your data groups:

var totals = [390, 500, 500, 900, 550, 550]

See example.


问:
JS:Want to animate on clicking the button
I want to animate/colorify the div on clicking the button 'Animate'
Can you test my code and suggest some changes or add some code ?

My code looks like this:-

.anime {
  animation: coloranimate 5s;
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background: red;
}

@keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

@-webkit-keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="anime" class="anime">
</div>
<button>Animate</button></code>```

I want to animate/colorify the div using the animate button.

答:
Here you have to add jquery for achieve your requirement.

Try this code it may helps you.

Edit

it is with plain javascript.

function addAnime() {
var classadd = document.getElementById('anime');
classadd.className = 'anime';
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.anime {
  animation: coloranimate 5s;
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background: red;
}

@keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

@-webkit-keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}</code>```

<button onclick="addAnime()">Animate</button>```

Body:
I want to animate/colorify the div on clicking the button 'Animate'
Can you test my code and suggest some changes or add some code ?

My code looks like this:-

.anime {
  animation: coloranimate 5s;
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background: red;
}

@keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

@-webkit-keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

<button>Animate</button>

I want to animate/colorify the div using the animate button.

Body:
Here you have to add jquery for achieve your requirement.

Try this code it may helps you.

Edit

it is with plain javascript.

function addAnime() {
var classadd = document.getElementById('anime');
classadd.className = 'anime';
}

.anime {
  animation: coloranimate 5s;
  width: 100px;
  height: 100px;
  border: 1px solid black;
  background: red;
}

@keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

@-webkit-keyframes coloranimate {
  from {
    background: green;
  }
  to {
    background: yellow;
    border: 4px solid black;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="anime" class="">
</div>
<button onclick="addAnime()">Animate</button>


问:
Laravel Dingo nested transformers
I'm trying to get one to many relationship objects with transformers. I want to get include metas but i only get just regular transform fields.

my transformer:

```<code>class AssistantTransformer extends TransformerAbstract
{

    protected $availableIncludes = [
        'assistantmetas'
    ];

    public function transform(User $user)
    {
        return [
            'id'        => (int) $user->id,
            'firstname' => ucfirst($user->first_name),
            'lastname'  => ucfirst($user->last_name),
        ];
    }

    public function includeMetas(User $user)
    {
        $assistantmetas = $user->userMetas;

        return $this->item($assistantmetas, new AssistantsMetaTransformer);
    }
}
</code>```

答: Just use defaultIncludes not available includes, because it needs to send request via url? include=assistantmetas to get result like this.

Title: Laravel Dingo nested transformers

Body:
I'm trying to get one to many relationship objects with transformers. I want to get include metas but i only get just regular transform fields.

my transformer:

class AssistantTransformer extends TransformerAbstract
{

    protected $availableIncludes = [
        'assistantmetas'
    ];

    public function transform(User $user)
    {
        return [
            'id'        => (int) $user->id,
            'firstname' => ucfirst($user->first_name),
            'lastname'  => ucfirst($user->last_name),
        ];
    }

    public function includeMetas(User $user)
    {
        $assistantmetas = $user->userMetas;

        return $this->item($assistantmetas, new AssistantsMetaTransformer);
    }
}


问:
I'm trying to get a count of records from a related entity that match a criteria
I have an entity matches which has a related to-many entity sets. I want to get a count of how many sets have the attribute 'set_finished' set to YES for a particular match. I'm trying to do this with:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY set_finished == YES"];
 NSUInteger numberOfFinishedSets = [[[match valueForKeyPath:@"sets"] filteredArrayUsingPredicate:predicate ] count];

The second line crashes with this error, which I don't understand. Can anyone shed some light on this for me? Thanks.

2010-12-20 13:17:13.814
  DartScorer[2154:207] * Terminating
  app due to uncaught exception
  'NSInvalidArgumentException', reason:
  '-[_NSFaultingMutableSet
  filteredArrayUsingPredicate:]:
  unrecognized selector sent to instance
  0x617fb20'

答: You should use filteredSetUsingPredicate: instead of filteredArrayUsingPredicate since the object is a set, not an array.


问:
Exposing data to BI and generating reports in neo4j
What is the best practice  exposed data to BI from neo4j ? and If we are generating reports what is best practice to generate reports in Neo4j

Need your guidance on this

答:
This page: Using PowerBI with Neo4j explains the setup of PowerBI - in essence you use the REST end point that Neo4j exposes and connect as a 'Web' connection in Power BI.

As to your second part of the question - that's your usage of PowerBI and isn't something that can really be answered here.