0

Im a newbie to azure and maven. I have created a build pipeline and it is dropping artifacts to Build.ArtifactDirectory. In CD pipeline, there is a java class which uses System.getProperty("user.dir"). But this path is taking wrongly and it throws ClassNotFoundException. Reason for this: Actual artifacts in cd after drop is present in path: C:/agent1/1/a/buildpipeline/drop/s/TestCode/src/main/read.java user.dir : is searching in path: C:/agent1/1/a/ in which the code is not available. Fix the issue:

  1. To fix this, i need to manually pass the user.dir value through maven commandline that is -Duser.dir="pathname". But this is not working
  2. I can change the artifact drop path from build pipeline and include a task of download artifact in release pipeline - Is not working because, I need to add a maven task to integrate pom.xml and it is automatically showing the path C:/agent1/1/a/buildpipeline/drop/s/TestCode/pom.xml. Please help me with a solution
Mitsuhaki
  • 1
  • 4
  • First I would ask why does a java class use `System.getProperty("user.dir")`? For what purpose? What kind project is this? – khmarbaise Dec 20 '21 at 16:26
  • I'm gonna read a file which is present in the project folder and for that I'm using System.getProperty(user.dir)+"//src//main//resources//file1.properties". I know we can do it in other way using .//src//main but for some reason this is used and it can't be changed. Also, this is a maven project which is used for web application testing – Mitsuhaki Dec 20 '21 at 19:21
  • Reading a file in resources via property is simply wrong. A resource should be read by using `this.getClass().getResourceAsStream(..)` (from `src/main/resources` which is automatically being packed into the resulting jar file into the root location of that jar file..) furthermore trying to read from outside a jar file will simply not work...Furthermore putting a java file into `src/main/java` is wrong because it's the default location which should not being done. You should use a package name which means in other words `src/main/java//JavaClass.java` .. – khmarbaise Dec 20 '21 at 19:41
  • Unit Test code should be located into `src/test/java//JavaClassTest.java`... and of course it will fail because your code is simply wrong.... – khmarbaise Dec 20 '21 at 19:42
  • This: `I need to add a maven task to integrate pom.xml and it is automatically showing the path` sounds as your setup is completely wrong..can you make an example project on Github or alike ... to see how it's really looking? – khmarbaise Dec 20 '21 at 19:43
  • I'm trying to read a property file which is stored under src/main/resources of a maven project inside a Java class. Since I'm going to integrate it to azure release pipeline, the location path is reading wrongly and I need an alternative for that. – Mitsuhaki Dec 20 '21 at 19:57
  • What is the purpose of that file? Related to your java code? why need that within the release cycle? Using Maven? Deploy artifacts? – khmarbaise Dec 20 '21 at 20:12
  • Yes for artifact's deployment – Mitsuhaki Dec 21 '21 at 09:19

0 Answers0