标签: properties-file

如何加载java属性文件并在Spark中使用?

我想将Spark参数(如输入文件,输出文件)存储到Java属性文件中,并将该文件传递给Spark Driver.我使用spark-submit提交作业但找不到传递属性文件的参数.你有什么建议吗?

java properties-file apache-spark

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

Spring-Boot多模块项目加载属性文件

我有一个Spring-Boot-Application作为maven中的multimodule-Project.结构如下:

Parent-Project
|--MainApplication
|--Module1
|--ModuleN
Run Code Online (Sandbox Code Playgroud)

MainApplication项目中有main()方法类注释用@SpringBootApplication等等.此项目一如既往地自动加载application.properties文件.所以我可以使用@Value注释访问值

@Value("${myapp.api-key}")
private String apiKey;
Run Code Online (Sandbox Code Playgroud)

在我的Module1中,我也想使用属性文件(称为module1.properties),其中存储了模块配置.只能在模块中访问和使用此文件.但是我无法加载它.我尝试过@Configuration,@PropertySource但没有运气.

@Configuration
@PropertySource(value = "classpath:module1.properties")
public class ConfigClass {
Run Code Online (Sandbox Code Playgroud)

如何使用Spring-Boot加载属性文件并轻松访问这些值?找不到有效的解决方案.

我的配置

@Configuration
@PropertySource(value = "classpath:tmdb.properties")
public class TMDbConfig {

    @Value("${moviedb.tmdb.api-key}")
    private String apiKey;

    public String getApiKey() {
        return apiKey;
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}
Run Code Online (Sandbox Code Playgroud)

调用配置

@Component
public class TMDbWarper {

@Autowired
private TMDbConfig tmdbConfig;

private TmdbApi tmdbApi;

public TMDbWarper(){
    tmdbApi = …
Run Code Online (Sandbox Code Playgroud)

java spring properties-file spring-boot

19
推荐指数
2
解决办法
7363
查看次数

从属性文件中删除键和值?

我想删除存储在属性文件中的键和值.我怎样才能做到这一点????

java properties properties-file

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

加载多个属性文件

是否可以在Java中堆叠加载的属性?比如我可以这样做:

Properties properties = new Properties();

properties.load(new FileInputStream("file1.properties"));
properties.load(new FileInputStream("file2.properties"));
Run Code Online (Sandbox Code Playgroud)

并从两者访问属性?

java properties-file

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

Gradle - 从jar打包中排除文件

我想从建造的jar中排除 AMAuthN.properties.此文件一直显示在已编译jar的根文件夹中.该文件位于AMAuthN\src\main\resources\AMAuthN.properties项目文件夹根目录下.谢谢!

apply plugin: 'java'
apply plugin: 'eclipse'

version = '1.0'
sourceCompatibility = 1.6
targetCompatibility = 1.6

test {
    testLogging {
        showStandardStreams = true
    }
}

// Create a single Jar with all dependencies
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',  
            'Implementation-Version': version,
            'Main-Class': 'com.axa.openam'
    }

    baseName = project.name

    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it) 
        }
    }
}

// Get dependencies from Maven central repository
repositories {
    mavenCentral()
}

// …
Run Code Online (Sandbox Code Playgroud)

java gradle properties-file

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

"get"VS"getProperty"之间的区别

Properties myProp = new Properties();
myProp.put("material", "steel");

Properties prop1 = new Properties(myProp);

System.out.println(prop1.get("material") + ", " + prop1.getProperty("material"));
// outputs "null, steel"
Run Code Online (Sandbox Code Playgroud)

在它返回Object的条目/属性的意义上,是否与getProperty类似?使用get时为什么不返回'steel'?

java properties-file

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

需要bash shell脚本来从文件中读取名称值对

我有一个类似的文件

name1=value1
name2=value2
Run Code Online (Sandbox Code Playgroud)

我需要使用shell脚本和设置变量来读取此文件

$name1=value1
$name2=value2
Run Code Online (Sandbox Code Playgroud)

请提供可以执行此操作的脚本.

我尝试了下面的第一个答案,即获取属性文件,但如果值包含空格,我会遇到问题.它被解释为空格后的新命令.如何让它在空间存在的情况下工作?

shell properties-file

16
推荐指数
6
解决办法
4万
查看次数

PropertyPlaceholderConfigurer和.properties文件中的环境变量

我有一个带有PropertyPlaceholderConfigurer的Spring application-context.xml,用于从.properties文件中获取属性值.主文件夹和测试源文件夹具有单独的.properties文件.问题是我需要在.properties文件中使用环境变量.但是,当我按以下方式执行此操作时:

property.name=${env.SYSTEM_PROPERTY}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'beanName' defined in class path resource [com/example/applicationContext.xml]: Could not resolve placeholder 'env.SYSTEM_PROPERTY'
Run Code Online (Sandbox Code Playgroud)

而占位符配置器定义为

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:com/example/application.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

任何想法如何使property.name被解释为环境变量(而不是占位符)?

最好的问候,德米特里.

java spring environment-variables properties-file applicationcontext

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

Crashlytics在运行时没有在crashlytics.properties中找到API密钥

我目前正在实现此处建议的API密钥切换脚本,除了使用构建类型而不是flavor.我的build.gradle看起来像这样:

...
buildTypes {
    debug {
        ...
        set("crashlyticsApiKey", "API_KEY_1")
        set("crashlyticsApiSecret", "API_SECRET_1")
    }
    release {
        ...
        set("crashlyticsApiKey", "API_KEY_2")
        set("crashlyticsApiSecret", "API_SECRET_2")
    }
}
...
productFlavors{...}
...
File crashlyticsProperties = new File("${project.projectDir.absolutePath}/crashlytics.properties")

applicationVariants.all { variant ->
    variant.productFlavors.each { flavor ->
        def variantSuffix = variant.name.capitalize()
        def generateResourcesTask = project.tasks.getByName("crashlyticsGenerateResources${variantSuffix}")
        def generatePropertiesTask = task("crashlyticsGenerateProperties${variantSuffix}") << {
            Properties properties = new Properties()
            println "...copying apiKey for ${variant.name}"
            properties.put("apiKey", variant.buildType.crashlyticsApiKey)
            println "...copying apiSecret for ${variant.name}"
            properties.put("apiSecret", variant.buildType.crashlyticsApiSecret)
            properties.store(new FileWriter(crashlyticsProperties), "")
        }
        generateResourcesTask.dependsOn generatePropertiesTask
        def cleanResourcesTask …
Run Code Online (Sandbox Code Playgroud)

java android properties-file crashlytics build.gradle

15
推荐指数
2
解决办法
7847
查看次数

我如何使用或设置sonar-project.properties文件

我很少接触到SonarQube但都被要求做一个文件,解释如何设置/使用"sonar-project.properties文件".任何信息或输入将不胜感激.

properties-file sonar-runner sonarqube

14
推荐指数
2
解决办法
5万
查看次数