小编Joe*_*ore的帖子

JSF 2.0转换器无法从单独的jar文件中运行

我有一个自定义转换器来选择SelectOneMenu组件中的国家/地区:

文件:address.jar

@FacesConverter(value="CountryConverter", forClass=Country.class)
public class CountryConverter implements Converter {

private CountryBean countryBean = CountryBean.getCountryService();

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    return countryBean.find(value);
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value != null)
        return ((Country)value).getcc_fips();
    else
        return null;
}    
Run Code Online (Sandbox Code Playgroud)

这是xhtml文本:

文件:项目根目录

  <h:selectOneMenu id="country" value="#{cc.attrs.addrEntity.country}">
     <f:selectItem itemLabel="Please select one..." 
             noSelectionOption="true" />
     <f:selectItems value="#{cc.attrs.addrBean.countries}"
                    var="model"
                    itemLabel="#{model.name}"
                    itemValue="#{model}"
                    noSelectionValue="&#8220;no selection&#8221;"/>
     <f:converter ConverterId="CountryConverter"/>        
 </h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)

我将转换器放在文件" address.jar "中,当我尝试打开页面写入地址时,它会回复说"表达式错误:找不到名称为MyCustomCoverter的对象"..甚至当我将转换器复制到xhtml文件所在的项目时,它就可以了.我该怎么做才能解决这个问题?

为什么它不能从分离的jar文件中工作?

谢谢.

java converter jsf-2

5
推荐指数
1
解决办法
2106
查看次数

JPA - 运行测试用例时未启用编织

我有一个使用 Eclipselink 2.5 的应用程序,在运行 Junit 测试用例时,我总是收到此警告:

[EL Warning]: metadata: 2013-08-19 01:14:05.142--ServerSession(14351551)--
Reverting the lazy setting on the OneToOne or ManyToOne attribute [currentTransit]
for the entity class [class ......persistent.entity.BPExecutionEntity] since
weaving was not enabled or did not occur.
Run Code Online (Sandbox Code Playgroud)

所以,我在 Ant 构建文件上写了一个“编织”任务,如下所示:

<target name="define.task" description="New task definition for EclipseLink static weaving">
    <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/>
</target>
<target name="weaving" description="perform weaving" depends="define.task">
    <weave  source="D:\...\dist\${ant.project.name}.jar"
            target="D:\...\dist\woven-${ant.project.name}.jar"
            persistenceinfo="D:\...\lib\persistence.jar">
        <classpath>
        </classpath>
    </weave>
</target>
Run Code Online (Sandbox Code Playgroud)

好的,一切正常,当我编译代码时,它会生成一个大小为已编译 jar 一半大小的编织文件。但是,当我运行项目的测试时,我仍然收到相同的警告blah blah blah... since weaving was not enabled or did not …

java jpa eclipselink

5
推荐指数
1
解决办法
6182
查看次数

无法在linux控制台中执行任何基本命令

我知道问题是如何创建的,但实际上不知道如何恢复服务器命令执行.

问题是,我在我的Ubuntu服务器中配置Glassfish的环境变量,我.bashrc从root 修改了文件,并添加了一个export子句(带GLASSFISH_HOME变量)和一个PATH子句(指向$GLASSFISH_HOME/bin).

紧接着我关闭控制台,然后再次打开它,以便使更改生效,和(BAM!)一旦我开始了新的控制台会话则没有基本的命令(dir,find,nano,ifconfig,任何东西)现在的工作,我只能用cd移动在目录中,我试图再次编辑.bashrc文件以撤消更改,但也无法编辑它,没有编辑器打开!在命令行中我只得到-bash: dir: command not found.

如果你对此有任何解决方案,请 我知道这似乎微不足道,但我有点失明,却无法查看或找到命令/应用程序所在的文件和文件夹.

linux bash

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

创建邮件发件人对象

我在Outlook 2013中创建了一个电子邮件对象,但我找不到如何创建Sender对象.我正在使用此代码:

Outlook.MailItem mail = (Outlook.MailItem)
         Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = "mail@gmail.com"
mail.Sender = // What goes here?
mail.Subject = "Mail subject";
Run Code Online (Sandbox Code Playgroud)

Sender对象是Outlook.AddressEntry接口的实现,因此必须在某处实现,但在哪里呢?是否可以创建此Sender对象?

顺便说一句,电子邮件的发件人不一定是在Outlook注册的帐户,所以我不能使用该mail.SendUsingAccount属性.

c# outlook

4
推荐指数
2
解决办法
5638
查看次数

使用没有JRE的javafx-maven-plugin Maven + Build Native

我有一个简单的JavaFX应用程序,我想为Windows机器创建一个安装程序.该javafx-maven-plugin作品,并创建一个Windows安装沿应用程序的可执行文件,但问题是,它创建了内部的JavaFX应用程序在Windows安装程序以及完整的JRE太大.

那么,如何在javafx-maven-plugin不使用完整的Java框架的情况下为Windows构建本机文件.也许它应该只创建一个Java Framework的依赖.这使安装程序从1.5MB到200MB的磁盘空间膨胀.

使用Maven我使用该命令mvn clean compile jfx:build-jar jfx:native获取Windows中的本机文件,这是我正在使用的POM文件:

<?xml version="1.0"?>
<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.demo</groupId>
    <artifactId>hello-javafx-maven-example</artifactId>
    <name>JavaFX Example Maven Project</name>
    <organization>
        <name>Jaa Demo</name>
    </organization>

    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.zenjava</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>8.1.3</version>
                <configuration>
                     <mainClass>com.demo.helloWorld</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>        
</project>
Run Code Online (Sandbox Code Playgroud)

java maven javafx-8

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

Apache Ant/NetBeans - build.xml中的语句,用于将dist/myfile.jar复制到另一个文件夹

我知道一旦Apache Ant完成编译,应该有一种方法将jar文件复制到另一个位置.我使用的是NetBeans 7,它创建了自己的build.xml文件,如下所示:

<project name="ccabstract" default="default" basedir="." xmlns:ejbjarproject="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
<description>Builds, tests, and runs the project ccabstract.</description>
<import file="nbproject/build-impl.xml"/>  
</project>
Run Code Online (Sandbox Code Playgroud)

那么,我应该在这里插入什么代码,所以Ant在完成编译后将编译后的(myfile.jar)复制到另一个文件夹(../myfolder/).我想要的是创建一个公共文件夹,其中所有项目都将其可分发文件复制到其中,并且该文件夹永远不会被清除,其中的文件应该只被替换.

谢谢.-

ant build.xml jar

3
推荐指数
2
解决办法
4791
查看次数

Java时钟同步

我必须在新德里,香港,法兰克福,华盛顿等不同地方的屏幕上显示多个时钟.这些时间正在像其他任何真正的时钟一样变化,但是作为时间 - 左到固定的日期时间,它们被添加到用户添加它们时在不同时刻的屏幕.例如:

New Delhi       1d 4h 20 min 5s
Hong Kong       9h 2min 55s
Washington      22min 3s
...
Run Code Online (Sandbox Code Playgroud)

我有一个类,它使所有的计算以这种格式获得那些时间.当这些时间显示在屏幕上时出现问题.如何让他们同时更新时间?因此,秒中的所有更改都会同时显示.我知道理论上它不会在同一时间,但最接近它.这是我正在使用的计时器:

Timer t = new Timer();   
t.scheduleAtFixedRate(
    new TimerTask()
    {
        public void run() {
          Platform.runLater(new Runnable() {
              @Override
              public void run() {
                  label[id].setText(getTimeLeft(id));
              }
          });
        }
    },
    0,      // run first occurrence immediately
    1000);  // run every seconds
Run Code Online (Sandbox Code Playgroud)

此外,他们中的一些最终冻结.有没有人知道为什么?

java multithreading timer

2
推荐指数
1
解决办法
189
查看次数

chrome.scripting.executeScript:“函数未定义”错误

我正在编写一个 Chrome 扩展程序,并且有以下页面:

<html>
  <body>
    <button id="changeColor"></button>
    <script src="popup.js"></script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用这个 JS (popup.js):

let changeColor = document.getElementById("changeColor");

chrome.storage.sync.get("color", ({ color }) => {
  changeColor.style.backgroundColor = color;
});

changeColor.addEventListener("click", async () => {
    let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
  
    chrome.scripting.executeScript({
      target: { tabId: tab.id },
      function: setPageBackgroundColor,
    });

});
  
function setPageBackgroundColor() {
  chrome.storage.sync.get("color", ({ color }) => {
    document.body.style.backgroundColor = color;
  });
  // Here, it says: Uncaught ReferenceError: getElementByXpath is not defined
  console.log(getElementByXpath("xpath").textContent);
}
  
function getElementByXpath(path) …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension

2
推荐指数
1
解决办法
1725
查看次数

chrome.scripting.executeScript 传递参数

我的 Chrome 扩展程序的文件中有以下代码popup.js

chrome.scripting.executeScript({
  target: { tabId: tab.id },
  function: myFunc,
});


function myFunc() {
  // do something
}
Run Code Online (Sandbox Code Playgroud)

但是,我想从executeScriptto传递一个参数myFunc。像这样的事情:

chrome.scripting.executeScript({
  argument: {"arg1", "arg2"}
  target: { tabId: tab.id },
  function: connectCmd,
});


function myFunc(arg1: string, arg2: string) {
  // do something
}
Run Code Online (Sandbox Code Playgroud)

或同等的东西。有什么办法可以做到这一点吗?

javascript google-chrome-extension

2
推荐指数
1
解决办法
3663
查看次数

Java - 如何将Generic参数作为Class <T>传递给构造函数

我这里有一个问题仍然无法解决,问题是我有这个抽象类:

public abstract class AbstractBean<T> {
    private Class<T> entityClass;

    public AbstractBean(Class<T> entityClass) {
        this.entityClass = entityClass;
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在我有另一个继承这个抽象的类:

@Stateless
@LocalBean
public class BasicUserBean<T extends BasicUser> extends AbstractBean<T>  {
    private Class<T> user;    

    public BasicUserBean() {  
        super(user);  // Error: cannot reference user before supertype contructor has been called.
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何让它工作?,我试图让BasicUserBean类继承,所以如果我有继承BasicUserBean的PersonBean,那么我可以在Generic中设置实体Person,它也继承了实体BasicUser.它最终会成为:

@Stateless
@LocalBean
public class PersonBean extends BasicUserBean<Person>  {

    public PersonBean() {
        super(Person.class);
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

我只想继承BasicUserBean到所有后代的基本功能,所以我不必在所有后代中重复相同的代码.谢谢!.

java generics inheritance

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

C# - 在String中获取整数字节数组

我有一个随机整数值,我需要在String中表示为Byte数组.例如:

int value = 32;
String strValue = getStringByteArray(value);
Console.WriteLine(strValue); // should write: " \0\0\0"
Run Code Online (Sandbox Code Playgroud)

如果value = 11那么getStringByteArray(value)shuld返回"\v\0\0\0".

如果value = 13那么getStringByteArray(value)shuld返回"\r\0\0\0".

等等.

有关如何getStringByteArray(int value)在C#中实现该方法的任何想法?

UPDATE

这是从C#NamedPipe服务器接收数据的代码:

bool CFilePipe::ReadString(int m_handle, string &value)
{
   //--- check for data
   if(WaitForRead(sizeof(int)))
     {
      ResetLastError();
      int size=FileReadInteger(m_handle);
      if(GetLastError()==0)
        {
         //--- check for data
         if(WaitForRead(size))
           {
            value=FileReadString(m_handle,size);
            return(size==StringLen(value));
           }
        }
     }
   //--- failure
   return(false);
}
Run Code Online (Sandbox Code Playgroud)

c# arrays encoding character-encoding

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

字符串比较长度不匹配

我正在比较两个字符串,一个我从一个32字符的服务器收到的字符串和另一个我使用以下代码计算的字符串:

string getMd5(string fileName)
{
    using (var md5 = MD5.Create())
    {
        using (var stream = File.OpenRead(fileName))
        {
            return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "??").ToLower();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,即使两个字符串看起来相同,比较也会失败,因为上面函数返回的字符串包含的字符多于我收到的字符.请看附图:

在此输入图像描述

那么,我该如何解决这个问题呢?

谢谢.

c# string md5

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