小编ale*_*zio的帖子

在Web应用程序中引用jpa persistence.xml中的jar文件的正确途径是什么?

persistence.xml看起来像这样:

<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>jdbc/test</non-jta-data-source>
    <jar-file>../../lib/app-services-1.0.jar</jar-file>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

它是一个Web项目,因此部署单元是一个war文件.我试图引用的jar文件在WEB-INF/lib /文件夹中,persistence.xmlWEB-INF/classes/META-INF文件夹中.部署时,它只是告诉我

"警告:无法找到文件(忽略):file:.../../lib/app-services-1.0.jar".

我也试过,我能想到的,即每一个可能的路径../lib/app-services-1.0.jar,LIB /应用服务-1.0.jar.

这样做的正确途径是什么?

persistence hibernate jpa war java-ee-6

22
推荐指数
3
解决办法
3万
查看次数

将Iterator向前移动到for语句和while语句之间的区别

当我使用对象的Iterator时,我使用while循环(如每本书中学习Java,如Bruce Eckel的Thinking in Java):

Iterator it=...

while(it.hasNext()){
    //...
}
Run Code Online (Sandbox Code Playgroud)

但有时我看到的是有人使用for循环:

Iterator it=...
for (Iterator it=...; it.hasNext();){
    //...
}
Run Code Online (Sandbox Code Playgroud)

我不明白这个选择:

  • 当我有一个带有序数序列的集合(作为数组)或者有一个特殊的步骤规则(通常声明为一个简单的增量)时,我使用for循环counter++.
  • 我在循环结束时使用while循环,我没有这个约束,但只有退出的逻辑条件.

这是一个没有其他原因的样式编码问题,或者存在一些我不知道的其他逻辑(例如性能)?

感谢您的每一个反馈

java iterator for-loop while-loop

14
推荐指数
3
解决办法
4万
查看次数

如何计算功能点

这是一个关于理论计算的问题.我遇到了类似下面的问题;

考虑具有以下功能单元的项目:

  • 用户输入数= 50
  • 用户输出数= 40
  • 用户查询数= 35
  • 用户文件数= 06
  • 外部接口数= 04

假设所有复杂度调整因子和权重因子均为平均值,项目的功能点将为;

答案是672.这是如何计算的?

theory function-points computation-theory

7
推荐指数
1
解决办法
3万
查看次数

FileNameFilter和FileFilter的用法

我正在编写一个简单的程序,以递归方式列出目录中的.class文件.

最初我编码了这个:

public class Parsing{

    public static void main(String[] args) {
        File f=new  File(".\\");
        readRecursive(f);
    }

    private static void readRecursive(File f) {
        String[] files=f.list(  new FilterByteCode());
        if(null==files){
            files=new String[0];
        }
        for(String curr: files){
            File currFile=new File(curr);
            System.out.println(currFile.getName());
            readRecursive(currFile);
        }
    }
}//end parsing

class FilterByteCode implements FilenameFilter {


    @Override
    public boolean accept(File dir, String name) {
        if(name.endsWith(".class")){
            return acceptByteCode(dir);
        }else{
            return  (null!=dir && dir.exists() && dir.isDirectory());
        }

    }

        private boolean acceptByteCode(File dir) {
            boolean res= (null!=dir && dir.exists() && …
Run Code Online (Sandbox Code Playgroud)

java file filefilter

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

如何为 TfidfVectorizer 使用列表列表或集合列表?

我正在使用sklearn TfidfVectorizer进行文本分类。

我知道这个矢量化器需要原始文本作为输入,但使用列表可以(参见 input1)。

但是,如果我想使用多个列表(或集),我会收到以下属性错误。

有谁知道如何解决这个问题?提前致谢!

    from sklearn.feature_extraction.text import TfidfVectorizer

    vectorizer = TfidfVectorizer(min_df=1, stop_words="english")
    input1 = ["This", "is", "a", "test"]
    input2 = [["This", "is", "a", "test"], ["It", "is", "raining", "today"]]

    print(vectorizer.fit_transform(input1)) #works
    print(vectorizer.fit_transform(input2)) #gives Attribute error

input 1:
  (3, 0)    1.0

input 2:
Run Code Online (Sandbox Code Playgroud)

回溯(最近一次调用最后一次):文件“”,第 1 行,文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/feature_extraction/text.py”中,第 1381 行,在 fit_transform X = super(TfidfVectorizer, self).fit_transform(raw_documents) 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/feature_extraction/text.py ”,第 869 行,在 fit_transform self.fixed_vocabulary_) 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/feature_extraction/text.py”,第 792 行,在 _count_vocab 中对于分析(doc)中的功能:文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/feature_extraction/text.py”,第266行,在tokenize(预处理( self.decode(doc))), stop_words) 文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sklearn/feature_extraction/text.py”,第 232 行,作为回报lambda x: strip_accents(x.lower()) AttributeError: 'list' 对象没有属性 'lower'

python python-3.x scikit-learn text-classification tfidfvectorizer

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

Sax解析器不完全读取一行

我正在尝试解析一个simil- InkML文档.每个内容的节点都有更多的元组(用逗号分隔),带有6或7个数字(负数和小数).

在测试中,我看到SAX 的方法字符不记忆所有数据.

代码:

    public class PenParser extends DefaultHandler {

   //code useless

public void characters(char ch[], int start, int length) throws SAXException {
//begin my debug print
        StringBuilder  buffer=new StringBuilder ();
        for(int i=start;i<length;i++){
            buffer.append(ch[i]);
        }
        System.out.println(">"+buffer);
//end my debug print
Run Code Online (Sandbox Code Playgroud)

在调试中,我看到缓冲区不包含感兴趣的标记的所有数量,但它只包含标记内容的前107个(或多或少)char(我的行不长于4610个字符):这很奇怪该切的焦炭通过的StringBufferSAX解析,在我看来.

我也使用过StringBuilder,但问题仍然存在.

有什么建议?

java xml sax string-parsing

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

如何在类的注释内编写注释?

为了好玩,我正在尝试编写一个使用带有另一个注释的注释的类,但我不明白如何编码。

我的代码

第一个注释

@interface FirstAnnotation {
    String author();
}
Run Code Online (Sandbox Code Playgroud)

第二个注释包含第一个注释

public @interface SecondAnnotation {
    FirstAnnotation inside();
    int version();
}
Run Code Online (Sandbox Code Playgroud)

带注释的类

@FirstAnnotation(
    author = "alessandro"
)
@SecondAnnotation(
    version = 1,
    inside = /*Compilation code: what code? FirstAnnotation, this??*/   
)
public class GeneralClass {

    /*
     * a generic method
     */ 
    public void method() {
        System.out.println("method");
    }

}
Run Code Online (Sandbox Code Playgroud)

我必须在带有字符串编译代码的行中放入什么,作为类中FirstAnnotation实际值的参考?

java annotations

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