You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by kgiannou <kg...@iti.gr> on 2011/04/20 09:29:42 UTC

Deploy artifact programmatically

Hi,

I want to upload an artifact with Java code but without having the
distributionmanagement tag in the settings.xml or in pom.xml files.
Is it possible to do it programmatically?

thank you




--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315124.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by Anders Hammar <an...@hammar.net>.
I believe you should have a look at Aether, which is the repository API.

Or, depending on the repo manager you're using you could use some
proprietary interface. If you're using Nexus, it has a REST API.

/Anders

On Wed, Apr 20, 2011 at 09:43, kgiannou <kg...@iti.gr> wrote:

> As a separate step, but no with command line but with Java code if possible
> :)
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315136.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.
its now ok I found the problems in my code..
One last question...Except from uploading the jar file, shouldn't I upload
the corresponding .pom file to the same directory?

Thank you very much for your effort!

--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4327893.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.

I still can not upload using the following code...any help would be valuable



				String webPage = "http://myServer.com";
				String name = "admin";
				String password = "admin";

				String authString = name + ":" + password;				
				byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
				String authStringEnc = new String(authEncBytes);				
				URL url = new URL(webPage);
				HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
				urlConnection = (HttpURLConnection) url.openConnection();
				urlConnection.setRequestProperty("Authorization", "Basic "
						+ authStringEnc);
				urlConnection.setRequestProperty("repositoryId", "releases");
				urlConnection.setRequestProperty("groupId ",
CreateConfigurationFile.groupId);
				urlConnection.setRequestProperty("artifactId ",
CreateConfigurationFile.artifactId);
				
				urlConnection.setDoOutput(true);
				urlConnection.setRequestMethod("PUT");

				OutputStreamWriter out = new
OutputStreamWriter(urlConnection.getOutputStream());
				File file = new File(
						"C:/Documents and
Settings/kgiannou/.m2/repository/Test/Test/1/Test-1.jar");
				try {
					FileInputStream fis = new FileInputStream(file);
					char current;
					while (fis.available() > 0) {
						current = (char) fis.read();
						out.write(current);
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
				out.close();
				InputStream is = urlConnection.getInputStream();
				InputStreamReader isr = new InputStreamReader(is);
				int numCharsRead = 0;
				char[] charArray = new char[1024];
				StringBuffer sb = new StringBuffer();
				while ((numCharsRead = isr.read(charArray)) > 0) {
					sb.append(charArray, 0, numCharsRead);
				}
				String result = sb.toString();
				System.out.println(result);






--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4326883.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by Jochen Wiedmann <jo...@gmail.com>.
Yes, as I said, that's what URLConnection.getOutputStream() is for.
And don't forget to invoke URLconnection.setDoOutput(true) in advance.

On Wed, Apr 20, 2011 at 2:44 PM, kgiannou <kg...@iti.gr> wrote:
> ok done with the authentication..
>
> Shouldn't I somehow put the contents of the jar file to be uploaded to my
> request?
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315695.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
I Am What I Am And That's All What I Yam (Popeye)

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


Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.
ok done with the authentication..

Shouldn't I somehow put the contents of the jar file to be uploaded to my
request?

--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315695.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by Jochen Wiedmann <jo...@gmail.com>.
Create an instance of java.net.URL, add user name and password as
described in [1], call setMethod("PUT") on the URLconnection, set
doOutput to true and write the file to the output stream.

1) http://www.avajava.com/tutorials/lessons/how-do-i-connect-to-a-url-using-basic-authentication.html


On Wed, Apr 20, 2011 at 1:11 PM, kgiannou <kg...@iti.gr> wrote:
> Hi again :)
>
> I have seen this post
> http://maven.40175.n5.nabble.com/Re-Looking-for-help-on-interacting-with-Nexus-programmatically-upload-files-tt132165.html
>
> but I dont know how to add authentication headers and how to add the jar
> file to be uploaded to the request.
>
> Do you have any concrete example?
>
> thank you very much
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315497.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
I Am What I Am And That's All What I Yam (Popeye)

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


Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.
Hi again :)

I have seen this post
http://maven.40175.n5.nabble.com/Re-Looking-for-help-on-interacting-with-Nexus-programmatically-upload-files-tt132165.html

but I dont know how to add authentication headers and how to add the jar
file to be uploaded to the request.

Do you have any concrete example?

thank you very much

--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315497.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.
Thank you both for your quick and informative answers! I will try it and let
you know


--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315178.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by Jochen Wiedmann <jo...@gmail.com>.
Question is, whether you really want to use Maven in that case.

Using Maven is the proper thing to do, if you want to be able to
deploy to multiple targets by just specifying a different URL, as in
scp://... or https://....

If you have a fixed target (like a Nexus repository), it is much more
likely that all you need to do is to program a single HTTP PUT request
or something similar, which can be done with a few lines of code and
without depending on the whole Maven infrastructure, like local
repository, and so on.



On Wed, Apr 20, 2011 at 9:43 AM, kgiannou <kg...@iti.gr> wrote:
> As a separate step, but no with command line but with Java code if possible
> :)
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315136.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
I Am What I Am And That's All What I Yam (Popeye)

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


Re: Deploy artifact programmatically

Posted by kgiannou <kg...@iti.gr>.
As a separate step, but no with command line but with Java code if possible
:)

--
View this message in context: http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315136.html
Sent from the Maven - Users mailing list archive at Nabble.com.

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


Re: Deploy artifact programmatically

Posted by Anders Hammar <an...@hammar.net>.
As part of the build process or as a separate step?
As a separate step you could use deploy:deploy-file.

/Anders

On Wed, Apr 20, 2011 at 09:29, kgiannou <kg...@iti.gr> wrote:

> Hi,
>
> I want to upload an artifact with Java code but without having the
> distributionmanagement tag in the settings.xml or in pom.xml files.
> Is it possible to do it programmatically?
>
> thank you
>
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Deploy-artifact-programmatically-tp4315124p4315124.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>