You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by br...@commcity.ch on 2013/10/25 11:07:49 UTC

Imports of required classes have classname only without package path within the class compiled by maven

The web project composed of several modules can be deployed to the 
application server (WAS 8.5.5) and runs as expected, when built within 
eclipse (juno sp2) by the eclipse compiler. The same project built with 
maven, either through the m2e-wtp plugin or with "mvn clean install" from 
the command line, can not be run on the AppServer.

Maven build worked too, but does not anymore for unknown reason. No 
changes of configuration or programs but update of m2e-wtp.

All required configuration files bundled within the resulting project.ear 
are correct and identical to the version compiled with eclipse.
On analyzing the issue it turned out, some classes compiled by maven have 
defective import lists! 
For instance:
A *.class file decompiled with jd has the following import list:
import DocumentId;
import DocumentKind;
import IProject;
import IRequirement;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;
We see, the list is truncated, and some imports have the class name only, 
but no package information.
If we look at the same decompiled class file, but the outcome from the 
eclipse compiler, the list look like:
import ch.commcity.monterosa.common.reports.DocumentId;
import ch.commcity.monterosa.common.reports.DocumentKind;
import ch.commcity.monterosa.ejb.IProject;
import ch.commcity.monterosa.ejb.IRequirement;
import java.io.IOException;
import java.io.Serializable;
import java.security.InvalidParameterException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.Application;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
First, the latter list is longer and second the import DocumentId for 
instance  includes the full package path!
As the import list is defective, no surprise all methods look like the 
following example:
  int getFrom()
  {
    throw new Error("Unresolved compilation problem: \n");
  }
instead of:
int getFrom() {
        return this.from;
}
which is neither very sophisticated, but does was is expected to be done.
Question:
All dependencies declarations within the poms are the same as before. May 
a missing declaration be the origin of the problem, which before had no 
effect?
What else? I must say I had the same problem in February of this year, But 
without any conscious change (I suspect after update to sp2 of juno) it 
worked suddenly as now it stopped to work, maybe due to the m2e-wtp 
update!
The poms are unchanged and within the Kepler IDE environment maven 
compiles the code as expected. The only differences are some parts proper 
to the glassfish 3.1.2 Appserver and for the Mojarra version of JSF in 
turn of MyFaces used by WebSphere.
Any hint or suggestion is welcome.

Re: Imports of required classes have classname only without package path within the class compiled by maven

Posted by Wayne Fay <wa...@gmail.com>.
> Maven build worked too, but does not anymore for unknown reason. No
> changes of configuration or programs but update of m2e-wtp.

This list does not support m2e. You'll need to ask this question on
the appropriate Eclipse list. We can help you sort out why command
line Maven is not working as it should.

> All required configuration files bundled within the resulting project.ear
> are correct and identical to the version compiled with eclipse.
> On analyzing the issue it turned out, some classes compiled by maven have
> defective import lists!
...
> We see, the list is truncated, and some imports have the class name only,
> but no package information.
> If we look at the same decompiled class file, but the outcome from the
> eclipse compiler, the list look like:

Maven (command line) simply calls out to the JDK installed on your
system. You can use "mvn -X" to see the actual command that Maven uses
to call javac. If you are experiencing problems with the output of
Maven's compilation process, your real complaint is with the JDK &
javac itself, not Maven. I trust that you realize that Eclipse has and
uses its own compiler, so I would expect that you might see some
different results when analyzing class files produced by the 2
compilers.

Is it possible that javac simply reduced your import list because a)
they were not all being used or b) it swapped out the import and
replaced the short name for the class with the fully-qualified name?
Did you look at the rest of the source code that came out of jd?

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org