1

Is there a way to use %UserProfile% when specifying paths in a Eclispe .classfile? I have a project that contains the following line in its .classfile:

<classpathentry kind="lib" path="C:/Users/<username>/.ivy2/cache/somelib.jar"/>

Is there a way to specify this in a more portable way that can be checked into a repository and used by different users? In particular I'd like to get rid of the C:/Users/<username> part of the path.

I see two possible ways to solve the problem, but don't know how to implement either of them:

  1. Use %UserProfile% in the path to refer to the users directory. On Linux, one could use ~, but this does not seem to work on Windows.
  2. Use an environment variable that specifies the location of the ivy cache.

Any hints how to do either of these things, or how to solve the problem in an other way would be appreciated.

Background: The project is a Scala project that is built using sbt, which manages dependencies with ivy.

stefan
  • 1,135
  • 1
  • 11
  • 22

3 Answers3

2

Have you thought about just using the sbt eclipse plugin to manage your eclipse project?

https://github.com/typesafehub/sbteclipse

This generates a project which you can import in your workspace.

Ivan Meredith
  • 2,222
  • 14
  • 13
  • Thanks. Yes, I have considered doing this. In fact, the Eclipse project has been generated with sbteclipse originally. However, the generated does not work for us, for the following reason: We have two projects, let me call them 'a' and 'b', where a depends on b. The dependency is managed through sbt, thus the jar of b will be in the ivy cache and is referenced in a. However, for a's Eclipse project, we would rather have a dependency on b's Eclipse project, so that e.g. refactorings work across both projects. – stefan Oct 20 '12 at 07:22
  • Sbteclipse should handle project dependencies just fine, as long as you define them in the Sbt build file as project dependencies – Iulian Dragos Oct 21 '12 at 11:30
  • Yes, sbteclipse handles mutli-projects fine - I use it for this myself. – Ivan Meredith Oct 22 '12 at 00:49
  • Currently, sbteclipse generates non-portable classpath metadata (ie absolute paths to the ivy repo). Like Stefan, I would prefer if it would generate portable .classpath files that, once correct, can be checked into git and "just work" for everyone who checks out. I note that sbt-idea is better at this, eg `` – Ben Hutchison Jun 08 '13 at 10:38
1

Another option is that a classpath container can be used. [I didn't try that for Ivy.]

http://ant.apache.org/ivy/ivyde/history/latest-milestone/cp_container.html

Classpath variables (Option 2 which you mentioned) is possible too.

Right click on project > Configure Build Path > Add Variable > Configure variables > New variable [create one with a proper name] > OK > Extend [select the jars which you need to use].

Your classpath should be updated. Your project team needs to follow the same procedure in this case.

ram
  • 747
  • 2
  • 11
  • 34
-2

from another stack overflow entry: does this work for you?

System.getenv(String name), which I guess would be or System.getenv("USERPROFILE") System.getenv("%USERPROFILE%") - the "answer" link below isn't as naive as my simple asssumption

Can we read the OS environment variables in Java?

Community
  • 1
  • 1
qaweb
  • 71
  • 1
  • 3