4

I have created a maven project in eclipse and I want to deploy it on a server(tomcat I guess). I believe this can be done via spring boot. My question is this: this project has imported several jar files located on my PC and has another project that is in the workspace in its build path. I worry that during the integration(turning it into maven) I might lose all the dependencies. What is generally the best way to import jar files to a project and how to add another project in its build path? Please comment with any other specifications that you need.

This is the pom.xml

<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>org.apache.jena</groupId>
  <artifactId>jena-examples</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Apache Jena - Code Examples</name>
  <description>A collection of example code illustrating uses of Apache Jena</description>
  <url>http://jena.apache.org/</url>

  <properties>
    <ver.jena>[3.1.0,)</ver.jena>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <organization>
    <name>Apache Software Foundation</name>
    <url>http://apache.org</url>
  </organization>

  <dependencies>
    <dependency>
      <groupId>org.apache.jena</groupId>
      <artifactId>apache-jena-libs</artifactId>
      <version>${ver.jena}</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-cli</groupId>
      <artifactId>commons-cli</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.9</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.3.6</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpasyncclient</artifactId>
      <version>4.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpmime</artifactId>
      <version>4.3.6</version>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20140107</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8</version>
    </dependency>
    <dependency>
     <groupId>org.glassfish.jersey.core</groupId>
     <artifactId>jersey-client</artifactId>
     <version>2.8</version>
 </dependency>
 <dependency>
     <groupId>org.glassfish.jersey.media</groupId>
     <artifactId>jersey-media-json-jackson</artifactId>
     <version>2.8</version>
 </dependency>
 <dependency>
        <groupId>com.github.galigator.openllet</groupId>
        <artifactId>openllet-owlapi</artifactId>
        <version>2.6.4</version>
    </dependency>
    <dependency>
        <groupId>com.github.galigator.openllet</groupId>
        <artifactId>openllet-jena</artifactId>
        <version>2.6.4</version>
    </dependency>
  </dependencies>

</project>
Stelios Botonakis
  • 183
  • 1
  • 3
  • 11

2 Answers2

5

For integrating local jar files in your maven project, have a look to: How to add local jar files to a Maven project?

To add Spring Boot to your pom.xml, you need to add the following (from this doc

<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
</parent>

<!-- Add typical dependencies for a web application -->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

<!-- Package as an executable jar -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
charlycou
  • 1,778
  • 13
  • 37
  • I did configure my pom and I think spring was built correctly but my jars are simply too many to add each of them seperately. Will I still be able to make my application run on a centos 7 VM tomcat server when the jars are stored locally on my PC? – Stelios Botonakis May 22 '19 at 21:42
  • I guess you could do that with several steps: 1 - package your spring application as war 2 - mount the folder where your local jar are stored on you VM 3 - setup the classpath of your application with the mounted folder to be able to resolve dependencies. Although I highly suggest you to store your local dependencies in a /bin folder in the base repository of your application and to add then using maven. Much more reproducible. – charlycou May 23 '19 at 09:22
  • I would also recommend to use SpringBoot embedded Tomcat by packaging your application as a jar file. If all your local dependecies are specified in your pom.xml, you could produce the jar file of your application and deploy it wherever you want as long as there is java installed. – charlycou May 23 '19 at 09:28
  • What do you mean by "you to store your local dependencies in a /bin folder in the base repository of your application and to add then using maven"? Can't I just add them to build path like always? Do I need to do something maven specific with the jars? – Stelios Botonakis May 23 '19 at 12:48
  • I understood the part about sroring them in the lib folder inside the project but I added them to build path normally. – Stelios Botonakis May 23 '19 at 14:37
2

i think you have a bit of a misconception of what spring.boot actually is.

Spring-boot is a complete eco system for building a microservice integrated with a lot of well used java libraries.

Your pom seams to be a fully written application made to be deployed onto an empty tomcat server. Spring-boot is not an empty tomcat, spring-boot is an application/framework that uses tomcat under the hood.

What you need is to go over to http://tomcat.apache.org/ and download the tomcat server and then google how to setup/start tomcat in your choice of IDEA. After that is done you need to open the maven project in your IDEA of choice and deploy it to the tomcat server.

Using eclipse/intellij there are several tutorials on the internet explaining how to install and setup tomcat. And also tonnes of tutorials in how to import maven projects and build and deploy to tomcat.

Toerktumlare
  • 12,548
  • 3
  • 35
  • 54
  • What do you mean by empty? I already have tomcat installed on a centos 7 VM and I want my java application to run on that server. What I also worry about is all the jars that that are somewhere stored in my PC and how they can be "uploaded" and integrated with the rest of the java program and not get any errors that I want to be able to send and receive requests on the server as well as another project which is in the same workspace and I have built the path to use that project's code. I did add spring boot as the top answer suggests but I didnt to the same with the jars as they are too many. – Stelios Botonakis May 22 '19 at 21:40
  • when you build something using maven, all the specified dependencies in your pom.xml will be bundled in the jar that in the end is produced. So running "mvn clean install" will produce a target folder. In that folder you will have a jar that is your program that contains your code, and all the bundled jars that are defined in your pom.xml. This jar needs to be deployed to your tomcat server. I suggest you look up a maven tutorial, and then a deploy to tomcat tutorial online. – Toerktumlare May 22 '19 at 23:21
  • tomcat is an application server. Meaning you can deploy applications to it. So you have an empty tomcat server running. And then you deploy your application to it (your jar) – Toerktumlare May 22 '19 at 23:23
  • here are several different ways of deploying an application to tomcat https://www.baeldung.com/tomcat-deploy-war – Toerktumlare May 22 '19 at 23:25
  • Another question. I have Java installed in my VM but do I also need to install maven? And also when I am building my project with maven which commands must I run and in which order: mvn compile? validate? install? clean install? initialize? I guess mvn package comes last. – Stelios Botonakis May 23 '19 at 12:44
  • When I run mvn compile I get some errors saying that some packages cannot be found and then some symbols cannot be found as well. – Stelios Botonakis May 23 '19 at 12:51
  • yes you need to install maven, and to understand all the maven commands i suggest looking up some tutorials on how to use maven because that is way to long to explain here. And if you have more questions start a new thread with your questions. If it says some package cant be found, then some packages cant be found. And some symbols cant be found. Please if you are going to ask questions you have to be very detailed in your questions. – Toerktumlare May 24 '19 at 10:42