Total Pageviews

Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

2020/06/09

[Eclipse] [Maven] missing artifact xxxxxx

Problem
I copy libraries (under .m2/repository) from other's machine.
As I tried to update maven in my eclipse project, I got missing artifact error.
I had confirmed these jar files which existed in my .m2/repository.

How-To
Go to specific directory and delete _remote.repositories, thenthe problem will be resolved.

2019/08/05

[Maven] Fail to generate web client code by wsdl2java

Scenario


Problem 
When I try to generate web service client code from WSDL :
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.6</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- define location which CXF will generate artifacts -->
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <encoding>UTF-8</encoding>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/OQ2Info.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oq2</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


I will get exception after I execute mvn clean install :
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:3.2.6:wsdl2java (generate-sources) on project test: 
Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:3.2.6:wsdl2java failed: 
file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [32,7]: 相同名稱 "test.ws.bind.oq2.Exception" 的類別/介面已在使用中. 請使用類別自訂項目以解決此衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [27,7]: (與上述錯誤有關) 另一個 "Exception" 從此處產生.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [32,7]: 兩個宣告導致 ObjectFactory 類別發生衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [27,7]: (與上述錯誤有關) 此為另一個宣告.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [35,13]: 兩個宣告導致 ObjectFactory 類別發生衝突.
[ERROR] file:/F:/workspace/test/src/main/resources/wsdl/oq2_ws.xml [29,11]: (與上述錯誤有關) 此為另一個宣告.
[ERROR]
[ERROR] -> [Help 1]



How-To
Owning to naming conflicts occur in this WSDL file, so I need to set autoNameResolution to true to resolve this problem:


            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.6</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- define location which CXF will generate artifacts -->
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <encoding>UTF-8</encoding>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/OQ2Info.xml</wsdl>
                                    <autoNameResolution>true</autoNameResolution>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oq2</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>




2019/07/05

[Maven] How to generate WSDL client code via Apache CXF in Maven?

Scenario


How-To
I have three WSDL files in my spring boot project:


Apache CXF includes a Maven plugin which can generate java artifacts from WSDL. Here is a simple example:
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.2.6</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- define location which CXF will generate artifacts -->
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <encoding>UTF-8</encoding>
                            <wsdlOptions>
                                <!-- generate io_ws wsdl client code to 
                                    test.ws.bind.oi2 package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oi_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oi</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>

                                <!-- generate oe_ws wsdl client code to 
                                    test.ws.bind.oe package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oe_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oe</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>

                                <!-- generate oj_ws wsdl client code to 
                                    test.ws.bind.oj package -->
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/oj_ws.xml</wsdl>
                                    <extraargs>
                                        <extraarg>-p</extraarg>
                                        <extraarg>test.ws.bind.oj</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

After executing mvn clean install, you can find out artifacts in ${project.build.directory}/generated/cxf :


Reference
[1] http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html

2018/04/07

[Maven] How to specify JDK version for Maven?

Problem
I have multiple JDK version in my computer, how to specify JDK version for Maven?

How-to

Add the two properties in your pom.xml
 <properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
 </properties>


2018/02/09

[Maven] How to stop Maven to check for updates for artifacts in offline mode ?

Problem
I am using offline mode to build my project, the command is as bellows:
mvn -o -Dmaven.repo.local="C:/Users/albert/.m2" clean install -Dmaven.test.skip=true

During the build process, Maven still check for updated for certain artifacts even in offline mode. How to avoid it?


How-To

Go to your local repository (ex. C:/Users/albert/.m2), and delete all *.lastupdated and _remote.repositories files.
Then Maven won't check updates any more.




2018/01/10

[Maven] How to use local repository?

Problem
How to use local repository in Maven?

How-To


Approach 1. Add localRepository tag in your settings.xml
1
2
3
4
5
6
7
8
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:SchemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
          
   <localRepository>C:\Users\albert\.m2</localRepository>
   
</settings>


Approach 2. Assign -Dmaven.repo.local in command line
1
mvn -o -Dmaven.repo.local=C:\Users\albert\.m2" clean install -Dmaven.test.skip=true -X



Reference
[1] https://stackoverflow.com/questions/9123004/maven-is-it-possible-to-override-location-of-local-repository-via-the-use-of-co

2018/01/07

[Maven] Cannot find IBM-related jar files in Maven Central Repository

Problem
If I would like to use some proprietorial jar files (i.e. IBM DB2 jdbc jar file, IBM MessageQueue jar files) in my Maven project, and add them into dependency. 
How to do it?

How-To

Step 1. Download jar files, ex. DB2 jdbc jar file
Step 2. Launch command prompt, change directorty to db2 jar file and execute the following command:
mvn install:install-file -Dfile=db2jcc4-4.22.29.jar -DgroupId="com.ibm.db2.jcc" -DartifactId="db2jcc4" -Dversion="4.22.29" -Dpackaging="jar"

Step 3. Add dependency to pom.xml
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc4</artifactId>
        <version>4.22.29</version>
    </dependency>


Step 4. Go to .m2 folder and copy com/ibm/db2/jcc/db2jcc4 to your project, for example:


Step 5. Add repository setting in your pom.xml
    <repositories>
        <repository>
            <id>my-local-repo</id>
            <!-- ${basedir} represents the directory containing pom.xml -->
            <url>file://${basedir}/local-repo</url> 
        </repository>
    </repositories>




2017/12/09

[Maven] How to assign WAR file name in pom.xml

Problem
When I utilize maven to build WAR file, the WAR file name always suffix by version which define in pom.xml (i.e. StockQry-1.0.war).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>StockQry</groupId>
    <artifactId>StockQry</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <!-- ignore plugins -->
        </plugins>
    </build>

    <dependencies>
        <!-- ignore dependencies -->
    </dependencies>

</project>
If I would like to have StockQry.war instead of StockQry-1.0.war, how to do it?


How-To
Add finalName in build tag, the updated pom.xml are the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>StockQry</groupId>
    <artifactId>StockQry</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <build>
        <finalName>StockQry</finalName>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <!-- ignore plugins -->
        </plugins>
    </build>

    <dependencies>
        <!-- ignore dependencies -->
    </dependencies>

</project>


2017/06/09

[Eclipse] project configuration is not up to date with pom.xml

Problem
I have Maven Project in Eclipse Mars.

One day I have an error in my project, but it does not have any negative effect to my implementation or maven build :


How-To
Although the root cause is still unclear, it works to follow these steps to get rid of this annoying error:

Step 1. Click this error => right click => Quick Fix


Step 2. Click Finish in Quick Fix window

Fixing problem in progress:

After fixing process, the problem is disappeared:

2015/05/04

[Maven] Error instantiating builder ‘org.eclipse.m2e.core.maven2Builder’.

Problem
My eclipse had shut down unexpectedly. As I restart eclipse, and try to do maven clean.

The console show this error message
1
2
3
4
Errors occurred during the build.
Error instantiating builder org.eclipse.m2e.core.maven2Builder.
Plug-in org.eclipse.m2e.core was unable to load class org.eclipse.m2e.core.internal.builder.MavenBuilder.
An error occurred while automatically activating bundle org.eclipse.m2e.core (524).

Solution
Step 1. Shut down eclipse
Step 2. execute eclipse with -clean parameter, i.e. "eclipse.exe -clean"
Then the Maven is working fine.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building FMS :: Entity Classes 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ fms-entity ---
[INFO] Deleting D:\git\fms\fms-entity\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.229s
[INFO] Finished at: Mon May 04 17:42:59 CST 2015
[INFO] Final Memory: 5M/120M
[INFO] ------------------------------------------------------------------------


Reference
[1] http://stackoverflow.com/questions/25929458/building-workspace-has-encountered-an-error

2014/11/11

Do not have git connector when I want to Checkout Maven project from SCM

Problem
I would like to import Maven project from Git
File => import

Check out Maven Projects from SCM => Next

I do not have "git" option to select !

Solution
Install git connector

Window => Preferences

Maven => Discovery => Open Catalog

Check "m2e-egit" => Finish

After installation, click Yes to restart eclipse

File => import => Check out Maven Projects from SCM => Next
We have "git" option now!




2014/04/29

[Apache Maven Problem] org/apache/maven/shared/ filtering/MavenFilteringException

Problem
As I build my JavaEE project with Apache Maven in Eclipse, it show this error message in my Eclipse
 Multiple annotations found at this line:  
 Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: A required class was missing while executing org.apache.maven.plugins:maven-resources-plugin:2.6:resources: org/apache/maven/shared/filtering/MavenFilteringException   
 -----------------------------------------------------   
 realm =      plugin>org.apache.maven.plugins:maven-resources-plugin:2.6   
 strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy   
 urls[0] = file:/C:/Users/javis-msi/.m2/repository/org/apache/maven/     plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar   
 urls[1] = file:/C:/Users/javis-msi/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar   
 urls[2] = file:/C:/Users/javis-msi/.m2/     repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar   
 urls[3] = file:/C:/Users/javis-     msi/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar   
 urls[4] = file:/C:/Users/javis-msi/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar   
 urls[5] = file:/C:/Users/javis-msi/.m2/     repository/junit/junit/3.8.1/junit-3.8.1.jar   
 urls[6] = file:/C:/Users/javis-msi/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar   
 urls[7] = file:/C:/Users/javis-msi/.m2/repository/org/apache/maven/shared/maven-filtering/1.1/maven-     filtering-1.1.jar   
 urls[8] = file:/C:/Users/javis-msi/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.13/plexus-interpolation-1.13.jar   
 Number of foreign imports: 4  

I try to do mvn clean install again, again, and again. But still in vain.

Solution
This problem may result from you have broken jar files. Try to retrieve jar files again. The steps are as follows:

Step1. Go to you .m2 folder, and delete everything.

Step2. Retrieve all jar files again. 

2011/06/28

Utilize Maven 2 JasperReports Plugin to Compile jrxml Automatically

Motivation
We would like to compile jrxml automatically as we build our web application.


Mechanics
We use Maven 2 JasperReports Plugin to compiles JasperReports xml design files to Java source and .jasper serialized files.

How to do it
1. edit nig-web/pom.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
   <dependencies>
      <dependency>
         <groupId>net.sf.jasperreports</groupId>
         <artifactId>jasperreports</artifactId>
         <version>4.0.1</version>
      </dependency>
   </dependencies>
   
   
   <build>
      ...
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jasperreports-maven-plugin</artifactId>
            <version>1.0-beta-2</version>
            <executions>
               <execution>
                  <goals>
                     <goal>compile-reports</goal>
                  </goals>
                  <configuration>
                     <!-- define where is your jrxml file -->
                     <sourceDirectory>src\\main\\java\\gov\\fdc\\nig\\report\\templates</sourceDirectory>
                     <sourceFileExt>.jrxml</sourceFileExt>
                     <compiler>net.sf.jasperreports.compilers.JRGroovyCompiler</compiler>
                     <!-- define where is the jasper file will be generated -->
                     <outputDirectory>src\\main\\resources\\report\\jasper</outputDirectory>
                  </configuration>
               </execution>
            </executions>
            <dependencies>
               <!--note this must be repeated here to pick up correct xml validation -->
               <dependency>
                  <groupId>net.sf.jasperreports</groupId>
                  <artifactId>jasperreports</artifactId>
                  <version>4.0.1</version>
               </dependency>
               <dependency>
                  <groupId>org.codehaus.groovy</groupId>
                  <artifactId>groovy-all</artifactId>
                  <version>1.7.5</version>
               </dependency>
            </dependencies>
         </plugin>
      </plugins>
   </build>

2. mvn install
3. check result

Benefits
1. Automate jrxml compilation process
2. We won't forget to compile jrxml file and lead to our program read old jasper file

2010/10/19

Apache Maven Quick Start


M2Eclipse Installation

1. Select Help > Install New Software. This should display the "Install" dialog.
2. Paste the Update Site URL into the field named "Work with:" and press Enter.
Pressing Enter should cause Eclipse to update list of available plugins and components.
m2eclipse Core Update Site: http://m2eclipse.sonatype.org/sites/m2e

3. Click Next

4. Choose "I Accept...", and click Next

5. downloading M2Eclipse jar files

6. Restart Eclipse


Create a Maven Project

1. New a project --> Maven Project

2. Click Next

3. Choose"maven-archetype-qiickstart", and click next

4. fill in group id, artifact id, version. Click finish.

5. Your Maven Project had been created.


6. Go to find out specific jar file: http://mvnrepository.com. For example, I would like to use commons lang in my maven project.

7. Choose specific jar file

8. Copy dependency tag to my pom.xml

pom.xml

9. You can find out commons-lang-2.5.jar had been downloaded.

10. I can import StringUtils in my class.