Trying to compile Maven with clean parameter:
C:> mvn clean
and got the exception below:
Cannot execute mojo: clean. it requires a project with an existing pom.xml, but the buid is not using one.
can anyone tell me how I can associate my existing project to maven.
Maven uses a file called pom.xml to build. It should be located in the root of your project.
Maven works on the basis that your project conforms to the Maven way of doing things and so I would recommend reading the Maven Getting Started Guide to familiarize with the standards before starting to use Maven.
I think you need to read up on a bit of documentation. Basically it is the pom.xml file it is complaining about that defines how maven should handle your project.
This explains how you can use maven to generate an example project.
This goes in more depth and also provides some links to other resources.
suppose your project is in 'C:\MyProject' where you can see a pom.xml file, open command prompt, go to C:\MyProject and type 'mvn clean' as follows:
> cd C:\MyProject
> mvn clean
The project you are compiling is not a maven project.
Related
I had a GWT app, and I wanted to automate its build and deploy system, since I do it manually. But I did not find a way how to build the app from command line, so it can than be automated. I had to click the Google button, then compile GWT project and then click Compile.
I found out that it is possible to create a GWT maven project and that it should then be possible to compile my project from commandline with mvn gwt:compile.
So I created a new project using this plugin. Copied my sources from the old project to this new one.
Now the structure is like this:
/src
---/main
------/java -> here are all my sources including my Project.gwt.xml file.
------/webapp
---/test
pom.xml
Now I have 2 problems.
1. I thought that I add dependencies to the pom.xml, and then when I build the app, it will create the jars and I can use those libraries in my GWT app. I guess 'mvn clean install' should do this, but so far I'm getting compile errors.
2. I did not get mvn clean install to work, so I added all the jars manually again... And then yes! I was able to build the app using the plugin GWT button! So I was thinking that now I can use 'mvn gwt:compile', but it fails with:
Unable to find: "com/company/project/Project.gwt.xml" on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
EDIT:
So I fixed my <moduleName> element in pom.xml, so now it finds the Project.gwt.xml. I'm trying to run:
mvn clean install gwt:compile
But I am getting compile errors. I think, it tries to build my project without the actual dependecies because it tells few classes don't exist, but those classes are part of an external library. (specifically this one). But I have it in the dependencies, so I don't know what more to do.
<dependency>
<groupId>com.github.tdesjardins</groupId>
<artifactId>gwt-ol3</artifactId>
<version>3.0.0</version>
</dependency>
Also in eclipse I had to manually add the jars to my project, so that was why it worked there and not in the command line. So I would also like to ask how to tell eclipse to get those jars and include them to the project, because otherwise eclipse is missing those dependencies and displays many errors.
First I had a problem with <moduleName> in my pom.xml was missing com.company.project prefix before the actual module name.
Then I had errors in my Java files, which was caused by RELEASE version of GWT-OpenLayers 3 library missing some of the features that I previously used by building the JAR from the GitHub repository.
I have a non-maven app engine project. I need to include the following library/project into it: https://github.com/UltimaPhoenix/luceneappengine. Without using maven at all, how do I make this work? I need step by step details. I have been trying and my code will not even compile. I am using eclipse.
Looking at the pom.xml I have figured that I need to download luceneappengine, which I did at http://search.maven.org/#search%7Cga%7C1%7Cluceneappengine. Do I need any other jars?
First of all, download Maven to be able to build the project. After that, just use "mvn install" to produce the *.jar of luceneappengine (the result will be stored in the "target" folder of the project). However, it will probably need some extra dependencies. To obtain them, use "mvn dependency:copy-dependencies -DoutputDirectory=$TARGET_DIRECTORY". This command will download all the required jars into the specified $TARGET_DIRECTORY.
I have a new maven project in eclipse and all maven stages work fine.
Problem comes when I write code.
I want classes in my dependencies to be available when I use organize imports.
On pressing Ctrl+Shift+O, eclipse does not use maven dependencies and I need to
manually type imports: this shows errors due to java builder
wait for maven build to compile
Can I not use eclipse java editor like I Used to with a simple java project which has some jars on classpath?
If so, how?
I hope there is a simple solution.
I don't want to spend more spend time mavenizing then writing code.
Use the Maven Eclipse plugin and tell it to download sources and javadocs for you or you can use M2eclipse(which automagically recognizes maven projects.)
use mvn eclipse:eclipse thanks to #Abdullah Shaikh
else
Window -> Preferences -> Java -> Code Style -> Organize Imports.(check
what your ctrl + shift +O do.?)
To convert a maven java project to support Eclipse, you can use below command to generate configuration files
mvn eclipse:eclipse
Run this command from the directory containing the pom.xml
In your case it will build classpath having all the dependencies mentioned in your pom
More details here maven eclipse plugin
mvn eclipse:eclipse
But don't forget to change the directory to your maven project first (command cd)
Then reboot Eclipse
Than go to Eclipse Explorer - right click on your file with import errors - Source -
organize imports (or Ctrl-Shift-O)
I'm hacking on a Maven-based project with a lot of dependencies; the project is normally meant to be developed in Eclipse but I need to work on it from the command line.
How to build+execute the project in a sane way? Something like mvn run, but of course Maven is not meant for running Java projects (for some reason).
The problem is specifying all the dependencies on java's commandline, I don't even know how to autogenerate that. I can currently deal with it using the assembly:single maven plugin (using the jar-with-dependencies descriptor) which will package the dependencies to a single .jar for me.
However, there really is a lot of dependencies and the assembly phase can take about two minutes, greatly disrupting my hack-test cycles so I'm looking for other ways to run the project with minimum build overhead - any recommendations, please?
Note: One possibility is running it in Eclipse once and capturing the java commandline. However, that's just a one-time hack, not a general solution in case I change pom.xml later or come to another project from the suite without Eclipse access anymore.
Have a look at the maven exec plugin
mvn exec:java -Dexec.mainClass="com.example.Main"
if you do this frequently, you can of course configure it via plugin configuration.
Regarding finding out project dependencies - you can use maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
If you want to put them into file it'd be smth like
mvn dependency:list > dependencies.txt
See this question: How can I create an executable JAR with dependencies using Maven?. You can use the dependency-plugin to generate all dependencies in a separate directory before the package phase and then include that in the classpath of the manifest.
I see three solution to this:
onejar-maven-plugin - faster than assemlby with jar-with-dependencies descriptor
With onejar-maven-plugin, you'll (...) get a nice clean super jar with the dependency jars inside.
Spring Boot Maven Plugin - but this is dedicated to Spring projects
Maven Assembly Plugin with custom descriptor. This custom descriptor should grab all dependencies into lib folder, maven-jar-plugin should set Class-Path in Manifest.fm according to this new location. After this you can simply execute your program or zip your jar with lib folder as distribution.
After this is possible to run your program on your computer or any other with one command:
java -jar myjar.jar
I have maven java project that is compiled fine in command line, but when I import in eclipse I receive compilation errors about CollectionUtils.
org.apache.commons.collections.CollectionUtils
Seems that project has transitive dependencies that has reference to old versions of apache commons collections.
How to track exactly error?
How to fix?
Thanks.
Perhaps you could track down the transitive dependencies by issuing mvn dependency:tree to figure out which dependency in your pom is pulling in the older version of Apache commons.
Alternatively, inside eclipse when you open the pom.xml file (with the m2e plugin installed) you should see the Dependency Tree tab at the bottom of the Editor like so :
In the Search field you could type the name of the apache commons jar to find out which dependency is pulling it in. Once you have that add the appropriate exclusion add it should all be peachy.
Question
How did you import the maven project inside eclipse. Did you do a mvn eclipse:eclipse and then import it as a normal eclipse project ? If so, I would recommend installing the m2e plugin (linked above) and then importing the maven project using Import Existing Maven Project from within eclipse.
Looks to me like the classpath (.classpath file) in Eclipse is not correctly configured. You can have maven configure this for you by using the Maven Eclipse Plugin. Simply execute the following from the command line:
mvn eclipse:eclipse
Maven will then correctly fill the .classpath file with all dependencies (including transitive dependencies) defined in your POM. Then refresh the project in Eclipse and all of the red crosses should disappear (hopefully...)
How to track exactly error? How to fix?
invoke
mvn clean compile -e
it will give you error stacktrace that would help you to fix this error