maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikael Åsberg <m.asberg.wa...@gmail.com>
Subject Re: Confusion with Dependency Paths
Date Tue, 05 Feb 2019 19:41:06 GMT
Hi Dennis, maybe you should start with something from scratch then so
you learn step by step.

Create a pom manually, don't rely on Eclipse to generate things. You
need to specify a groupId, an artifactId, and a version. It could be
called mavenexample:mavenexample:1.0 (groupId:artifactId:version). You
should also set properties maven.compiler.source and
maven.compiler.target. Set to 1.8 if you are using Java 8. Finally,
set packaging to jar.

Now you have the basics of a pom file. Main sources go in
src/main/java. You could create a folder there called mavenexample and
place a class MavenExample.java inside it. Package name would be
mavenexample. Create a very simple public class. Doesn't have to have
a main method. Maybe with a single method sayHello() which returns
"Hello". It should not need any 3rd party jars to compile. When you
have that you can test to build it using "mvn clean install". Maven
uses the environment variable JAVA_HOME to find the JDK so make sure
that is set.

When it builds successfully it's time to add a dependency. Add
com.google.guava:guava:20.0 as dependency and try to use it in your
MavenExample.java class. When that works you know a lot of the basics.
Or any other dependency you are familiar with.

Finally, write a Junit test. Then you need to depend on the
junit-library. Test sources go into src/test/java. A junit test class
for mavenexample/MavenExample would be
mavenexample/MavenExampleTest.java (but under src/test/java instead of
src/main/java). Test classes typically go into the same package as the
class under test, so package-private things become visible to it.

If you can do the points above, you have understood the basics and
have tools to help you migrate a bigger project. Good luck!

On Tue, Feb 5, 2019 at 5:08 PM Dennis Putnam <dap1@bellsouth.net> wrote:
>
> Hi Mikael,
>
> I am using Ant. Others have tried to get me to switch to Maven but as I
> said I could never get it to work. The problem is that the project was
> not Maven to begin with but I had to change it in Eclipse because the
> app needs iTextPDF and Maven was the only way to get it.
>
> On 2/5/2019 9:33 AM, Mikael Åsberg wrote:
> > Well, you need to make up your mind what you want to use...ant or
> > maven. If you want to use maven you need to structure your project
> > according to the rules of Maven. I suggest Maven (over ant), which is
> > supported by all major IDEs. So you specify your dependencies in the
> > pom file once and for all, and you can build the project in the IDE or
> > from the command line without additional tinkering.
> >
> > On Tue, Feb 5, 2019 at 3:14 PM Dennis Putnam <dap1@bellsouth.net> wrote:
> >> Hi Mikael,
> >>
> >> I've been down this road before. This is ultimately compiled using Ant.
> >> I have never been able to get it to work using Maven. It has been
> >> working in the past but I ran into a problem with a git update and since
> >> then I've had this problem. There has to be something that is messed up
> >> with wherever javac gets the path information from for the Maven
> >> dependencies.
> >>
> >> On 2/5/2019 8:27 AM, Mikael Åsberg wrote:
> >>> If you have a maven project you compile using maven, you don't use javac
> >>>
> >>> On Tue, Feb 5, 2019, 14:25 Dennis Putnam <dap1@bellsouth.net wrote:
> >>>
> >>>> Hi Bernd and Marco,
> >>>>
> >>>> After further thought I'm not sure how these changes will help with
the
> >>>> path problem when compiling. It seems to me that the more likely culprit
> >>>> is .classpath. I know even less about that than pom.xml. Just in case,
> >>>> here is my .classpath (again generated by Eclipse.
> >>>>
> >>>> <?xml version="1.0" encoding="UTF-8"?>
> >>>> <classpath>
> >>>>         <classpathentry including="**/*.java" kind="src"
> >>>> output="target/classes" path="src">
> >>>>                 <attributes>
> >>>>                         <attribute name="optional" value="true"/>
> >>>>                         <attribute name="maven.pomderived" value="true"/>
> >>>>                 </attributes>
> >>>>         </classpathentry>
> >>>>         <classpathentry kind="con"
> >>>>
> >>>> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
> >>>>                 <attributes>
> >>>>                         <attribute name="maven.pomderived" value="true"/>
> >>>>                 </attributes>
> >>>>         </classpathentry>
> >>>>         <classpathentry kind="con"
> >>>> path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
> >>>>                 <attributes>
> >>>>                         <attribute name="maven.pomderived" value="true"/>
> >>>>                 </attributes>
> >>>>         </classpathentry>
> >>>>         <classpathentry kind="output" path="target/classes"/>
> >>>> </classpath>
> >>>>
> >>>> I don't understand how Eclipse is able to compile this successfully
and
> >>>> javac cannot. Shouldn't the files be the same for both? There must be
> >>>> some difference between what Eclipse is using and what is winding up
in
> >>>> my git working tree that is used for javac. However, pom.xml and
> >>>> .classpath in both working trees are the same. What I don't see in
> >>>> either file is the path to the Maven dependencies that show up in the
> >>>> Eclipse dependencies window (see attached). I think that is the crux
of
> >>>> the problem but I don't know how that get factored into the compile
step
> >>>> with javac.
> >>>>
> >>>> Thanks again for your patience and help.
> >>>>
> >>>> On 2/4/2019 3:44 PM, Bernd Eckenfels wrote:
> >>>>> Hello,
> >>>>>
> >>>>> to add to this, after moving the source to src/main/java/* and Fixing
> >>>> the POM (removing the source path and potentialla the resource plugin)
you
> >>>> can use eclipse alt+f5 t refresh from the pom, this will configure the
> >>>> ecplise Project layout (.classpath) to detect the same source Folders
so it
> >>>> can work in combination with Maven.
> >>>>> Gruss
> >>>>> Bernd
> >>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>

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


Mime
View raw message