如何从Java项目中的所有Java文件中提取所有String? [英] How to extract all String from all Java files in a Java project?

查看:103
本文介绍了如何从Java项目中的所有Java文件中提取所有String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从中的所有 Java 文件中提取所有个硬编码字符串值Java项目

Java常量文件

I need to extract all hard coded Strings values from all Java files in a Java project
Into a Java Constant file

示例


输入



// Java file number 1
public class A {    
    public static void main(String[] args) {
        System.out.println("HardCoded String A");
    }
}

// Java file number 2
public class B {    
    public static void main(String[] args) {
        System.out.println("HardCoded String B");
    }
}




输出



// a Java Constant file
public class MyConstants {  
    public static final String HardCodedString_01 = "HardCoded String A";
    public static final String HardCodedString_02 = "HardCoded String B";   
}

// Java file number 1
public class A {    
    public static void main(String[] args) {
        System.out.println(MyConstants.HardCodedString_01);
    }
}

// Java file number 2
public class B {    
    public static void main(String[] args) {
        System.out.println(MyConstants.HardCodedString_01);
    }
}

我知道 Eclipse的外部字符串


但它可以在一个文件而不是所有文件

当我检查此帖子时,

从Java项目中提取所有字符串

我找不到提供的演示文稿的链接

And when i check this post
Extract all string from a java project
I could not find the link of provided presentation

我也检查此帖子

为Android项目扩展字符串 < br>
但这是为 Android 项目提供的,而不是 Java 项目

Also i check this post
Externalize strings for Android project
But that is provided for Android projects not Java projects

推荐答案

首先使用 Eclipse

首先检查所有硬编码的字符串值。核心思想是 Java硬编码字符串值

正则表达式 *

So

我们可以按照此条件使用搜索

例如

First to inspect all hard coded Strings values from all using Eclipse
The core idea is that
The Regular Expression of Java hard coded String value is "*"
So
We can do that Using search by this criteria
For example

Eclipse搜索查询

Eclipse Search Inquiry

Eclipse搜索结果

Eclipse Search Result

这篇关于如何从Java项目中的所有Java文件中提取所有String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆