Maven: add a folder or jar file into current classpath

前端 未结 2 1705
星月不相逢
星月不相逢 2020-12-05 18:48

I am using maven-compile plugin to compile classes. Now I would like to add one jar file into the current classpath. That file stays in another location (let\'s say c:/jars/

2条回答
  •  忘掉有多难
    2020-12-05 19:24

    From docs and example it is not clear that classpath manipulation is not allowed.

    
     
      classpath=${basedir}/lib/bad.jar
     
    
    

    But see Java docs (also https://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/tooldocs/solaris/javac.html)

    -classpath path Specifies the path javac uses to look up classes needed to run javac or being referenced by other classes you are compiling. Overrides the default or the CLASSPATH environment variable if it is set.

    Maybe it is possible to get current classpath and extend it,
    see in maven, how output the classpath being used?

        
          cp.txt
        
    
      
        org.apache.maven.plugins
        maven-dependency-plugin
        2.9
        
          
            build-classpath
            generate-sources
            
              build-classpath
            
            
              ${cpfile}
            
          
        
      
    

    Read file (Read a file into a Maven property)

    
      org.codehaus.gmaven
      gmaven-plugin
      1.4
      
        
          generate-resources
          
            execute
          
          
            
              def file = new File(project.properties.cpfile)
              project.properties.cp = file.getText()
            
          
        
      
    
    

    and finally

      
        org.apache.maven.plugins
        maven-compiler-plugin
        3.6.1
        
          
             classpath=${cp}:${basedir}/lib/bad.jar
          
        
       
    

提交回复
热议问题