小编Jas*_*ler的帖子

接受scala中参数的多个类型

我有两个对象,ObjectA和ObjectB,都有方法update().我想编写一个接受ObjectA或ObjectB(但没有其他类型)的函数.从概念上讲,这就是我要做的事情:

def doSomething[T <: ObjectA | T <: ObjectB](obj: T) = {
    obj.update
}
Run Code Online (Sandbox Code Playgroud)

我意识到还有其他方法可以解决这个问题(例如,update()方法的结构类型,公共基类等)但我的问题是它可以在Scala中这样做,如果是这样,语法是什么?这叫什么?

types scala structural-typing

16
推荐指数
1
解决办法
7524
查看次数

如何从JSF 1.2中的Facelet标记文件访问父组件

我正在JSF 1.2中编写Facelet标记文件.我希望能够引用父容器.在JSF 2.0中,我可以将它作为一个复合组件并使用#{cc.parent}.但有没有一个JSF 1.2等效的方法呢?

taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
  <namespace>http://company.com/jsf</namespace>
  <tag>
     <tag-name>parentid</tag-name>
     <source>../components/parentid.xhtml</source>
  </tag>
</facelet-taglib>
Run Code Online (Sandbox Code Playgroud)

parentid.xhtml

<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:ui="http://java.sun.com/jsf/facelets">

  <!-- The next line is the line that isn't working for me -->
  <h:outputText binding="#{obj}" value="Parent id is: #{obj.parent.id}" />
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

testpage.xhtml

<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:test="http://company.com/jsf"
  xmlns:ui="http://java.sun.com/jsf/facelets">

  ...
  <a:form id="form1">
    <test:parentid />
  </a:form>
  <a:form id="form2">
    <test:parentid />
  </a:form>
  ...
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

我编辑了这个以包含来自BalusC链接的信息,我几乎就在那里.

在示例中,如果只有form1,它将完美地工作.但是添加form2,这是我得到的输出:

Parent id is: form2
Parent …
Run Code Online (Sandbox Code Playgroud)

jsf facelets parent tagfile jsf-1.2

6
推荐指数
0
解决办法
1728
查看次数

如何使用maven创建一个可运行的jar,其中包含一个单独的"lib"文件夹(不是超级jar)中的依赖项

我正在尝试使用Maven创建一个可执行jar文件,其中包含单独目录中的依赖项.我已经看到很多关于创造"uberjar"的问题 - 我不希望如此.我想要的是将依赖项复制到像这样的"lib"目录中(以及MANIFEST.MF带有ClassPath指向它们的条目的jar 文件):

/myApp
  myApp.SNAPSHOT-1.0.jar
  /lib
    hibernate.jar
    log4j.jar
    ...
Run Code Online (Sandbox Code Playgroud)

作为一个额外的奖励,如果我可以复制/src/main/resources/*/myApp/conf然后压缩整个/myApp目录,那将myApp.zip是很好的.

编辑:我使用maven-dependency-plugin和maven-resources-plugin以及maven-jar-plugin.这是我在我的pom.xml中包含的内容(它将运行时依赖项复制到/ target/release/lib,以便我可以压缩/目标/发布并准备好了):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <outputDirectory>
                    ${project.build.directory}/release/lib
                </outputDirectory>
             </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-resources</id>
        <!-- here the phase you need -->
        <phase>package</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/release</outputDirectory>
          <resources>          
            <resource>
              <directory>src/main/config</directory>
              <filtering>true</filtering>
            </resource>
          </resources>              
        </configuration>            
      </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals> …
Run Code Online (Sandbox Code Playgroud)

java executable-jar maven

4
推荐指数
1
解决办法
4037
查看次数