Question: I am using "spring MVC" to build something(**project “A”**). I use maven to get the jar I need.

But I have a question, if I have a Java file(**a separate file**), a class in it, how can I use it in **project “A”** just like the other in pom.xml?

maybe it like this： when i use JSONObject i must edit pom.xml like:

```
<dependency>
        <groupId>net.sf.json-lib<groupId>
        .........
    </dependency>

```

I mean i want my java file like JSONObject,i put it in pom file when it want use it in some project:

test.java:

```
class bc {
    public String test() {
        return "bc->test";
    }

}

```

pom.xml

```
<dependency>
    <groupId>test<groupId>
    .........
</dependency>

```

controller file (in springMVC)

```
import ...

@controller
@requestMapping(value="/api")
public class apiController {
    @RequestMapping.....................
    public @ResponseBody String testMyMavenClass() {
        return new bc().test()
    }
}

```

Answer: 
Im not sure about how to use .class in maven pom file but Im sure you can define your own jar file.   

First, combine your classes into jar file.  

Then, Define it inside pom.xml as external library.
Reference: <https://www.tutorialspoint.com/maven/maven_external_dependencies.htm>   

One more note, you can add below line to make sure maven knows where is external repository:

```
      <repositories>  
          <repository>  
              <id>in-project</id>  
              <name>In Project Repo</name>  
              <url>file:/${project.basedir}/libs</url>  
          </repository>  
      </repositories>  

```
**Method 1**: Install jar file to local maven repository:

* Export your project to jar file, then
* <http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/>

**Method 2**: Use a repository manager. This is more advanced and requires some server skills. I can give you the name & link only, and you should do your research your self: <https://www.sonatype.com/download-oss-sonatype>