Maven + Spring in Eclipse: Unable to find the downloaded Jars - java

I am new to using Maven and Eclipse, I am following this link.
Below is the pom.xml I have in my workspace:
<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.HelloWorld</groupId>
<artifactId>SpringHelloWorld</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>SpringHelloWorld Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<jdk.version>1.6</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SpringHelloWorld</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
For adding the required jars, I run the below command from command prompt:
mvn eclipse:eclipse -Dwtpversion=2.0
I got the "BUILD SUCCESS" message in my console. But when I refresh the project in Eclipse IDE, I can see all the libraries are missing and the path for those jars does not exists.
e.g.
Description Resource Path Location Type
Project 'SpringHelloWorld' is missing required library: 'C:\Users\username\.m2\repository\org\springframework\spring-aop\3.0.5.RELEASE\spring-aop-3.0.5.RELEASE.jar' SpringHelloWorld Build path Build Path Problem
For this error, when I check manually, I can't see any folder named springframework inside the org folder, hence the jar is missing and the error is displaye din Eclipse IDE.
I tried running the command mvn eclipse:eclipse -Dwtpversion=2.0 multiple times but of no use.
Please advice how to resolve this.
EDIT
Below is the snapshot of the Eclipse Installations:
EDIT 2
I am not getting the Maven option when I Right Click on my project in Eclipse IDE. Hence when I create the java folder under the main folder, I am not able toUpdate Project Configuration` as mentioned here. Please advice

The Maven command mvn eclipse:eclipse generate the eclipse project files from POM.
The "-D" prefix in the argument means that it's a system property.
System property are defined like http://docs.oracle.com/javase/jndi/tutorial/beyond/env/source.html#SYS
mvn eclipse:eclipse -Dwtpversion=2.0 command convert the web based java project to maven based java project to support Eclipse IDE.
You can simple use given below command to clean and build your project:
mvn clean and mvn install
OR mvn clean install
Suggestion: Check maven is installed properly using command mvn --version.

Please try installing m2eclipse plugin (if you haven't done so yet) and nextly convert project to use maven behaviour through right clicking on project and choosing "convert to maven" option.

mvn eclipse:eclipse -Dwtpversion=2.0 -e clean install
run this instead. This builds your project by resolving dependencies

Related

Inject Maven Plugin Dependencies runtime

is it possible to inject dependencies in maven plugin and/or gradle plugin at runtime. I know you can add dependencies in plugin in pom.xml but i want those dependencies to be runtime as i want to be able to inject them something like this
mvn <plugin>:<goal> <arg=pass dependencies here)
This plugin is not in repo pom.xml so i want to run mvn cli to execute this plugin outside of the project. Has anyone done this
Add Plugin Dependencies Runtime
use tag for doing this. sample below here :
<dependency>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>version</version>
<scope>runtime</scope>
</dependency>
You could define an additional property like:
<properties>
<plugin.dependency.version>someDefaultVersion</plugin.dependency.version>
</properties>
and use it in the plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.verision}</version>
<dependencies>
<dependency>
<groupId>groupid</groupId>
<artifactId>artifactId</artifactId>
<version>${plugin.dependency.version}</version>
</dependency>
</dependencies>
</plugin>
By doing so you should be able to define plugin's dependency via command line using this command:
mvn org.springframework.boot:spring-boot-maven-plugin:yourGoal -Dplugin.dependency.version=runtimeDepenencyVersion

Maven project is missing package when compiling from terminal

I'm currently trying to compile my first maven project from the command line but whenever I run this command:
C:\Users\zacha\git\INF2050\tp1\PELZ07039904\src\main\java>javac analyse.java
I get this back
analyse.java:7: error: package org.apache.commons.io does not exist
But the project runs perfectly fine when I run it directly from InteliJ
Here is my pom.xml file:
<?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>org.example</groupId>
<artifactId>PELZ07039904</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</project>
I checked and all my jar are in my .m2 file so I'm not sure why I'm getting this error.
javac doesn’t have any idea about maven and it’s dependencies. All it can do is just compile a class. Thats it.
Instead you need to use maven specific command.
Maven provides a command line tool.
To build a Maven project via the command line, run the mvn command from the command line. The command should be executed in the directory which contains the relevant pom file. You need to provide the mvn command with the life cycle phase or goal to execute.
The Maven tooling reads the pom file and resolves the dependencies of the project. Maven validates if required components are available in a local repository. The local repository is found in the .m2/repository folder of the users home directory.
For example the mvn clean install command triggers the jar packaging. This includes compiling the sources, executing the tests and packaging the compiled files in a JAR file. As last step the install phase installs the resulting artifact into the local repository, so it can be used as dependencies by other Maven builds.
Check full guide here

Eclipse Add Project1 as dependent and auto import its dependents

I am trying to get used to Eclipse/Java but am more familiar with MS VisualStudio. Lets say I have Java Library (Project1) which has some dependencies on jar files via Properties->Java Build Path->Libraries (eg: AWS SDK, gson, swagger, etc). Now if I have Project2 and set a project dependency for Project2 to Project1 via Properties->Java Build Path->Project, I would hope that Project1 dependents would also be included for Project2. I dont see that happening or I am missing a step. I have been googling but I don't see any tutorial/documentation discussing 2 levels of dependents. I see that the Project1 jar is being referenced but what about the dependents for Project1? I am receiving an error such as:
The type XXXX cannot be resolved. It is indirectly referenced from
required .class files XXXX
I strongly suggest using Maven, which is a great and easy to use dependency manager.
Probably your eclipse already comes shipped with it, all you have to do is:
Do this for both projects:
Right click both projects, go to Configure -> Convert to Maven Project.
Create a group id,artirfact id and specify the version for your projects.
It will generate a pom.xml file in the root of your project.
Something like this:
<?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>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</project>
You can add dependencies for your projects just by adding a dependency tag.
<dependency>
<groupId>yourGroup</groupId>
<artifactId>yourProject</artifactId>
<version>1.0.0</version>
</dependency>
After that just right click your projects go to
Run -> Run Configurations -> Maven Clean
Run -> Run Configurations -> Maven Install
and it will automatically download and install your dependencies for you.
You might want to have a look at Maven or a tool like this (Gradle, Ivy...) to handle your dependencies.
Relying on Eclipse for defining your build process (and dependencies) is a bad idea for long term projects.
This depends a little, on your project.
In case it is just a Java project, then it is better to use a build tool like Ant with Ivy, Maven or Gradle. As these contain the dependencies and other configuration details. Eclipse Mars (v4.5.1) comes with build in support for all these build tools.
In case it is an Eclipse Plug-in which you are developing, then you can configure it in Eclipse. And then store the configuration files, with the source code in the code repository.

no native library found for maven plugin project

I want to integrate a leap motion app into Weasis Dicom Viewer.
Projects:
Weasis-maven-plugin -> where my leap implementation is
Weasis-framework -> dicom viewer
Weasis-launcher -> This is where I launch the Dicom viewer.
What I've done already:
have m2e with eclipse and added the LeapJava.jar to plugin project and set the location of the native library
installed LeapJava.jar into the .m2/repository folder so that mvn install on my maven plugin build succeeds
added into the pom.xml of maven-plugin
updated maven project
what doesn't work:
when i launch the application, I get no LeapJava in java.library.path
I've seen some other threads that says I need to manually add -Djava.library.path to the VM arguments. However, when I add that to the launcher run config in eclipse the library not found still exists. Should I be adding this somewhere? Any help is greatly appreciated.
This is my pom.xml for the weasis-plugin:
<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">
<parent>
<artifactId>weasis-parent</artifactId>
<groupId>org.weasis</groupId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../weasis-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>LeapPlugin</groupId>
<artifactId>UBC</artifactId>
<packaging>bundle</packaging>
<name>Tool panel sample [${project.artifactId}]</name>
<properties>
<bundle.symbolicName>${project.artifactId}</bundle.symbolicName>
</properties>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Service-Component>OSGI-INF/*.xml</Service-Component>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-ui</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.weasis.dicom</groupId>
<artifactId>weasis-dicom-viewer2d</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${basedir}/sdk/LeapJava.jar</systemPath>
</dependency>
</dependencies>
When I add the "systemPath" I can still mvn install properly but when i run the launcher project now I get org.osgi.framework.BundleException: "Unresolved constraint in bundle"
UPDATE 1:
So right now this is what my pom.xml looks like
<groupId>com.leapmotion.leap</groupId>
<artifactId>leapMotion</artifactId>
<version>1.0.0</version>
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no leapMotion-1.0.0 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at weasisTool.SampleTool$1.run(SampleTool.java:98)
Not sure if this is the actual solution.
But I added:
nativedependency-plugin in my pom.xml
made sure to do mvn package on the plugin project folder (this generated some files under target/ folder
added -Djava.library.path to the VM argument and it compiles and runs!

I'm having troubles to compile a maven project

I've imported my project into Eclipse (Helios + m2eclipse), and also into Netbeans (7.0) and in both IDEs one of the troubles is:
This is what I get in Netbeans when I try to build.
The project com.miCompany:myProject:1.0 (.....) has 1 error
Unresolveable build extension: Plugin
org.apache.axis2:axis2-wsdl2code-maven-plugin:1.3
or one of its dependencies could not
be resolved: Failed to collect
dependencies for
org.apache.axis2:axis2-wsdl2code-maven-plugin:jar:1.3
(): Failed to read artifact descriptor
for
org.apache.woden:woden:jar:1.0-incubating-M7b:
Could not transfer artifact
org.apache.woden:woden:pom:1.0-incubating-M7b
from/to jibx
(http://jibx.sourceforge.net/maven):
No connector available to access
repository jibx
(http://jibx.sourceforge.net/maven) of
type legacy using the available
factories
WagonRepositoryConnectorFactory ->
[Help 2]
This is what I get in Eclipse:
Project build error: Unresolveable build extension: Plugin
org.apache.axis2:axis2-wsdl2code-maven-plugin:1.3
or one of its dependencies could not
be resolved: Failed to collect
dependencies for
org.apache.axis2:axis2-wsdl2code-maven-plugin:jar:1.3
() pom.xml /myProject line 1 Maven
Problem
In Eclipse I've downloaded this: http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.5.4/axis2-eclipse-service-plugin-1.5.4.zip unzipped and copied the file: "org.apache.axis2.eclipse.codegen.plugin_1.5.4.jar" into the directory "plugins" of my Eclipse instalation. And I still getting the same error.
I am running Netbeans over Win XP and Eclipse over Win XP and also over Mac, allways the same error.
Does somebody have any idea what can I do?
Here goes my pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>MyParent</artifactId>
<groupId>com.mycompany</groupId>
<version>1.0</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>myModule</artifactId>
<version>1.0</version>
<name>myModule</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>src/main/java</directory>
<includes>
<include>com/mycompany/client/*.java</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.3</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.mycompany.client</packageName>
<wsdlFile>src/main/axis2/MyWsdl.wsdl</wsdlFile>
<outputDirectory>.</outputDirectory>
<targetResourcesFolderLocation>target/main/axis2</targetResourcesFolderLocation>
<targetSourceFolderLocation>src/main/java</targetSourceFolderLocation>
<namespaceURIs>
<namespaceURI>
<uri>http://schema.mycompany.com/Esb</uri>
<packageName>com.mycompany.services.Esbsrv.schema</packageName>
</namespaceURI>
<namespaceURI>
<uri>http://wsdl.mycompany.com/Esb</uri>
<packageName>com.mycompany.services.Esbsrv.schema</packageName>
</namespaceURI>
<namespaceURI>
<uri>http://schema.mycompany.com/Global/WSException</uri>
<packageName>com.mycompany.schema.global.wsexception</packageName>
</namespaceURI>
</namespaceURIs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
<scope>compile</scope>
</dependency>
-->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
<!--
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
-->
</dependencies>
</project>
Well, I can only offer suggestions as I"m not much of a maven expert, but I did just have to do this today and it was pretty straightforward for me -
set up the maven project to be eclipse friendly : mvn eclipse:eclipse
make sure eclipse can see the libs. this meant going to the projectsetup/buildpath/libraries editor in eclipse and adding the variable M2_REPO to point to your local maven repository (e.g. something like /home/nacho3d/.m2/repository)
Your error, actually, looks to me like maven can't find a dependency for axis. The specifics for that should be on the axis website,
I think you're using maven 3.0+, right?
That pom(org.apache.woden:woden:jar:1.0-incubating-M7b) isn't compatible with maven 3 yet.
If you use maven 2.2.1 to build ESB 4.3.0-03 source, then it would be successfully.
If you have the jar of the missing dependency you can:
1) deploy it on your maven repository, if you have one
2) declare the dependency in your pom with a scope of 'system': check this out
I have also faced the same problem and fixed it by following below step...
In you project directory do the command: mvn eclipse:eclipse
In eclipse project right click->Maven->Update Project.
Again right click->Maven->Disable Maven Nature
Restart eclipse.
Right click on project->Configure->Convert to Maven Project.
Finish. Error will gone.
Thanks

Categories