I'm trying to manipulate an open source project, where I have made my changes and created the WAR file. The WAR file that I have created is an "dependency" for an another module.
The code for that "dependent" module uses org.eclipse.aether.artifact.DefaultArtifact like this:
public static DefaultArtifact getReportArtifact(String version) {
return new DefaultArtifact(ALLURE_GROUP_ID, ALLURE_REPORT_FACE_ARTIFACT_ID,"WAR", version);
}
to get the WAR and builds it jar.
I need to pass the my local WAR file, instead of it getting from the Maven repo. How can I do that?
Thanks in advance.
If I understand you correctly:
Maven: The Complete Reference, 3.4.1. Dependency Scope
system
[...] you have to provide an explicit path to the JAR on the local file system. [...] The artifact is assumed to always be available and is not looked up in a repository.
There are multiple approaches you can take. The most portable would be to specify an additional Maven repo in your project at a path inside (or relative to) ${project.basedir}. In there, you could install the artifacts you need, in the normal Maven fashion. This way, the build would be portable across environments without modifications.
But, I must say, I only half-understood the question as you never really explain what you're trying to achieve.
Related
I am newbie to maven. I have few questions on it.
I have to build a webapp and prepare a war out of it. I have put my web application under ..\src\main\webapp. And all classes of it, which were under web-inf\classes, i have copied to ..\src\main\java. And i have put pom.xml in the root directory.
I have numerous jars in web-inf\lib folder, on which my compilation of classes depends on. I want to add all those to my local repository. My local repository is default folder, which i have not changed in settings.xml. So, how do i put all these jars to my local repository? Just copying jars to local repository folder is not working.
Should i create a folder for each jar as per its groupid? Am i doing things correctly? Or i am missing something?
Kindly help. Thanks in advance!
To deploy to maven local repository you can use an install plugin:
http://maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html
Your question is confused enough. Firstly try to explain in a better way how to are doing?
If you are trying to add maven nature at your project (like I think) there are something to review.
I'm not able to understand when you say:
And all classes of it, which were under web-inf\classes, i have copied to ..\src\main\java
Usually in web-inf/classes there are the .class files, while in src/main/java there must be the source files. And this is an strange thing
Finally fon dependencies copy you have to just configure maven correctly and add all jar like project's dependencies. Then when you try to install you application maven will download the jars file in your folder
I have a maven-java project and I use git at the same time. Now I need to use some libraries which does not have any maven support. I have the .jar files of the libraries.
How will I add them to my maven project? and.. Will the other people who pull my code from my git repo be able to run my code without having the .jars?
If you have an artifact repository manager such as Nexus, Archiva, or Artifactory, you can deploy the jars to it. Then you can define them as dependencies in your pom.xml files.
If you don't, you can install them to your local repository using the maven-install-plugin using the install-file goal.
If you don't want to do that, there's also a not-recommended option of defining a dependency with <scope>system</scope> as illustrated here. Again, this is highly NOT recommended, as you would be expecting people would have the artifact on their file system and quite possibly, this jar might end up in your version control, which is really not the way to do it, but is also possible.
answer is that others will not be able to build your code unless some conditions are met.. As mentioned by carlspring, you would have to either install to your own local repo or put a system scope dependency.
if you add it to your local repo, then your local would have to be
some kind of common network writeable share/location that your entire team maps to in a standardized fashion in your development environment.
if you add a system scope dependency, you could actually put this jar into your codebase into a project relative lib directory and provide a path such as ${basedir}/lib/some.jar
I have a Netbeans Java Project under Subversion (svn). This is shared with another guy working on the project.
The project requires an external library that we have as a jar file. Now, when either of us makes a change and commits it, the project's library dependencies fail as we have different paths for the library ( as we are working on different machines the location of the jar file is different ).
This means that every time I update my repository, I have to resolve library dependencies.
Is there a way I can prevent this?
1st way: You can use NetBeans Library support.
Go to Tools->Libraries, and new Library with your jar. Name it the same way on both machines and include to your NB project as Library rather then direct path to jar.
2nd way: use relative path.
Agree on having jar located at ../lib/foo.jar and use this path in NB project
3rd way: use property file.
Add file named, for example, build.properties but don't commit it to svn. So both of you will have different local version of that file.
Content should be something like next:
myproject.library.foojar=C:/foopath/foo.jar
In your build.xml include this file:
<property file="../build.properties"/>
In your nbproject/project.properties find a reference to the jar -- it will look like:
file.reference.foo.jar=C:/foopath/foo.jar
change it to
file.reference.foo.jar=${myproject.library.foojar}
Also you may want to add build.properties into ignore list for svn to avoid commiting it.
I recommend you to use Maven to control library dependencies(jars). It is easy to use and NetBeans has a module to use it easily.
Maven download all the dependencies you declared into a local repertory so you don't need to worried about managing libraries, Maven do it for you.
Also with this module you can search libraries in the Maven repertory(Has a lot of java librarys) only you need to type the name and maven download it for you.
Here there are some links for how to use Maven With NetBeans:
http://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
http://today.java.net/article/2009/10/14/working-maven-netbeans-671
In Eclipse we have a project where we reference an external jar in the build path. When I upload my project to the repository and my colleagues check it out, the build path looks for the jar file in the same place. One of us uses a Mac so doesn't even have a C: drive and my other colleague has a different partition containing the jar, so it always breaks.
How do we fix this issue? Ideally the jar file would be included as part of the project but it seems that the svn commit doesn't include the referenced library.
Thanks
I would suggest you use a build tool (maven, ant/ivy, gradle, etc) along with a repository manager (such as nexus or archiva), depending on what you use to build your project. These store libraries in a central location(s) and then users get the libraries from there.
In eclipse, when you include your .classpath file in the checkin, you will have the issues you are describing, since the .classpath file will contain the path to the file, and then you all must have the files in the same locations. A workaround for this is to create a "lib" directory and put all of the libraries in there. Each of the users can then add all of the libraries in that directory to their path (but do not checkin the .classpath file). This is an older way of doing things before the concept of dependency managers.
Add the jar as part of the project (say in a lib folder in your project) and commit it to svn.
Start using Maven, to resolve your dependencies.
Worst case : Commit the external jar into another project called MyProjectDependencies
You can use Apache Maven to avoid incident like this and to get many others pluses.
You can find many guides on maven, for example this one.
Eclipse has integration with maven.
1.) Check in JAR in a directory inside the project.
2.) Use Maven (or something similar) to manage your dependencies.
3.) Create a User Library referencing the JAR and refer to it this way in your project. Each user will need to create the User Library in their install of Eclipse, but it sounds like you're already doing something similar by referencing the library externally anyway.
if you don't want to use a dependency management tool like Maven, a simple solution in your case would be to use an Eclipse Classpath Variable. All projects can reference the variable, but it will have a different value for each developer.
Set up a Classpath Variable with:
Right click on the Project, select Project Properties
Click Add Variable
Configure Variables
New...
Name the variable and point to a Folder
Now commit your .classpath file. The variable will be referenced in the .classpath. Each developer can configure to their particular directory, and Extend the variable to a specific jar file.
My project requires some external libraries to build in in Eclipse. They live in /trunk/lib whereas my project is in /trunk/projectA. To get Eclipse to find the libraries on all machines we set a variable PROJECT_A_HOME.
Now I'm trying to get some builds going with maven and I can not figure out how to add that path (be it environmental variable or relative to $(basedir)) to the build. I really do not want to set up a repository for these dependencies, as I keep them in source control and want builds to continue to work in Eclipse.
I've seen talk about but that hasn't worked for me.
Ideas ?
You should put your static configuration files in resources/ dir. If you have your own or proprietary jars you should set a your own repository so you can download them from the repository or better yet just install them manually , here is how
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Setting up a file-based repository as suggested in this previous question would allow to keep the libs in your version control system and work seamlessly at the Eclipse level (the libs would be treated like any other dependency). The only problem I can think of could be at the continuous integration level: a build of projectA would require a checkout of trunk/lib. Many CI tools would allow to implement this though. And if not, moving the libs under projectA (or another mavenized project project if you need to share them between modules) would do the trick.