how to mvn deploy-deploy:file from java app - java

I am trying to deploy a file to the local repository using maven-embedder 3.0.4 from java program, but I'm getting following error:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file
(default-cli) on project test: Failed to deploy artifacts/metadata: No connector available
to access repository local (file://~/.m2/repository) of type default
using the available factories
I'm trying to achieve this with MavenCli.doMain(String[], String, PrintStream, PrintStream) function, but it seems I can't make it work.
Any help will be very appreciated. Also, if there is another way to deploy file from java program please let me know.

I would suggest to use Aether instead of Maven embedder. Source on github.

Related

Do I need to install Apache Maven on my PC first, or is it enough to install the plugin in Netbeans to run a Maven project?

I build an Apache Project in java which runs fine on my laptop, now that I try to run the same project in Netbeans on my work PC I get an error:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project aping: Command execution failed.
With a reference to:
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The Maven plugin in Netbeans was installed by default. When I tried to find out if the Apache version in the POM file was correct I tried to check the version on my PC with mvn -version I got the error:
'mvn' is not recognized as an internal or external command,
operable program or batch file.
Does this mean that Maven is not installed on my PC and should I also install Maven on my PC first in order to use the plugin, or should just installing the plugin be enough and do I have a different problem?
The error message you see is
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project aping: Command execution failed.
This is a message from the Maven executable embedded inside Netbeans (so Maven is running), saying that a specific maven plugin (here exec-maven-plugin) failed. This is most likely trying to invoke another program on your computer that is not installed so Netbeans (and hence the embedded Maven) can see it.
If you want to run maven outside Netbeans, you must download and install a copy and invoke the "mvn" binary inside.
You Have to install Maven To run Maven on your PC - http://www.avajava.com/tutorials/lessons/what-is-maven-and-how-do-i-install-it.html see how to install maven
in linux - http://www.mkyong.com/maven/how-to-install-maven-in-ubuntu/
I mistakenly assumed that the problem had something to do with Maven, the problem seems to be something in my source code unrelated to Maven. When I change some of the code the program is build succesfully

Where to put JDBC driver in Java console program?

I've created a little test app as a console program in java that tries to work with hibernate, and I'm trying to connect to an instance of SQL-Server-2008. But when I run my app I'm getting an error stating that it can't find the JDBC driver.
Now I've created the project as a maven project so if the driver is available as a maven dependency that would be great, although I couldn't find it. I do however have the actual .jar file, but I have no idea where to put this in my project structure. Which look like this:
So.. any help would greatly be appreciated! Thanks :)
Download it from http://msdn.microsoft.com/en-us/sqlserver/aa937724 and then install
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar
Once you include it using maven, it is referenced from maven directory.

Connecting with mongodb in openshift is showing error.

I am developing a project based on java and mongodb. MongoDb is my backend, but when I try to connect it, says
[ERROR] /var/lib/openshift/someclass.java: error: cannot find symbol
[ERROR] package com.mongodb
I know this is a problem in Maven build as it cant find the methods and classes in my DBconnect class.
Please tell me how to solve the problem. I need to figure out as soon as possible. How to include my jar in maven repo and upload to openshift.
Double check that your dependencies are listed correctly in your pom.xml
If you can't or don't want to add the dependency to your pom.xml file, try following this KB article about how to add the jar file to your project: https://www.openshift.com/kb/kb-e1087-how-to-include-libraries-jar-files-in-your-java-application-without-using-maven

How to execute a Maven build Java application

I am playing to Maven and tried to built a simple HellowWorld application.
This application uses Spring to libraries.
When I tried to run it, I run it through:
\target\classes
with command:
java -cp HelloWorldApp
It has a long list of classpath dependencies.
I think maven must have some more clever ways to do this instead of listing a whole list of dependency libs.
Can someone help?
Update:
Thanks. I now have another question. I run the project using:
mvn exec:java -Dexec.mainClass="com.vaannila.HelloWorldApp"
However, my project uses a Spring config called beans.xml which is in the
\src\main\resources
When I run it, it says:
Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.jav
a:336)
How can I specify where to look the Spring config?
Many thanks
Run your application by issuing mvn exec:java at the command line, maven will take care of the rest including download of the maven exec plugin.
EDIT As for your updated question: It appears that maven did not copy your resources to the target folder, you can use the maven-resources-plugin to do that. This link should help you get this done.
If you use IDE, such as eclipse +m2eclipse - it will calculate all dependencies from maven dependencies.
If you are running from command line use Exec maven plugin

Java + include sqljdbc4.jar for continuous integration server

does anyone know how I can use the sqljdbc4 jar file inside a project but without setting it in the build path of the project inside Eclpise?
I store my project in a source control repository and have a Countinuous Integration Server (Jenkins) to run my java tests.
If the sqljdbc4 jar is included at Eclipse level only, the Countinuous Integration Server yells it cannot find the class specified (using Class.forName()) as the file is not "shipped" with my java code.
I also use Maven but it seems to not be provided by Maven repository as dependency.
Or any alternative I could use instead of sqljdbc4?
Thanks;
You may find this Using eclipse and maven 2, how to get dependancy for sqljdbc4? helpful as it shows you how to add sqljdbc4 as a dependency. You will have to do this on your CI server as well, unless you have a repository manager such as http://nexus.sonatype.org/, then you can install it there.

Categories