I'm trying to run the YouTube JSON-C Sample in eclipse. I have followed the instructions in the link and I managed to run it in the command line using mvn -q exec:java, but when I import the project to eclipse (I use eclipse indigo), it says that "The import com.google.api.client.googleapis cannot be resolved", and gives me compiler errors in every line that is related to the api. Is there some other configuration that needs to be done? Specifically adding google-api-java-client-1.5.0-beta jars to the build path?
Ok I finally solved the problem. What did the work for me was to execute mvn eclipse:eclipse on the project folder in terminal...
You need to check if you are pulling out all the dependencies in pom.xml from the repository:
<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.5.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.5.0-beta</version>
</dependency>
</dependencies>
Check the settings.xml file in the Maven installation directory if it is pointing to a global repository or if you have hosted your own Nexus/Sonatype repository then make sure that your settings.xml points to that and also you must have the above two jars in your repository.
Or if you just want to get the project up and running, then instead of importing as a Maven project, just import it as a normal Java project and manually add the two libraries to the project's classpath. That should at the least get you started with the project without worrying about the Maven stuff.
Related
I have a java project with dependencies from a Maven private repo. Upon initial set up maven built the project correctly but now projects from the private repo have to be built manually/ locally( mvn clean install -U in the project used to work). When I try to run the project, everything compiles correctly, however upon runtime I get a java.lang.NoClassDefFoundError. These are all from Maven private repos that need to be recompiled locally for the project in question to run.
There are two things that happened around the same time: 1) I had to update my password to the Maven Private repo, however, I updated my credentials stored locally on my computer and when I try mvn clean install -U I can see the dependencies downloading correctly. 2) I am new to Java / Intellij and when trying to delete a class file I accidentally deleted the entire module. Not sure if this broke some link somewhere I may just not be aware of?
I've cleared the cache, deleted the entire .m2 dir contents and started from scratch, deleted the entire project directory and restarted again but still get the same issue.
It might happen when you have duplicate libraries . Please check the maven dependency tree. You should get an insight. You can use tag to remove the duplicate jars.
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
I am working with a maven project in eclipse which I have been testing using the built-in "run on server" tomcat option. When I try to do this, I get errors stating certain dependencies are unmet from an external jar I reference in the POM. However I have found if I add the jar via the DeploymentAssembly Tab I can run in eclipse without issues:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.company.user.server.UserDetailsAuthoritiesMapper#0'
The issue comes when I try to deploy on an actual tomcat instance. The Maven build runs fine, but when I start the servlet I get the same unmet dependency errors. This to me is indicating that the external jar is not being properly packaged into the war. What is the maven equivalent of adding the package via the DeploymentAssembly tab in eclipse? The entry in the POM.xml:
<dependency>
<groupId>com.company.webapp</groupId>
<artifactId>webapp-user</artifactId>
<version>106</version>
</dependency>
Thanks
You need to locate the maven info for the external jar. If you google the name of the jar and maven you often find a direct link to the block you need. For example if I want version 1.58 of the Bouncy castle jar Google "Maven BouncyCastle" you can find the artifact info. Add that info to your pom.xml as a new dependency in your block.
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
</dependency>
After you rebuild, refresh maven in your IDE 1st after doing a clean, this will tell maven to pull down the jar and added it to your build.
You can also go to the repo directly and search:
Maven Repo: https://mvnrepository.com/
I am new to Maven Project. I am making changes to one of the open source maven project. I am facing a problem in adding a library to the project. So far i have done this :-
I added a library named jni4net.j-0.8.8.0.jar to the resources folder of the project.
I right clicked the jar(in Intellij) and clicked 'Add as library'.
Then in the pom.xml i added:-
<dependency>
<groupId>jar.0.8.8.0.jni4net</groupId>
<artifactId>jar.0.8.8.0.jni4net</artifactId>
<version>0.8.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/jni4net.j-
0.8.8.0.jar</systemPath>
</dependency>
But when i build this project(build is successful, test cases are running) and use this it throws following error:-
java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
Please help me resolve it. I am new to maven and pom. I have looked at various answers, but not getting it right.
PS - I named groupId and artifactID as just reverse of jar file
This is not the right way to add that dependency.
All you need is:
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
The dependency will be retrieved from Maven Central when you build.
Using <systemPath>...</systemPath> is highly discouraged as it usually ties your project to a local environment.
Since jni4net.j dependency is available in maven central, You don't have to download and put the dependency manually. Maven will download and store the dependency locally in `'.m2' folder. Just add dependency as bellow.
<dependency>
<groupId>net.sf.jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
I'm trying to convert a "classic" JAVA EE project, using IBM websphere 8.0.0.5, into a maven multi module project and facing issues with the IBM dependecies.
We use IBM classes from the following packages:
com.ibm.websphere.asynchbeans
com.ibm.websphere.scheduler
com.ibm.websphere.ce.cm
com.ibm.ws.asynchbeans
com.ibm.ws.util.ThreadPool
To get my local project to be compiled I downloaded the was.installer-8.0.0.pm from IBM and installed it to my maven using
mvn install -f "was.installer-8.0.0.pom" -D serverInstallationFolder="C:\Program Files (x86)\IBM\WebSphere\AppServer"
This step was successfull according to command line output.
I then added the following dependencies to my project as described from IBM:
In parent:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
<version>8.0.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
In module:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
</dependency>
But I still can't compile my project as the IBM packages are not found.
Can anyone help me to find and correct a mistake I made?
Edit
After following BevynQ tip from the comments I copied the "was_public.jar" to "was_public-8.0.0.jar" (described at IBM here) and added it to my repository:
mvn install:install-file -Dfile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.jar" -DpomFile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.pom"
I then changed the dependencies to:
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was_public</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was</artifactId>
</dependency>
This helped to get the compiling errors for the imports to com.ibm.websphere done.
What I now have still open is the packages com.ibm.ws.* package. Anyone have an idea?
Edit 2
I added the following dependency and then I was rid of the com.ibm.ws.* import errors.
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>1.0.0</version>
</dependency>
But it still does not compile as now indirectly references can not be found (in my case commonj.work.WorkManager). It seems I need to add further .jars for every single thing. Isn't there an easier way to provide all websphere jars at once as descirbe in the above linked tutorial with the com.ibm.toolsdependency (which do not work)?
In general, com.ibm.websphere are public API for use by applications (this is true of the packages you listed above) which is consistent with these being in was_public.jar
However, com.ibm.ws package is generally product internals. May I ask what interface methods you are using from the com.ibm.ws.asynchbeans package? Maybe there is a public API alternative.
Regarding commonj.work, the only place I can find this in the WebSphere Application Server product image is WAS/plugins/com.ibm.ws.prereq.commonj-twm.jar so it looks like you will need to use that to compile against.
Here's the solution so I solved my dependency problems:
I configured the company repository manager (nexus) as a mirror. In this nexus all ibm packages are present. As you can think that solved the main problem.
I then added the following dependencies according to common maven style:
Dependencies in pom.xml (version numbers extracted to properties):
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>${ibm.ws.runtime.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.ws.prereq</groupId>
<artifactId>commonj-twm</artifactId>
<version>${ibm.ws.prereq.commonj-twm.version}</version>
</dependency>
Sorry I can't provide a "nice" solution that's useable by all people but the answer from njr and the comment from BevynQ helped at lot to get clearer with the problem and helped to solve the problem in a "more manual" way by copying the needed jars by hand.
I was facing this issue as I tried to build a project using Maven version 3.3.9, running on Java version 1.8.0_101, as depicted in the screenshot:
This is how I resolved it: Step 1. Download the commonj.jar from here.
Step 2. Determine which JDK your Maven is using by typing mvn -version in the command prompt.
Step 3. Go to that directory and place the commonj.jar file there in the jre/lib/ext directory, as shown below. Now your project should build in maven without any issues.
I'm using MyEclipse to develop a really simple Java Struts project. Everything was working fine until I wanted to use the StringUtils class in org.apache.commons.lang. In MyEclipse I imported the package like
import org.apache.commons.lang.StringUtils;
I added the Jar file for commons-lang-2.4 to my build path. This all works fine and dandy and I get the Intellisense and no errors in Eclipse or anything. Now, when I go to do a mvn clean package, I get an error saying that
The package org.apache.commons.lang does not exist
I checked in my war/Pom.xml file and I do have it declared as a dependency
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
From my research I figured that Maven should download the package and install it to my local repository if it doesn't exists. I checked the repository and the jar file was in there. I figured the jar file must be corrupted so I deleted the commons-lang folder to get a fresh download of commons-lang. Now this is where it blows my mind, after I deleted it from the local repository and ran a mvn clean package, it goes out and downloads the commons-lang-2.1.pom and jar (even though the pom.xml has 2.4) BUT still gives a compilation failure saying that the package org.apache.commons.lang does not exist.
I haven't been using Maven for very long so I'm not sure how to go about fixing this. Am I missing something? Do I need to add the dependency in another pom.xml file somewhere else?
Try running the following commands and examine the output:
$ mvn dependency:tree
$ mvn help:effective-pom
Look for commons-lang, maybe something will draw your attention like excludes or dependency overrides. Also, is:
$ mvn dependency:copy-dependencies
copying commons-lang JAR to your target?
Adding following dependency to pom.xml in dependencies tag helped me:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
I did "mvn clean install -U" without settings.xml, so it erred. Then I added settings.xml, did "mvn clean install -U", it said "error:org.apache.commons-lang does not exist". I know the code was built successfully on another machine. So it was not my code. After about 2 or 3 hours, I finally realized it was .m2\repository was corrupted by my first run. So just delete "repository" folder complete and run "mvn clean install -U" and succeeded.
Better go with below to avoid clashes :
import org.springframework.util.StringUtils;
In src/main/java there would be a .auth folder. Open the folder, Go to AuthController.java file and delete the import io.swagger line. Restart.