I am building my project with maven-shade-plugin and Netbeans 8.0 is complaining with the following warning:
Project's main artifact is processed through maven-shade-plugin
When the final artifact jar contains classes not originating in current project, NetBeans internal compiler cannot use the sources of the project for compilation. Then changes done in project's source code only appears in depending projects when project is recompiled. Also applies to features like Refactoring which will not be able to find usages in depending projects.
How can I fix this? What can it break?
I found a "fix" by following the instructions over in Apache's Maven Docs
I added the following to my pom in the shade plugin section.
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName> <!-- Can be any name that makes sense -->
</configuration>
I now have 2 artifacts but it works for my needs.
typically it's a problem in projects depending on this one.
While the jar file in local repo contains classes from it's own dependencies, the src/main/java folder doesn't contain them. That confuses the java engine when it attempts to re-compile the changes done locally in the editor.
there is no way to "fix" it. it's been placed there after repeated bugs were filed against the editor showing compile errors where there were none. I think there is an issue filed for letting the user have the warning disappear.
Related
I am building my project with maven-shade-plugin and Netbeans 8.0 is complaining with the following warning:
Project's main artifact is processed through maven-shade-plugin
When the final artifact jar contains classes not originating in current project, NetBeans internal compiler cannot use the sources of the project for compilation. Then changes done in project's source code only appears in depending projects when project is recompiled. Also applies to features like Refactoring which will not be able to find usages in depending projects.
How can I fix this? What can it break?
I found a "fix" by following the instructions over in Apache's Maven Docs
I added the following to my pom in the shade plugin section.
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName> <!-- Can be any name that makes sense -->
</configuration>
I now have 2 artifacts but it works for my needs.
typically it's a problem in projects depending on this one.
While the jar file in local repo contains classes from it's own dependencies, the src/main/java folder doesn't contain them. That confuses the java engine when it attempts to re-compile the changes done locally in the editor.
there is no way to "fix" it. it's been placed there after repeated bugs were filed against the editor showing compile errors where there were none. I think there is an issue filed for letting the user have the warning disappear.
I just produced my first parent-module project with maven, and successfully installed it. Can I add this project as a dependency in another project, only by referring to the parent? My Eclipse IDE complains that it can't find the parent.jar, but that is not a surprise, as it is packaged as parent.pom.
Question:
So is it possible to add a parent (.pom) dependency, and get all transitive dependencies for free, or do I have to add .jar's.
Bonus Question:
Is it possible to add dependencies to other packaging formats as well, like a war? I can't really figure out how that would work, or why I would need that at this point though. Just curious.
Disclaimer:
I'm still learning maven, and find the philosophy and theory of it to be great. However, there are so many pits and reefs that seems to pop out, and more than once, I struggle to see if I'm trying to do something impossible, or if there is another mistake in configurations I.E. Right now Eclipse says it can't find any of my .m2 referenced dependencies in this one particular project. I have no idea why, as other projects works fine. I am in other words trying to find the error, by checking one area at the time...
Answer: Yes, you can add different types such as pom, test-jar and so on. Jar is just the default
Bonus Answer: Yes, you can specify type war as well
The Maven-Guide defines the following types: "The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par."
Here is a example on how a POM is included:
<dependencies>
<dependency>
<groupId>com.my</groupId>
<artifactId>comm-group</artifactId>
<type>pom</type>
</dependency>
</dependencies>
This (the pom of comm-group) is oftenly used to group certain dependencies and include all of them using the type-pom.
Here is additional information on grouping: http://blog.sonatype.com/2009/10/maven-tips-and-tricks-grouping-dependencies/#.VFC7LR_JY8c Note that there are similar behaviours you could create using polymorphism.
I had my issues with maven when we migrated from Ant and i still have certain concernes on it (like were is the advantage of maven if 80% of our SWEs apply wrong scopes, types and so on leading to a massive drawback if they just 'need to add a fcking jar' as well as to refactorings lead by "maven gurus").
BUT: I can guarantee you that if you go throught http://maven.apache.org/pom.html completely you will aquire statisfieing results compared to ANT over time.
Update: I just ran into the case where my pom could not be included on the remote build server while it worked building it from inside Intellij Idea/ Eclipse. Type definition in my case had to be lowercase (e.g. 'pom' instead of 'POM').
I am converting a large Java project to use maven. I have a LOT of inter dependencies to work out, but I would like to get it off the ground with maven before I do the real cleanup work. I have broken it up into a few modules plus one giant module; let's call that module monolith.
Monolith has regular Java classes and some gwt classes (with interdependencies). I separated the two parts to have a directory structure like this:
./src/main/java/...
./src/client/gwt/...
So, I can easily get this to compile in eclipse with m2eclipse, but then I can't seem to find how to get it to compile with maven. I saw that the pom file has a build section where you can specify an alternate source and target, but I think it is not a repeatable attribute in the pom:
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
</build>
In eclipse, I can adjust the project's .classpath file (in the project properties) to add additional source files (and output dirs) to accomplish what I am looking to do.
Is there any way to do this, or do I need to work out the dependencies first, and separate into separate modules?
If you go against the grain with maven it will be an uphill battle all the way.
Maven doesn't lean towards multiple main source directories, they would do better in maven environment as separate modules.
I've looked at a number of maven gwt projects and archetypes, and none of them seem to take the approach you've suggested.
Have a look at the source structure used by Hupa, also see the archetypes from the Ham and Eggs blog
http://hamandeggs.wordpress.com/2010/01/26/how-to-gae-eclipse-maven/
http://hamandeggs.wordpress.com/2010/07/25/gae-eclipse-maven-update-for-helios/
These also cater for App Engine.
If you really need to separate your java server source from your gwt client source, then monolith needs to be split into more modules.
It is quite common to see gwt projects with a package structure as follows:
com.company.project
.client
.server
.shared
And then specify the source paths in your gwt.xml to include client and shared
What you have is called a maven multi-module project. Take a look at this tutorial on the maven book.
So, I can easily get this to compile
in eclipse with m2eclipse, but then I
can't seem to find how to get it to
compile with maven.
-- I am not sure what you meant by this. M2Eclipse plugin is using maven to build your modules. Perhaps you can clarify this section. Hope the tutorial link helps you.
try to follow this tutorial http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html
main idea- start from creation of empty project from maven mvn archetype:create and then put you sources to created by maven structure...
also i can strongly recommend to check your dependency tree and effective pom with eclipse plugin tool when you perform this task (for avoid duplicate in dep. & other bad things)
I am trying to figure out the use of Maven and I got many articles describing its features and uses. But I am just not able to understand the actual use of Maven from productivity standpoint.
From what I am used to in our school projects was just create a new Java project in Eclipse, write your Code, create a .war (if web-based) and paste the code to the webapps folder of Tomcat and start the server!
So,
Where does Maven come into picture? I have used Ant and I understand Ants benefit of a standardized build process. But why do we need an advanced Ant in form of Maven?
In any case, I need to use it, so where do I get started - basic flow, some good tutorials?
Thanks
Maven is used to manage the build, testing, and deployment processes. It can separate the unit tests and integration tests so you only run them when necessary and cut down on build time.
It is also a dependency manager, which means when you realize the server piece of your project needs apache commons-logging 1.0.4 but the client conflicts with anything past 0.7.9, you can just add a couple lines to the respective pom.xml files, and Maven handles all of that (downloading, installing, and keeping track of the different versions of those dependencies).
I was not a believer before my current task, but after 2 years using it for large enterprise applications, I definitely respect what Maven brings to the table. There are a lot of online resources but if you are going to be the lead on this and really feel uncomfortable, I recommend getting a book -- the O'Reilly one is helpful.
Forgot to mention that there is an Eclipse plugin which makes it almost painless to use with Eclipse: m2Eclipse.
Second update for example pom.xml segment to answer OP question:
Your pom.xml will contain XML code such as:
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
These are downloaded from the central Maven repository (google "maven nexus") or you can configure your own additional repositories (like for your own projects, or if you are not Internet-connected).
I had exactly the same perception as you and for years I avoided Maven.
The thing is, it allows you to easily get the required jars your application may need( called dependencies - jars and other things - ) . So the next time somebody else run your project he will get the jars automatically.
I know that's a bit hard to grasp, until you work with an existing projects using it.
For instance I downloaded an open source project recently, which depended on 10 or 12 different on different jar versions. After downloading the source code and executing Maven, all those jars ( and a lot more others ) were downloaded for me.
The problem with Maven ( as a friend of mine told me ) is that to perform a "Hello world" program, it first downloads the world to greet him. :P
for all those wondering where the maven downloads the dependency jars, check out a folder named .m2 in the user root directory. eg. for me it is the c:\documentsand settings\myUserName.m2\
also i have researched a bit on maven and i have made some small scribbling like reminders. If it is worth a read then here it is ::
/*
mvn generate
mvn install downloads all necessary jars
mvn test tests the application made...
mvn site builds the site downloading dependencies
to deploy the site, we need to declare a location to distribute to in your pom.xml,
similar to the repository for deployment.
...
website
scp://www.mycompany.com/www/docs/project/
...
mvn site-deploy deploys the site
how to build structure of site :
The site.xml file is used to describe the layout of the site, and replaces the navigation.xml file used in Maven
A sample is given below:
Maven
http://maven.apache.org/images/apache-maven-project.png
http://maven.apache.org/
http://maven.apache.org/images/maven-small.gif
<menu name="Maven 2.0">
<item name="Introduction" href="index.html"/>
<item name="Download" href="download.html"/>
<item name="Release Notes" href="release-notes.html" />
<item name="General Information" href="about.html"/>
<item name="For Maven 1.x Users" href="maven1.html"/>
<item name="Road Map" href="roadmap.html" />
</menu>
<menu ref="reports"/>
...
so in effect, we need to link our html to this structure format to make the website layout
also in order for us to add any new css or such stuff, all we need to do is to put them into the resources part of the
src folder
then we can create a war file of our project and lay it out in the httpd folder of apache or such similar folder ofour web server
In case we need to generate projects, we need to add a few lines of code to our pom.xml file and that is:
...
org.apache.maven.plugins
maven-project-info-reports-plugin
2.0.1
...
also, site descriptors are to be set in site.xml
the details can be seen in the documentation of maven
maven structure with their importance:
project/
pom.xml - Defines the project
src/
main/
java/ - Contains all java code that will go in your final artifact.
See maven-compiler-plugin for details
scala/ - Contains all scala code that will go in your final artifact. ////not needed for our current project as of yet
See maven-scala-plugin for details
resources/ - Contains all static files that should be available on the classpath
in the final artifact. See maven-resources-plugin for details
webapp/ - Contains all content for a web application (jsps, css, images, etc.)
See maven-war-plugin for details
site/ - Contains all apt or xdoc files used to create a project website.
See maven-site-plugin for details
test/
java/ - Contains all java code used for testing.
See maven-compiler-plugin for details
scala/ - Contains all scala code used for testing.
See maven-scala-plugin for details
resources/ - Contains all static content that should be available on the
classpath during testing. See maven-resources-plugin for details
mvn validate this will validate that all the dependencies are satisfied and nothing is missing
mvn compile this will compile the project
mvn verify checks whether the package is valid or not
also in the project, the dependencies are to be inserted into the xml file
the example of dependencies injection is given below::
org.scala-lang
scala-library
2.7.2-rc2
junit
junit
3.8.1
test
Each dependency consists of several items:
* groupId - The group of the dependency to rely on
* artifactId - The artifact in the group to rely on
* version - The version of the dependency to rely on
* scope - The "scope" of the dependency. Defaults to compile (more details later)
* packaging - The packaging for the dependency. Defaults to jar (e.g. jar, war, ear)
You can integrate your static pages by following these steps:
* Put your static pages in the resources directory, ${basedir}/src/site/resources
* Create your site.xml and put it in ${basedir}/src/site
* Link to the static pages by modifying the menu section, create items and map them to the filenames of the static pages
mvn tomcat:deploy to deploy to tomcat or apache, you can go for this command
Free books about Maven can be downloaded from Sonatype (where the original developers of Maven come from).
Also see the documentation on the Apache Maven website.
Where does Maven come into picture? I
have used Ant and I understand Ants
benefit of a standardized build
process. But why do we need an
advanced Ant in form of Maven?
Maven introduced "convention over configuration" this helps if some colleagues write bigger ant scipts than code. plus dependency management, the only trouble is to convert monolithic projects with many artifacts.
In any case, I need to use it, so
where do I get started - basic flow,
some good tutorials?
I found these tutorials
And Maven: The Definitive Guide
helpful.
The latest netbeans also has a pretty good maven integration.
If you are within an organization, try to build a maven repository proxy. Artifactory is a good option.
Hi all I'm new to apache maven. I imported a project into netbeans everything seems well but i get this error when trying to build it:
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Property "loadVersion" is required for this build.
I think this means that the version of one of the dependencies in the pom.xml file are wrong but not sure.
Any help is appreciated.
More detail from the question poster:
I'm working on a small part of a project and the part I'm working on has a pom.xml file. This file doesn't have any enforcer rules. However the top level (or highest level pom.xml file) does have an enforcer rule with the required version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
</plugin>
Shouldn't this be enough?
More details from the OP:
It seems I could have just commented this line out in the top level pom file:
<requireProperty>
<property>loadVersion</property>
</requireProperty>
But then I would get other errors. I then read the project sites thoroughly and found out that the project's code can and only should be built with their provided build scripts. When building with their scripts the build is successful. This is good and bad it because now I have to edit code in the IDE and then build it in the terminal, but at least it's a solution.
Your project is using the Maven Enforcer Plugin which is somewhere configured (in a parent POM, in an active profile) to "enforce the existence and values of properties" using the requireProperty rule, in your case a loadVersion property.
Declaring such a custom property with Maven can be done in a pom.xml directly under the project element or in a profile or in a profile in the settings.xml by adding the following:
<properties>
<loadVersion>someValue</loadVersion>
</properties>
And this property can then be referenced by ${loadVersion}. I have of course no idea of the value that should be set.
See also
POM Reference
The complete reference for the POM structure
Settings Reference
I'm going to guess that your pom.xml uses the enforcer plugin and that you have not defined the loadVersion property as per the rule constraints.