Maven Jib plugin: 401 Unauthorized - java

I am using Maven Jib plugin to deploy my application to Gitlab docker registry. If I use docker login registry.gitlab.com and enter username and password I can log in to the gitlab registry successfully. I can see that ~/.docker/config.json contains the following information:
{
"auths": {
"https://registry.gitlab.com": {},
"registry.gitlab.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.2 (darwin)"
},
"credsStore": "desktop",
"stackOrchestrator": "swarm"
}
Now if I try to run mvn -Djib.to.auth.username=${username} -Djib.to.auth.password=${password} compile jib:build it fails with the 401 Unauthorized exception. The reason I need to pass the username and password is I would like to run this command in my CICD pipeline and it is required to pass the username and password somehow. I have tested other approaches like setting credentials in the .m2/settings.xml or pom.xml. None of them works.

You can have the credential in the jib plugin section as follows
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<from>
<image>openjdk:8u171-alpine</image>
</from>
<to>
<image>registry.gitlab.com/${project.build.finalName}:${project.version}</image>
<auth>
<username>${jib.username}</username>
<password>${jib.password}</password>
</auth>
</to>
</configuration>
</plugin>
<plugins>
<build>
Have the jib.username and jib.password as properties in settings.xml.
Note: Adjust the from image as to you need.

Related

Windows 7, JDK 1.8, Spring Boot application JAR takes up lot of time for method Security.getProviders() to return

I am executing a Spring Boot application which takes up lot of time to create a SSL context.
Initial debugging points to method Security.getProviders() not returning the list of providers for around 8 minutes.
Provider[] providers = Security.getProviders();
This happens when I execute the JAR using below command on command prompt. But it does not take time when executed as Java Application via Eclipse of STS.
"Command to run Application"
java -DkeystoreFile=<Certificate File Name> -DkeystorePassword=<Password> -jar aws-sqs-consumer-0.0.1-SNAPSHOT.jar <QueueName> localhost false <proxy IP> <proxy Port>
Maven Pom.xml, uses spring boot maven plugin to build the application:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

org.jolokia:docker-maven-plugin:0.10.4:push (code: 500, Internal Server Error)

When trying to push a docker image, using
mvn deploy
I receive following exception:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jolokia:docker-maven-plugin:0.10.4:push (push) on project my_app: Error while pushing image 'd-docker.image' (code: 500, Internal Server Error)
my pom.xml looks like this:
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.10.4</version>
<configuration>
<images>
<image>
<alias>docker.image</alias>
<name>d-docker.image:latest</name>
<build>
<from>d-rscript:latest</from>
<assemblyDescriptorRef>artifact</assemblyDescriptorRef>
<ports>
<port>8084</port>
</ports>
<command>java -jar /maven/${project.build.finalName}.jar</command>
</build>
</image>
</images>
</configuration>
</plugin>
The thing is, that pushing the docker image manually works perfect
docker push docker.image:latest
I don't know if it is important, but as OS I'm using Arch Linux.
can somebody give me a hint please?

How to switch conf tomcat with maven

I have ,in a java high envirgure project using Maven, to add integrations test. To do that, I must add a new test's database (minimalist true copy of the database). Until then it's good.
By against the problem is that I have two differents configurations in my file:
\web\target\tomcat\conf\context.xml
So I always put a ressource in a comment.
exemple of ressource :
<Resource
auth = "jdbc / soarepo"
driverClassName = "oracle.jdbc.driver.OracleDriver"
logAbandoned = "true"
maxActive = "32"
maxIdle = "32"
maxWait = "10000"
name = "jdbc / soarepo"
password = "..."
username = "..."
removeAbandoned = "true"
removeAbandonedTimeout = "60"
type = "javax.sql.DataSource"
url = "jdbc: oracle: thin: # ..."
/>
Q: How do I switch from one to another ressource with Maven?
I already use a profile for integration tests. So I have to change what resources when the profile is called ?
If you are using the Maven Tomcat Plugin to run your web application, you can specify the path of a custom server-dependent deployment descriptor, context.xml, using the contextFile property:
<profiles>
<profile>
<id>integration-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<contextFile>/path/to/context/file</contextFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
.. Other profiles ..
</profiles>

exec-maven-plugin says cannot run specified program, even though it is on the PATH

Edit 20140716:
Solution found
tl;dr = exec-maven-plugin does not recognise .cmd files, but only .bat files, as executable scripts. Rename grunt.cmd --> grunt.bat, bower.cmd --> bower.bat, etc. as a workaround.
Having done npm install -g grunt-cli on my system, grunt is most certainly on the PATH
When I run maven install however, this doesn't seem to register.
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
(build-spa-bower) on project foobar: Command execution failed.
Cannot run program "grunt" (in directory "C:\workspace\foobar\src\main\spa"):
CreateProcess error=2, The system cannot find the file specified -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
(build-spa-bower) on project foobar: Command execution failed.
Just to be sure, in the same terminal, I have executed this
cd C:\workspace\foobar\src\main\spa
grunt build
... in the same terminal as I issued the maven command above, and grunt executes just fine.
Does exec-maven-plugin use the PATH environment variable, or does it need to be told that this executable exisst in some other way?
EDIT:
This documentation suggests that executables on PATH should be found, so it stumps me further.
I dug into the source code of exec-maven-plugin and found this snippet.
From the source of ExecMojo#getExecutablePath:
CommandLine toRet;
if ( OS.isFamilyWindows() && exec.toLowerCase( Locale.getDefault() ).endsWith( ".bat" ) )
{
toRet = new CommandLine( "cmd" );
toRet.addArgument( "/c" );
toRet.addArgument( exec );
}
else
{
toRet = new CommandLine( exec );
}
I compared this to another plugin that ran grunt tasks from maven, and found this
if (isWindows()) {
command = "cmd /c " + command;
}
... and that worked for me. So essentially the latter worked because all commands in WIndows were prepended with cmd /c,
whereas the exec-maven-plugin did not, because it only did so for file ending in .bat.
Looking in C:\Users\USER\AppData\Roaming\npm, I see:
node_modules (folder)
grunt (unix script file)
grunt.cmd (windows script file)
When I rename grunt.cmd --> grunt.bat, this solves the problem, and exec-maven-plugin is able to run this command.
(this also applies to other executables created using npm install -g, such as bower and yo)
In addition to bguiz' answer, which would be the best solution, I've created a workaround using Maven profiles, bypassing the problem.
This is a temporary solution, until the maven-exec-plugin's bug gets fixed.
Please upvote the bug report here: http://jira.codehaus.org/browse/MEXEC-118
Edit: The bug is resolved, you can point to 1.4-SNAPSHOT to fix it.
<project>
(...)
<profiles>
<profile>
<id>grunt-exec-windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>grunt-default</id>
<phase>generate-resources</phase>
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/C</argument>
<argument>grunt</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I had the same issue with 1.5.0 of the plugin.
The cause in my case was spaces in my user name resulting in a grunt path:
C:\Users\My name with spaces\AppData\Roaming\npm.
When I moved the contents of the npm directory to a path without spaces, it worked.

How m2eclipse create a new domain by maven-glassfish-plugin?

version is glassfish v3
I want to trying maven-glassfish-plugin but I don't know how to create a new domain.
You can use the create-domain command. Either pass parameters on the command line or follow the interactive steps:
$ asadmin create-domain
But the Maven GlassFish Plugin (once properly configured) can also create a domain with the following goal:
glassfish:create-domain Create a new Glassfish domain. (Creating an existing domain will cause it to be deleted and recreated.)
Here is a configuration sample (inspired by the Fairly Complete Configuration Example):
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.2-SNAPSHOT</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>${domain.username}</user>
<adminPassword>${domain.password}</adminPassword>
<!-- <passwordFile>path/to/asadmin/passfile</passwordFile> -->
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>true</echo>
<skip>${test.int.skip}</skip>
<domain>
<name>${project.artifactId}</name>
<httpPort>8080</httpPort>
<adminPort>4848</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
</plugin>

Categories