1

I have two java projects A and B, If I have a credentials.properties file in A and I want to access the same properties file in project B, Is there a way I can achieve this?

The two projects are maven build.

Slayer
  • 832
  • 1
  • 6
  • 21
  • why don't you copy the file into the new project? how large can a credential file be in size? – Juvanis Jul 24 '13 at 05:29
  • 1
    @Juvanis: Copying resources between files can lead to out of date properties in projects, leading to hard-to-track bugs and aberrant behavior in the application. – Makoto Jul 24 '13 at 05:35
  • @juvanis We should not make obviate duplicacy. – Slayer Jul 24 '13 at 05:49

3 Answers3

0

Try this:

<resource>
                <directory>${other projects dir}/src/main/resources</directory>
                <includes>
                    <include>*.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>

Give the path as a full path

Neron
  • 1,500
  • 7
  • 30
  • 52
  • That's going to result in the properties file from project A being packaged up in project B. If that's good enough, then this approach works; if not, you can create a project dependency from B to A and then load the properties file as a resource using [getResourceAsStream()](http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream%28java.lang.String%29) or similar approaches. – Tim Jul 24 '13 at 05:38
  • @Tim Actually I have an X project which depends on A and B so the pom of X contains the reference of A and B. – Slayer Jul 24 '13 at 05:47
  • @Prerit Tim is also right. That situation that u have mentioned is not a problem for that solution also. – Neron Jul 24 '13 at 05:54
  • Can I achieve this at project level? – Slayer Jul 24 '13 at 06:17
0

Keep the property file in the class path of B and set Project B as a dependency to project A.

Sanjaya Liyanage
  • 4,706
  • 9
  • 36
  • 50
0

Commiting cleartext passwords into your source control is normally a bad idea...

How about using a shared Maven profile in your settings file? ($HOME/.m2/settings.xml):

<settings>
    ..
    <profiles>
        <profile>
            <id>credentials</dev>
            <activeByDefault>true</activeByDefault>
            <properties>
                <password1>XXXXX</password1>
                <password2>YYYYY</password2>
                ..
                ..
            </properties>
        </profile>
        ..
    </profiles>
    ..
</settings>

This approach is more Maven friendly and encryption is supported.

If you use Jenkins to build your code, you can use a plugin to manage the settings file centrally:

Your project can still have a default value, the key point is that the real passwords are set externally to files under source control.

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185