Maven compilation failed while eclipse was successful

I am using maven3.03 and Eclipse 3.5 on Windows XP. I converted the old web project to the maven configuration style.
When I compile the project in eclipse, everything compiles.
Note. The class path contains: Maven Dependencies and JDK (1.6_018).
When I compile from the command line using mvn, I get a few errors:
1.package com.sun.xml.internal.stream.buffer.stax does not exist.
2.package com.sun.xml.internal.stream.writers does not exist
3.cannot find character - character: class XMLDOMWriterImpl
4.package com.sun.xml.internal.messaging.saaj.util does not exist
5.package com.sun.xml.internal.bind.v2.runtime.unmarshaller does not exist
6.cannot find character - character: class NamespaceContexHelper
7.cannot find character character: class ByteOutputStream

I see that this is something with a solar jar. But I just can’t understand why eclipse is ok and not on the command line.

EDIT . One of the errors that I did not mention in the above list:

[ERROR]<path>\EventsViewer.java:[54,69] inconvertible types found: <br>java.util.SortedMap<java.util.Date,java.util.List<com.myClass>> required: java.util.Map<? extends java.util.Date,? extends java.util.List<com.myOtherClass>> 


When I see the same line in eclipse, I get a warning:

 Type safety: Unchecked cast from SortedMap<Date,List<myClass>> to Map<? extends Date,? extends List<myOtherClass>> 

In Eclipse I get a warning and in maven I get an error. I checked org.eclipse.jdt.core.prefs and saw that this is the parameter org.eclipse.jdt.core.compiler.problem.forbiddenReference = warning.

Update : I read some of the errors above. The β€œproblem” is that in eclipse it looks like an unused import. Stangly maven report this as an error. After deleting this unused import, the error disappeared. But still there are problems 3 and 7.

Conclusion I think warnings become bugs in javac. since I do not use any condoms. I am just surprised that the error is different. What is it?

+7
source share
4 answers

This is the real reason, probably from the maven forum answer

β€œJerome is right that he is not recommended to use the com.sun classes from rt.jar. And especially those that are designated asβ€œ internal ”; you're just asking for a problem.

However, I was interested, so I tried it. The above class can really access Eclipse. However, compiling code using javac with the error "does not exist." So my assumption is that the Sun java compiler detects when a special β€œinner” class accesses it and refuses to import the class. Eclipse uses a different compiler, which apparently does not have this check.

Maven just uses the javac compiler, available at system runtime track. Therefore, the problem has nothing to do with Maven. This is a maven compiler that refuses to compile the source. I do not see any public flags on the javac command line to disable this "lock" of internal access, so if you do not want to use Sun javac, you just need to avoid using this internal class.

Just for fun, I tried Jerome's suggestion to put rt.jar on the Class Path: javac -cp / usr / java / jdk1.6.0_03 / jre / lib / rt.jar Foo.java but it still failed compile.

The ByteOutputStream class can be loaded at run time through Class.forName ("..").

Interestingly, the project I'm working on really makes sense to import the com.sun.org.apache.xml.internal.utils.SAXSourceLocator class; and it works fine. Warnings are issued, but the code compiles (and yes, it's on my TODO list to fix this :-). So these are not all the inner classes that are blocked, only the selected ones. "

+9
source

Double check that you are using the same JDK to build Eclipse and Maven. Even if you think so, double-check again.

These packages are one of those included in some versions of Java, and not others.

+2
source

If java version is different by adding maven-compiler-plugin

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.1</version> <configuration> <target>1.6</target> <source>1.6</source> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> 

with the source and target configuration pointing to 1.6, and updating the project configuration from the context menu of the Maven project will solve the synchronization problem in many cases (which leads to different compilation results):

enter image description here

0
source

This is my case: I have the same error in IntelliJ after adding //TODO , Intellij automatically added this line to the import section import com.sun.xml.internal.bind.v2.TODO;

After removing the above import line, the problem is resolved. Now I can successfully compile using maven

0
source

All Articles