Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best place to store your JAR's and other libs in Mac OS X

Tags:

java

macos

My question is simple: what is the best place to store all my jar's, gwt and other frameworks on mac os x ?

I thought that it is /Library/Java/Extensions. But I'm not sure that it is correct.

like image 498
Igor Konoplyanko Avatar asked Mar 17 '11 19:03

Igor Konoplyanko


People also ask

Where are JAR files stored on Mac?

The /Library/Java/Extensions directory can be used for additional jar files or JNI libraries that need to be placed on the system classpath. For more controlled access, the ~/Library/Java/Extensions directory can be used for user-level installation of support libraries.

Where is Library Java Extensions?

For Windows, the JDK extension directory is located at " <JAVA_HOME>\jre\lib\ext " (e.g., " c:\Program Files\Java\jdk1. 8.0_xx\jre\lib\ext "). For Mac, the JDK extension directories are " /Library/Java/Extensions " and " /System/Library/Java/Extensions ".


4 Answers

There are two ways to install java stuff:

  • Use a package manager like Homebrew or MacPorts,
  • Or do things your own way.

As a sample, here is how MacPorts installs Tomcat:

/Library/LaunchDaemons/blah.blah.start.Tomcat.daemon
/opt/local/etc/LaunchDaemons/blah.blah.plist
/opt/local/bin/start-tomcat-script
/opt/local/share/docs/...tomcat docs
/opt/local/share/java/...tomcat classes

You don't want to mimic that manually because it's an insane amount of work and there is no benefit. You either sudo port install tomcat6 or uncompress the whole Tomcat in /Users/YOURUSER/java/apache/tomcat/6/ and add bin to the path. Same thing for SDKs.

If you want to install just jars (not SDKs), use Maven as much as you can. You said something about trouble adding to your local repository. That's not correct, you can have several repositories and enable/disable them per project. I have one for the stuff maven downloads, and another one where I manually add things. If you are the only user of your machine put the repo somewhere inside your home, otherwise use /opt/local/var/ or anywhere you like.

Don't overthink it, it's about you getting work done.

like image 181
Jano Avatar answered Nov 14 '22 15:11

Jano


Your .m2 repository? Are you not using Maven for resolving your dependencies?

like image 40
jiggy Avatar answered Nov 14 '22 17:11

jiggy


It is a very bad idea to install libraries in system folders, as it will influence all Java programs running on your computer, and may conflict with other libraries carried properly along by the individual programs.

A much better approach is to create executable/runnable jars in which the Class-Path attribute points to the jars you need.

like image 30
Thorbjørn Ravn Andersen Avatar answered Nov 14 '22 15:11

Thorbjørn Ravn Andersen


Normally, you'd want to store libraries in the projects that use them rather than at the system level. Using a technology such as Maven would be an excellent way to do this.

UPDATE: Now that I know you're using maven, the suggestion changes a bit. I understand that you don't want to just manually install libraries into your local repository, which makes sense. My response would be that this is a LOT cleaner than dumping them in some global library folder. (And you avoid getting all of the anti-LD_LIBRARY_PATH people up in arms :) ).

Another thought would be to setup your own maven repository and keep your libraries there.

It really comes down to what you are trying to do. Do you just want to write some code that'll never leave your box or do you want a nice portable solution or what? We definitely need a bit of context.

like image 1
Jon7 Avatar answered Nov 14 '22 16:11

Jon7