I have my Selenium tests written in java (Eclipse). I connect to SQL Server and verify some results in database, using JDBC SQLServerDriver; The tests run perfectly in Eclipse : (Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver).newInstance();).
While I need to execute them via command line I run the following line:
mvn clean install -Dtest=Test1 test
The test gets executed only until it has to connect SQL Server to verify the data. I get error message that says:
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://DBALIASSTAGING:1433
at java.sql.DriverManager.getConnection(DriverManager.java:689)
I point to JDK 1.8 in Eclipse and in my JAVA_HOME. I have my sqljdbc4.jar pointed at in Eclipse and in CLASSPATH (C:\Microsoft JDBC Driver 4.0\sqljdbc_4.0\enu\sqljdbc4.jar).
Anything else I am missing? The weird thing is the Test1 runs very well- connects and searches database within Eclipse only. But fails to connect SQL Server via command line, when I run mvn clean install -Dtest=Test1 test. The run well, but chokes when need to connect to SQL Server (11).
I have read all the posts on sqljdbc4.jar and set up the CLASSPATH variable properly and couldn't find anything wrong in my configuration.
Please give me a clue or a hint, I am totally lost, what am I doing wrong?
This is quite tricky as far as I know Microsoft has not released that jar into any maven repositories.
First of all, the fact that you have the jar in eclipse classpath means nothing for Maven (it's independent).
Maven will require you to have a dependency in the pom.xml of the project in order to use the jar. (works similarly as the eclipse classpath).
Like this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
Notice the scope test means that the jar will only be available for maven when testing.
Now, the dependency is usually downloaded from maven central repository. Since it is not there, you will have to download it from microsoft and install it yourself using:
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar
Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
Please also check the other answer regarding JTDS. This library (it's openly available on maven) is one that I have successfully used in multiple production running software.
More info on maven dependencies: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Related
maven noob here
I have this in my pom.xml file
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-encryption-sdk-java</artifactId>
<version>1.6.1</version>
</dependency>
but for some reason, when I do mvn dependency:resolve, this will never show up in the list, and the code itself is forever failing to import com.amazonaws.encryptionsdk. Also the jar file wouldn't appear under External Libraries in IntelliJ.
If my googling skills haven't filed me, isn't mvn dependency:resolve suppose to download the jar file? Please let me know what I'm missing. Thanks!
Which repositories are you connecting to?
Are you connecting to nexus/artifactory/... which in its turn cannot download the dependency?
You can check the repositories in the settings.xml (usually in a .m2 folder).
If using nexus/artifactory/... please check in the respective application if something fails
Are you behind some kind of proxy server?
You can check additional logging output by adding one of following flags to the command:
-e, --errors (Produce execution error messages)
-X, --debug (Produce execution debug output)
I commonly use mvn clean install
Edit 3:
I also tried to set maven proxy through java option parameters mentioned at this thread.
Edit 2:
I'm sure intellij idea are using same settings.xml, same maven binary and the same local repository as system maven.
Edit 1:
I tried to check build log of each workload, the main difference is about how to invoke maven at the very beginning of build log.
For intellij idea, it's like below:
C:\Program Files\Java\jdk1.8.0_101\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\eugene\IdeaProjects\alluxio -Dmaven.home=C:\apache-maven-3.5.4-bin\apache-maven-3.5.4 -Dclassworlds.conf=C:\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin\m2.conf "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA\plugins\maven\lib\maven-event-listener.jar" -Dfile.encoding=UTF-8 -classpath C:\apache-maven-3.5.4-bin\apache-maven-3.5.4\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version2019.2.4 -DskipTests=true -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip
For system shell, maven just launched without this invoking info.
I'm using maven to build a project Alluxio from source code.
I tried both Windows 10 and Ubuntu and found same issue when using intellij idea, let me clarify it into details.
OS: windows 10/ Ubuntu 18.04
Maven: 3.5.4
Build command: mvn -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip
The Alluxio can be built successfully using maven 3.5.4 directly but failed with several errors using intellij idea. What makes me confused is that I configured intellij idea to use system maven 3.5.4 and used exactly same build command. Why errors happened here but not in system shell.
The error I met is like:
Failure to find com.google.guava:listenablefuture:jar:sources:9999.0-empty-to-avoid-conflict-with-guava in https://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
And also like:
sourceFile C:\Users\eugene\IdeaProjects\alluxio\table\server\underdb\target\alluxio-table-server-underdb-2.2.0-SNAPSHOT-jar-with-dependencies.jar does not exist
The method used to trigger maven build from intellij idea:
Click maven icon at right top corner
Click Execute Maven Goal
Input mvn -T 2C clean install -DskipTests -Dmaven.javadoc.skip -Dfindbugs.skip -Dcheckstyle.skip -Dlicense.skip and enter to launch build
The maven settings in intellij idea is as default except change the maven binary from build-in binary to system maven 3.5.4.
Thanks for your help in advance.
I have seen two issues that will produce an error message like you see and it has nothing to do with IntelliJ.
The first occurs when Maven fails to successfully download an artifact from a repository (e.g., network interruption). It will mark the artifact as failed and will refuse to retry until some period lapses. Cleaning your local Maven cache or removing that artifact's folder will fix this issue.
The second occurs when two separate Maven builds attempt to download the same artifact from different repositories. Many years ago, Maven had a problem with people building modified versions of open-source projects (e.g., Apache Commons) and publishing them in a publicly available repository. I don't remember the details but this caused lots of issues. Maven now records the repository used to fetch an artifact. When two Maven projects use different repositories, the second one built will fail because the repository does not match. I had this occur when switching to a private repository, Artifactory, and not having all my projects migrated yet.
Since you are attempting to build the same project with two tools, your issue appears to be a variant of the second issue. I suspect that IntelliJ is using a different settings.xml than what you have available from the command line and that IntelliJ is using different repositories. Repositories can be specified in the settings.xml as well as the project's POM.
Try deleting your local cache and building from IntelliJ first. If it succeeds and then the shell build fails, this is your problem.
Update: See this answer for more details on why Maven started tracking the repository but note the the tracking file is now called _remote.repositories.
https://stackoverflow.com/a/16870552/252344
I'm working with a web app, called A, using maven, in eclipse, going between using m2e eclipse plugin and command line maven.
A depends on a custom library B, which is installed in the local repo. A details this dependency in its pom.xml
When I test the app in eclipse using eclipse's Tomcat, everything is fine -- the up-to-date version of B is used, and I see so in Maven dependencies folder.
But for some reason, when I go to command line and run mvn package, the resulting WAR uses out-dated version of B. I can tell because when I get it deployed to app server, its logging and functionality is broken in a specific way that was fixed in a newer version of B.
Is there any way for me to debug what's going on here? What is eclipse doing that mvn package is not including?
Project definition:
<groupId>org.com.web</groupId>
<artifactId>DocImgTransfer_Servlet</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
Dependency on lib that is somehow getting old version:
<dependency>
<groupId>DocImgTransfer</groupId>
<artifactId>DocImgTransfer</artifactId>
<version>1.0.0</version>
</dependency>
So really 3 questions:
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
Will mvn clean or mvn package -U possibly help in this case at all?
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
If it is just some issue with maven grabbing the wrong version from local repo, is there a way for me to tell Maven to double-check the dependency version it's pulling in?
a) Is your CustomatJar-1.0.0.jar version that eclipse is referring to same as maven is picking up or is maven picking up an older version?
i.e. Do you own the code for CustomatJar and are you just updating it v/s the one getting packed in war is truly an older version e.g. CustomatJar-0.0.5
i) You could tell by just unzipping the war and seeing which version is packed inside the jar.
ii) mvn dependency:dependency would tell you which dependencies maven command line thinks should be packed. more info
Is the only advice to just double-check groupId, artifactId, version in pom.xml?
Could you server have got an older version of CustomatJar in say it's lib?
You did double check your POM.xml already ... correct?
I have a Java project that is ready to ship, but i have stumbled at the last hurdle. The program runs fine in the IDE, but after i run mvn clean install and the target jar is created successfully, the application fails both on the command line AND in the IDE. I can get it to run again in the IDE by doing a rebuild from within the IDE.
Has anyone else experienced something similar?
The error after the mvn clean install is
2014-08-08_10:38:20.328 INFO coza.modh.fxplatform.Controller - Application start
2014-08-08_10:38:20.344 INFO c.m.f.c.p.DataSourceFactory - Connecting to Database.
2014-08-08_10:38:20.499 INFO coza.modh.fxplatform.Controller - Model created
Exception in thread "main" java.lang.NullPointerException
at coza.modh.fxplatform.view.MainView.<init>(MainView.java:46)
at coza.modh.fxplatform.Controller.startup(Controller.java:40)
at coza.modh.fxplatform.Application.main(Application.java:7)
The line it fails on looks like this:
setContentPane(contentPane);
If i rebuild from within the IDE then the variable is not null when it gets here, but after the mvn command the variable is null when it gets to this point.
EDIT: Someone pointed out that it might be related to the fact that i used the intelliJ GUI designer tools and that Maven might not gel with it. Possibility?
I had a similar problem today. To solve the issue -
Firstly, add the following to the pom.xml
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>5.0</version>
</dependency>
Secondly, as you stated, use the correct maven plugin to create the build.
See this for step by step instruction.
Unlikely that contentPane is null, but check. Do a clean build anyway. Maybe the line number is not entirely correct.
Normally the problem are resources, like an application icon.
They are not File but zipped inside the jar.
So paths like /src/main/resources/... will not do.
Neiter using a backslash \, and
furthermore the file paths are case sensitive.
This can be caused by different library versions, do you have changed the build path in Eclipse? (Project->Properties->Build Path -> Libraries). There should only be "JRE System Library". If there is more, then it is possible that it is be loaded instead of one of your Maven dependencies. You using "mvn clean install" means it is compiled against the Maven dependencies and thus it runs differently.
Install Maven on the system(not having IDE) before running the code
ensure you've got system property M2_HOME set to your Maven installation location and also Maven bin folder added to PATH
go to the directory,containing pom.xml of your project and type "mvn install" plus Enter to build your project
if it's for example simple project,packaged as JAR,you can run it then by typing something like this in the console:
$ java -cp target/simple-1.0-SNAPSHOT.jar org.yourcompany.projectNam.App
and Enter
I am getting really frustrated about this one:
I am using an maven project, using jdbc with eclipselink. mvn install works as intended. Until I have to change the PW in the persistence.xml. When I do an mvn clean and afterwards mvn install the project is broken and the wrong (old) persistence.xml is still in use. In eclipse I have to do maven -> update project (using m2e addon) and mvn install works suddenly again.
Now my problem: On the deployment server I am using command line scripting and I found no mvn XYZ equivalent for the m2e functionality...
Is there some equivalent?
Explicit scenario:
I am developing on my local machine (osx/win7) in an maven project imported in eclipse. I have a JPA Persistence interface which encapsulate the database connection which is realized via eclipselink. I can deploy locally (mvn install) but after I run mvn clean and change the password in persistence.xml mvn install isn't possible anymore. I just get classDefNotFound Persistor in the tests because it static initialize the EntityManager which can't connect cause of the new persistence.xml -- or at least it's my opinion, because the stacktrace is not really helpful. But, after maven -> update project... in eclipse on the project, mvn install works again and the new password is taken (tests run!).
When I want to deploy the project on a remote machine (debian, commandline) I can't ´mvn install` the pulled project, cause after I changed the password in persistence.xml for deployment, it's again the wrong persistence.xml or at least some cached used.
I hope that make it a bit more clear.
SOLUTION:
Make sure persistence.xml is placed in src/main/resources/META-INF and not elsewhere. m2e catches persistence.xml from wrong places (in my case, src/main/java/META-INF). So it was basically just a wrong project structure.
Looks like you can use mvn eclipse:clean eclipse:eclipse to regenerate the eclipse project files -- hope that sorts you.
maven update project from eclipse is different because it will generate a Maven Dependencies class path container
mvn eclipse:eclipse generates a Referenced Library Container.