Adding to the classpath on OSX

后端 未结 5 644
野趣味
野趣味 2020-11-29 17:24

Can anyone tell me how to add to the classpath on OSX?

相关标签:
5条回答
  • 2020-11-29 17:53

    If you want to make a certain set of JAR files (or .class files) available to every Java application on the machine, then your best bet is to add those files to /Library/Java/Extensions.

    Or, if you want to do it for every Java application, but only when your Mac OS X account runs them, then use ~/Library/Java/Extensions instead.

    EDIT: If you want to do this only for a particular application, as Thorbjørn asked, then you will need to tell us more about how the application is packaged.

    0 讨论(0)
  • 2020-11-29 18:12

    Normally there's no need for that. First of all

    echo $CLASSPATH
    

    If there's something in there, you probably want to check Applications -> Utilites -> Java.

    0 讨论(0)
  • 2020-11-29 18:14

    If your shell is tcsh or csh, you can set it in /etc/profile. Open terminal, "vim /etc/profile" and add the following line:

    setenv CLASSPATH (insert your classpath here)

    0 讨论(0)
  • 2020-11-29 18:16

    To specify a classpath for a single Java process, you can add a classpath option when you run the Java command.

    In you command line. Use java -cp "path/to/your/jar:." main rather than just java main

    The option tells Java where to search for libraries.

    0 讨论(0)
  • 2020-11-29 18:18

    In OSX, you can set the classpath from scratch like this:

    export CLASSPATH=/path/to/some.jar:/path/to/some/other.jar
    

    Or you can add to the existing classpath like this:

    export CLASSPATH=$CLASSPATH:/path/to/some.jar:/path/to/some/other.jar
    

    This is answering your exact question, I'm not saying it's the right or wrong thing to do; I'll leave that for others to comment upon.

    0 讨论(0)
提交回复
热议问题