8

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.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
Igor Konoplyanko
  • 9,176
  • 6
  • 57
  • 100

8 Answers8

6

There are two ways to install java stuff:

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.

Jano
  • 62,815
  • 21
  • 164
  • 192
4

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

jiggy
  • 3,828
  • 1
  • 25
  • 40
  • I'm using it. It's a good, but there exist libraries that don't exist in maven repository. I know I can add them to my local repo, but it's adds some difficulties. – Igor Konoplyanko Mar 17 '11 at 20:05
  • If you plan to release your work to the outside work one day (outside of your Mac machine), you can't put jars to any global location like /Library/Java/Extensions. You can have a look at this : http://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them – Nicolas Bousquet Apr 12 '11 at 09:40
2

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
1

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.

Jon7
  • 7,165
  • 2
  • 33
  • 39
  • Hi. Thanks for your answer. My task is simple: one internal developer provides me *.jar archive. I want to save it somewhere. I'm downloading some SDK (android SDK, GWT SDK, etc..) - I want to save it the same directory where all my jars are stored. – Igor Konoplyanko Mar 28 '11 at 14:20
1

Don't install jars in /Library unless you really know what you are doing (for example, maybe you need to install some encryption policy files). You'll be much, much better off if you keep your jars in a different location.

Since you're using Maven, you could specify a different local repository by creating a ~/.m2/settings.xml file:

<settings>
  ...
  <localRepository>/path/to/local/repo/</localRepository>
  ...
</settings>

Then, use Maven to install the jars in your local repo and off you go.

Personally, I keep my libraries under a folder like ~/dev/java/lib to keep them organized, and then I also install them using Maven into my local repo.

asinesio
  • 345
  • 1
  • 5
1

Ignoring needing Maven and Tomcat, you should put them in any folder that is included in your $JAVA_HOME environment variable. I would recommend that you create a directory, say

~/java

and set

JAVA_HOME=$JAVA_HOME:$HOME/java

Info on Environment Variables in OS X. Follow this for the bare instructions, but keep the JAVA_HOME line that's in the post. Add the line I have given you somewhere below the other definition. Something like this:

JAVA_HOME= < blah, blah >
JAVA_HOME=$JAVA_HOME:$HOME/java

Also note that if you use a system file like /etc/launchd.conf, you shouldn't use $HOME, as it may not be set yet. Use a full path to your folder instead, or use a file run when your user logs in instead.

I agree 100% with people who told you not to store your own files in system folders.

Community
  • 1
  • 1
James Broadhead
  • 1,878
  • 1
  • 16
  • 19
0

If you are running an application through command line (Terminal) and the app comes with a jar that is called through a shell script (.sh) a messy option (that unfortunately I use sometimes) would be to copy the jars to you /System/Library/Java/Extensions path.

I believe you're problem was the missing /System/ on your path.

Felipe Leão
  • 915
  • 2
  • 15
  • 27
0

You must have Tomcat for your local development. You could install Nexus on it and then have your own repository, which you could also easily relocate if you needed to at some future date (and it gives you the ability to add artifacts through a web interface rather than at the command line with the maven 2 step of pom and *ar).

Rob
  • 11,446
  • 7
  • 39
  • 57