What is the best place to store your JAR's and other libs in Mac OS X
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开发者_如何学C correct.
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.
Your .m2 repository? Are you not using Maven for resolving your dependencies?
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.
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.
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.
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.
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).
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.
精彩评论