Maven "could not parse error message" (Java 7 + Maven 2) - java

I have a maven-based GWT project that includes Guava. I am running into trouble with Maven trying (and failing) to compile the sources that it finds in guava-gwt*.jar:
could not parse error message: symbol: static setCountImpl
location: class
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol
return setCountImpl(this, element, count);
^
I can't figure out why Maven thinks it needs to compile the sources in guava-gwt. Here's what my project looks like:
├── pom.xml
└── src
   ├── main
   │   └── java
   └── test
   └── java
   └── SomeTestFile.java
SomeTestFile.java
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.junit.Test;
public class SomeTestFile {
#Test
public void testMethod() {
Multimap<Integer, String> someMap = ArrayListMultimap.create();
someMap.put(5, "five");
System.out.println(someMap);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>guava-problem</groupId>
<artifactId>guava-problem</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have already tried the following:
Removing the guava dependency (leaving only guava-gwt)
Scoping guava-gwt to provided
I'm not sure what else to try. guava-gwt includes sources because GWT will compile it into equivalent Javascript. But I don't want Maven to try to compile these sources.
Edit
Just a note...the test files themselves have no real need for guava-gwt over guava since they are compiled and run as Java code (they don't go through the GWT compile step). I don't need guava-gwt specifically for these tests but it needs to be available for my actual GWT client code.
Full Maven Output
mark#mark-peters:~/devel/guava-problem$ mvn -V clean test-compile
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - guava-problem:guava-problem:jar:1.0
[INFO] task-segment: [clean, test-compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: /home/mark/devel/guava-problem/target (included: [**], excluded: [])
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/guava-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/guava-problem/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to /home/mark/devel/guava-problem/target/test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):[19,0] error: cannot find symbol
could not parse error message: symbol: static setCountImpl
location: class
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol
return setCountImpl(this, element, count);
^
could not parse error message: symbol: method setCountImpl(AbstractMultiset<E>,E,int)
location: class AbstractMultiset<E>
where E is a type-variable:
E extends Object declared in class AbstractMultiset
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):105: error: cannot find symbol
return setCountImpl(this, element, oldCount, newCount);
^
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Feb 21 12:49:42 EST 2012
[INFO] Final Memory: 18M/212M
[INFO] ------------------------------------------------------------------------
Edit (again)
Having found that the source of the problem has nothing to do with Guava but rather the Maven version (see my answer), I've updated the title and question to try to be a lot more helpful to future users.

tl;dr
Maven 2 and JDK 7 are incompatible, as Maven tries to parse javac output which has changed in JDK 7.
Full explanation
Raghuram's note that this worked for him in Maven 3+ took me down the road of exploring this not as a config problem but as an actual Maven problem. I started doing more testing and found that this problem:
Occurs with Java 7 and Maven 2.2.1
Does not occur with Java 7 and Maven 3+
Does not occur with Java 6 and Maven 2.2.1
So at that point it became clear to me that the "could not parse error message" errors were relevant, and the problem probably had less to do with the guava-gwt compilation occurring and more to do with Maven not knowing how to handle the errors properly.
To test this I created a separate Maven project that has nothing to do with Guava:
├── pom.xml
└── src
└── main
   └── java
   └── ClassWithWarnings.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maven-problem</groupId>
<artifactId>maven-problem</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>
ClassWithWarnings.java
public class ClassWithWarnings implements java.io.Serializable {}
Lo and behold, Maven tanks on this project as well when using Java 7:
mark#mark-peters:~/devel/maven-problem$ mvn -V compile
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
could not parse error message: warning: [options] bootstrap class path not set in conjunction with -source 1.3
/home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:1: warning: [serial] serializable class ClassWithWarnings has no definition of serialVersionUID
public class ClassWithWarnings implements java.io.Serializable {}
^
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Feb 21 13:10:47 EST 2012
[INFO] Final Memory: 14M/150M
[INFO] ------------------------------------------------------------------------
With Java 6, it still reports the warnings, but can parse the Javac output and so doesn't tank:
Apache Maven 2.2.1 (rdebian-1)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes
[WARNING] /home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:[1,7] [serial] serializable class ClassWithWarnings has no definition of serialVersionUID
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Feb 21 13:18:39 EST 2012
[INFO] Final Memory: 9M/150M
[INFO] ------------------------------------------------------------------------
So it seems as if the problem was that the latest Maven 2 release doesn't know how to parse error messages from Java 7+ javac. Maven 3 does. I still haven't found documentation of this and am a little surprised that Maven doesn't give a warning when it tries to compile against a JDK version that it doesn't know how to support properly.

Converting my comment to an answer...
The exact pom file along with the test class above compiles fine on my Windows box with maven 3.0.4.
The problem could be with the maven version that you are using. Or there could be other maven goals in the actual pom, which may be causing an issue.

For a similar problem I upgraded maven-compiler-plugin to a later version.

Happened to us, that we received the exact same failure, but with gradle instead of maven. After switching from ArrayListMultimap to LinkedListMultimap to error is gone. So it seems, that in version 11.0.2 at least the ArrayListMultimap is broken.

It appears that it's not trying to compile the Guava libraries, but without the full maven build log we can't tell.
Judging by the information you've posted so far, it would appear instead that you have two incompatible versions of a class or library on your classpath during compilation.
I'm going to try your test project and see if I can give you more information.
EDIT:
So I've found a couple of interesting things. First, I was able to get your project to work without a whole lot of fanfare :(
I changed your pom to:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
<version>11.0.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
By default though, your test file will not run. I refactored it so it was is now named SomeTestFileTest which will actually run the test.
I'm running Maven v2.2.1 on OSX. I also cleaned out my ~/.m2/repository before starting. I suggest you try the same: nuke your local repository folder and retry your build. If that doesn't work, let me know what version of maven you're running.

Related

Eclipse jdk 11 problem: The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

I have a toy program that has a compilation error only in Eclipse when I try to use a Chronicle import and compile to language level 11. The program compiles and runs in maven, and also in IntelliJ (with the same maven and JDK).
The versions I have are:
maven 3.6.1
jdk openjdk version "11" 2018-09-25
eclipse 2020-03-R
chronicle-bom 2.19.199 (supported java11 since 2.17)
This is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testjava11</groupId>
<artifactId>chronicle-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>2.19.199</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
</dependency>
</dependencies>
</project>
And here is my simple test class:
import net.openhft.chronicle.bytes.BytesMarshallable;
public class App {
public static void main(String[] args) {
System.out.println("BytesMarshallable: " + new BytesMarshallable() {});
}
}
The output when running exec:java directly with maven is
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< testjava11:chronicle-test >----------------------
[INFO] Building chronicle-test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # chronicle-test ---
[INFO] Deleting C:\Users\eclipse-workspace\chronicle-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # chronicle-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # chronicle-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\eclipse-workspace\chronicle-test\target\classes
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) # chronicle-test ---
BytesMarshallable: App$1#309d6b5b
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.400 s
[INFO] Finished at: 2020-06-11T15:04:53+02:00
[INFO] ------------------------------------------------------------------------
It compiles in IntelliJ and this is the output when I run as a Java Application:
BytesMarshallable: App$1#39fb3ab6
Process finished with exit code 0
However, in Eclipse the class App will not compile. The error is on the import line and says:
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
There is an additional message in the Problems panel:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.String.
Fix the build path then try building this project
But I don't see what the issue is in my build path:
Furthermore, I can see java.lang is present in the package explorer:
(Note that if I change the language level to 8, but still using JDK 11, it will work in Eclipse.)
I have checked for obvious issues (build path, maven/jdk path) and everything appears correct to me. Why do I get this error in Eclipse and how can I fix it?
The full error message is :
Type java.lang.String is indirectly referenced from required .class files but cannot be resolved since the declaring package java.lang exported
from module java.base conflicts with a package accessible from module
It's caused by one of the transitive dependencies, net.openhft:affinity:3.2.3, embedding 2 classes from the java.lang package, which is illegal. The ECJ compiler in Eclipse complaining about it is expected. However, the fact it works in javac is a bug in itself: https://bugs.openjdk.java.net/browse/JDK-8215739
There's an affinity issue about it: https://github.com/OpenHFT/Java-Thread-Affinity/issues/58
If you're not using the thread affinity features, just exclude affinity from your dependencies and the Eclipse compiler will stop complaining.
The error was solved after I opened
Window > Preferences: Java > Installed JREs > Execution Env
And re-selected the JavaSE-11, Apply and Close
In my case I had following error, and it had no relationship with "Configure build path" --
The type java.io.FilterOutputStream cannot be resolved. It is indirectly referenced from required .class files
The error was solved after I create a package and located the problematic class into the class.
It has a mismatch with pom file so update in pom file as well.
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
I have used these two then its working fine for me.

Maven - how to change pom.xml to use jars installed into local repo?

I have successfully installed a JAR into the Maven local repository. I edit my pom.xml to include these lines:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
<scope>system</scope>
<systemPath>[somepath]/jcrontab-4.0.0.jar</systemPath>
</dependency>
But, after installing with install:install-file, I think these lines are redundant. I just use them to install and when I want to "use" the jar, they are useless because the jar is in the local repo.
So I changed them to:
<dependency>
<groupId>org.jcrontab</groupId>
<artifactId>jcrontab</artifactId>
<version>4.0.0</version>
</dependency>
The same form as those dependencies that exist in the remote Maven central repo. But now Eclipse complains about:
missing artifact: org.jcrontab:jcrontab:jar:4.0.0
And in the Maven dependencies library in Java Build path, I see red cross on the jar, saying:
jcrontab-4.0.0.jar - D:\desarrollo\eclipse-jee-mars-x86_64\eclipse\${maven.home}\m2\repository\org\jcrontab\jcrontab\4.0.0 (missing)
Under this dir, I only see:
jcrontab-4.0.0.jar.lastUpdated jcrontab-4.0.0.pom.lastUpdated
And no jar is there. But other dependencies jars in this Eclipse repo are in their places.
As I examine my maven home repo (<maven-installation-dir>/m2/repository), the jar is installed there. But in the repo under Eclipse dir, the jar is missing.
I am confused.
If the installation of external jar generates a JAR under Maven installation repo, why does Eclipse "Maven dependencies" library points to a repo under Eclipse dir? The {$maven.home} directory smells bad to me.
Am I supposed to change the dependencies of local installed jars like what I did?
As suggested, I execute the command of install:install-file, and I get:
C:\Windows\System32>mvn install:install-file -Dfile="D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar" -DgroupId=org.jcronta
b -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # standalone-pom ---
[INFO] Installing D:\desarrollo\Java environment\lib\jcrontab-4.0.0.jar to D:\desarrollo\Java environment\lib\Maven\apache-maven-3.5.0\bin\..\m2\repository\org\jcrontab\jcrontab\4.0.0\jcrontab-4.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.597 s
[INFO] Finished at: 2017-08-03T14:27:48+02:00
[INFO] Final Memory: 6M/114M
[INFO] ------------------------------------------------------------------------
The same form as those dependencies that exist in the remote Maven central repo.
But jcrontab doesn't exist on maven central.
See yourself on maven central: https://search.maven.org/#search|ga|1|jcrontab
So you need to install the jar into your local repository if you want to use it like another dependency. You can do that like that:
mvn install:install-file -Dfile=jcrontab-4.0.0.jar -DgroupId=org.jcrontab -DartifactId=jcrontab -Dversion=4.0.0 -Dpackaging=jar
See also the maven documentation here: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

What is the correct way to create a Java package from command line? (trouble with Maven)

[ SOLVED ] - but still looking for explanation. Please see bottom of question
I don't have much experience with command line or with Maven. I'm working on a tutorial from a book. It state I should create a java file
src/main/java/com/effectivemaven/chapter01/ExampleAction.java
What I did was mkdir each directory separately i.e. mkdir com, mkdir effectivemaven, mkdir chapter01
I create the .java file in the chapter01 directory.
package com.effectivemaven.chapter01;
import org.slf4j.*;
public class ExampleAction {
final Logger logger = LoggerFactory.getLogger(ExampleAction.class);
public boolean execute() {
logger.info( "Example Action Executed." );
return true;
}
}
When I mvn compile, it says compiling 1 file to target..., but when I look at the taget directory, nothing is created.
So I tried to create a another .java file without using packages, just a simple
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
in the java directory, then mvn compile and it shows up in the target file.
So my assumption is that I'm not creating the packages correctly by using mkdir, or possibly I'm doing something else wrong I'm unaware of.
So basically I just want to know, what is the correct way to create a package from the command line? And if I'm doing it correctly, what could be the other possible reasons the .class is not being created in the target?
EDIT tree
first-webapp
src
main
java
Hello.java
com
effectivemaven
chapter01
ExampleAction.java
target
classes
Hello.class
pom.xml
Command running from C:\Maven Book\first-webapp>
C:\Maven Book\first-webapp>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building first-webapp Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # first-weba
pp ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # first-webapp
---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 2 source files to C:\Maven Book\first-webapp\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.667s
[INFO] Finished at: Sun Jan 12 00:09:49 PST 2014
[INFO] Final Memory: 11M/111M
[INFO] ------------------------------------------------------------------------
C:\Maven Book\first-webapp>
EDIT pom.xml as requested
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.underdogdevs.webapp</groupId>
<artifactId>first-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>first-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
<build>
<finalName>first-webapp</finalName>
</build>
</project>
By the way, this is a web-app I created with the following command
mvn archetype-generate -DgroupId=com.underdogdevs.webapp -DartifactId=first-webapp -DarchetypeArtifactid=maven-archetype-webapp
[ SOLVED ] - but with very mimimal understanding - still offering brownie points for anyone who can explain to me this behavior. Below is what I did
I got it to work. Since I create the project with groupId=com.underdogdevs.webapp, I tried to make a package com\underdogdevs\webapp and created a the class with the corresponding package reference. This fixed the problem. The class appears. But I tested it even further and deleted the package I just created and tried to clean and compile with only the original package structure, but the file showed up again in the orginal package structure. I have no idea why this happens though.Anyone have any ideas?
Ok, the groupid isn't related to your application structure -- it's part of your application name. You are building a webapp, so the compiled classes go into the WEB-INF/classes directory in the generated war file (which, according to your pom is called first-webapp.war) which can be found in the target directory. You need directories src/main/java, src/main/resources, src/test/java, src/test/resources, src/main/webapp/WEB-INF. Under the java directory you should put your package structure (more directories), which in this case is com/effectivemaven/chapter01 and under that put your java file ExampleAction.java. Put your pom in your project root.
On the command line run mvn clean install and you'll generate the target and you should find your .war file in there. In that, under the WEB-INF/classes/com/effectivemavem/chapter01 directory you'll find your compiled java class with a .class extension.
At some point you'll have to put a web.xml file in the WEB-INF directory.

What is a POM on maven?

I'm trying to follow the get started manual of maven, but I receive this error
c:\Ambiente\workspace>mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archety
pes \ -DgroupId=com.mycompany.app \ -DartifactId=my-app -X
Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-27 23:15:32-0300)
Maven home: C:\Ambiente\apache-maven-3.1.0
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: pt_BR, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from C:\Ambiente\apache-maven-3.1.0\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\t316360\.m2\settings.xml
[DEBUG] Using local repository at C:\Users\t316360\.m2\repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\Users\t3163
60\.m2\repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent
: null]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.078s
[INFO] Finished at: Mon Jul 22 17:23:03 BRT 2013
[INFO] Final Memory: 11M/247M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this d
irectory (c:\Ambiente\workspace). Please verify you invoked Maven from the correct directo
ry. -> [Help 1]
org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a proj
ect to execute but there is no POM in this directory (c:\Ambiente\workspace). Please verif
y you invoked Maven from the correct directory.
what is POM and what do I suppose to do to have this file?
A pom.xml file describes how to build a project. It can be considered the Java version of a Makefile in C/C++ or setup.py in Python. Are you following a specific example?
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively.
Below is just a simple example:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
To build the dependencies that you specified in pom.xml file execute:
mvn clean package
After a successfull mvn package you will see something like below:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jul 23 (Time..)
[INFO] Final Memory: 3M/6M
[INFO] -----------------------------
the above command will download all the dependencies to your home directory /home/user/.m2/..
Have a look on this How to create a maven project
Also have a look to Maven in 5 min
The way you tried the command is supposed to work for Linux environment and you are running Windows. Please double check the command (likely removing the \ ) and it should work just fine.

How to import a Maven project to Eclipse Mylyn with WTP features enabled?

I cannot import a maven project with WTP features enabled.
I have already tried:
mvn -Dwtpversion=R7 eclipse:eclipse
When I did the import, the WTP features are not enabled.
How do I import with the features enabled?
Does the maven-eclipse-plugin generate the .wtpmodules file as expected? This is what I get when running the same command on a war project:
$ mvn -Dwtpversion=R7 eclipse:eclipse
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-eclipse-plugin-wtp-testcase
[INFO] task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse {execution: default-cli}]
[INFO] Adding support for WTP version R7.
[INFO] Using Eclipse Workspace: null
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "maven-eclipse-plugin-wtp-testcase" to /home/pascal/Projects/maven-eclipse-plugin-wtp-testcase.
[INFO]
Javadoc for some artifacts is not available.
Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.
List of artifacts without a javadoc archive:
o junit:junit:3.8.1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Tue Oct 27 22:49:17 CET 2009
[INFO] Final Memory: 9M/79M
[INFO] ------------------------------------------------------------------------
$ ls -a
. .. .classpath pom.xml .project src .wtpmodules
$ cat .wtpmodules
<project-modules id="moduleCoreId">
<wb-module deploy-name="maven-eclipse-plugin-wtp-testcase">
<module-type module-type-id="jst.web">
<version>2.4</version>
<property name="context-root" value="maven-eclipse-plugin-wtp-testcase"/>
</module-type>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
</wb-module>
$
On my environment, the eclipse plugin seems seems to be working fine.
That said, WTP R7 (0.7) is quite old (it was released in July 2005) and may not be the right version for your configuration. According to the Web Tools Platform downloads page, WTP 0.7 and WTP 1.0 goes with Eclipse 3.1, WTP 1.5 goes with Eclipse 3.2, WTP 2.0 goes with Eclipse 3.3, WTP 2.1 and WTP 3.0 goes with Eclipse 3.4, WTP 3.1 goes with Eclipse 3.5.
So the question is: what versions of Eclipse and of the WTP are you running?
The plugin actually can create WTP R7, 1.0, 1.5 and 2.0 configuration files as mentioned on the WTP Support page (2.0 is currently missing in the documentation of the wtpversion optional parameter but this is a documentation bug, see MECLIPSE-434). I've successfully imported a generated WTP 2.0 project in Eclipse 3.5.1 + WTP 3.1 so using 2.0 should be ok for recent versions of Eclipse (regardless of MECLIPSE-559).
Note: If you don't want to pass the wtpversion on the command line, you can set it in the maven-eclipse-plugin configuration in your pom.xml like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>2.0</wtpversion>
...
</configuration>
</plugin>
Don't forget to run a
mvn eclipse:clean eclipse:eclipse
To remove the previously created eclipse wtp configuration files

Categories