NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
difficult
Joined: 04 Jan 2009 Posts: 52
|
Posted: Mon Aug 22, 2011 2:00 pm Post subject: In maven web application,how can I refer to the jar in webapp/web-inf/lib |
|
|
| In eclise these libs are served as web application library,is there the similar way in netbeans? |
|
| Back to top |
|
 |
mdeggers
Joined: 28 Jan 2009 Posts: 208
|
Posted: Mon Aug 22, 2011 4:33 pm Post subject: |
|
|
I don't understand your question.
If you're using Maven to build your application. you don't put jars in the
project. Maven is designed for dependency management. NetBeans will
find the jars and resolve this while you're developing when you're
using Maven.
If a jar is already provided in your target environment - like servlet-api
would be in a web application server - just mark the jar as provided
in pom.xml.
If you need jars excluded due to conflicting dependencies - like a group
of jars that go along with log4j-1.2..15 - then mark them in an exclusions
block.
Once you package the application, the jars will be placed in:
<Project-Name>/target/<target-name>/WEB-INF/lib
The war file will be built and placed in:
<Project-Name>/target/target-name.war
Maven will also place a versioned copy of your war file (and all of the
maven information) in:
~/.m2/repository/<org-name>/<target-name>/<version>
The war file will be named target-name-version.war.
Change the location of .m2 if you're on Windows or a Macintosh.
If Eclipse behaves differently, then Eclipse is broken with respect to
Maven.
. . . . just my two cents.
/mde/ |
|
| Back to top |
|
 |
difficult
Joined: 04 Jan 2009 Posts: 52
|
Posted: Tue Aug 23, 2011 2:41 am Post subject: |
|
|
thanks to mdeggers.
In my web project,I have some private jars which I want use them ,but I can't import them in class in netbeans java editor. I want to know how to configure it? |
|
| Back to top |
|
 |
mdeggers
Joined: 28 Jan 2009 Posts: 208
|
Posted: Tue Aug 23, 2011 6:10 am Post subject: |
|
|
This is really more of a Maven question than a NetBeans question.
I'll outline the solutions, but you should read up on the
Maven-centric ones by searching the 'net.
1. Run your own repository server
This is the preferred solution. Install something like the following:
Archiva (archiva.apache.org)
Nexus (nexus.sonatype.org)
Then, depending on the behavior you want, configure your local system
to either use the local repository as the only one, or as an
additional repository.
For straight Maven (ie., outside of NetBeans), you would add your
repository as the only one in ~/.m2/settings.xml. For Archiva, the
instructions for doing so are here:
http://archiva.apache.org/docs/1.3.5/userguide/using-repository.html
Doing this inside of NetBeans is also not difficult. You can add your
own repository, and then the repository browser, code completion,
etc. will all work with that. Instructions for doing that are here:
http://wiki.netbeans.org/MavenBestPractices
Look under Utilizing and Managing Maven repositories for the
information.
Since both Archiva and Nexus act as proxies to any central
repositories you configure, they'll automatically pull down
dependencies that you don't have.
This is really the preferred setup for a corporate development
environment, and not too difficult to set up for a personal
development environment.
OK, that was long, unpleasant, and overly complicated. However, it's
the "right" way to do things.
Now for something quick and dirty.
2. Add the jar and POM to your local repository
This makes for unportable builds, since everyone using your pom.xml
file will have to have the jar installed in their local repository in
exactly the same manner that you have.
From:
http://maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html
| Code: | mvn install:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar \
-DlocalRepositoryPath=path-to-specific-local-repo
|
For example, let's say you have a jar file of foo-1.23.jar, containing
the following structure:
| Code: | org/bar/foo/AClass.class
org/bar/foo/Another.class
org/bar/foo/util/Util.class
.
.
. |
You might then install it as:
| Code: | mvn install:install-file -Dfile=foo-1.23.jar \
-DgroupId=org.bar \
-DartifactId=foo \
-Dversion=1.23 \
-Dpackaging=jar |
This will put the jar in:
~.m2/repository/org/bar/foo/1.23 on UNIX/Linux/Macintosh, and in the
appropriate spot on Windows.
You can then start up a new Maven project and add the dependency. You
can either edit pom.xml directly, or you can do the following.
a. right-mouse click on the Dependencies node in the Project view
b. select Add Dependency
c. fill in the blanks:
Group Id: org.bar
Artifact Id: foo
Version: 1.23
d. leave scope as compile
Now everything should work as you expect. Code completion works,
imports automatically work, implementing all abstract methods from
interfaces work.
When you build your WAR file, everything should be included in the
proper spot (WEB-INF/lib for dependent jars).
3. Forego Maven
Use a standard NetBeans project and add the jars manually.
. . . . just my two cents.
/mde/
PS - I just did this with a sample library jar and a Maven web application. It worked as advertised. |
|
| Back to top |
|
 |
difficult
Joined: 04 Jan 2009 Posts: 52
|
Posted: Tue Aug 23, 2011 9:50 am Post subject: |
|
|
| so detailed ! thank you,mdeggers . |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|