This is a follow up question to this question:
java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication Maven
I have developed a web service using Eclipse on Windows. I need to run it on a Solaris station and there I get the ClassNotFoundException.
This is my pom.xml: (that maven shade plugin is something I've read about that can create an uber jar with all the dependecies).
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
And this is the exception I get when trying to run the jar on Solaris:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
The project got a "Maven Dependencies" folder with many jar files of the Spring framwork.
I did not really understand the answers to that question. The main answer suggested creating a consolidated jar as shown here: How can I create an executable JAR with dependencies using Maven?
But i did not fully understand how to create that conolidated jar. Do I need to add the lines in the answer to the pom file? or somewhere else? and running the mvn clean compile assembly:single should be done in windows in the command line? and if so on which path? won't just exporting to jar suffice?
If someone could make a list of operations of what to do, that'll be great.
What no one ever said in the answers to other questions is that you need to use maven to create the jar and not using Eclipse's export to jar option. What you need to do is:
1) download maven from https://maven.apache.org/download.cgi
2) The maven dir contains a 'bin' folder. Add this folder to your "path" enviornment variable (on Windows 8 right click "This PC" -> properties -> Advanced System Settings -> Environment Variables -> in System Variables find "Path" -> double click it and add it by adding the bin folder path to that variable the same way other paths are located there.
3) open CMD
4) navigate to your project's folder
5) type mvn package
The jar file is created inside the "target" folder.
Good luck
The spring-boot-maven-plugin already creates a runnable JAR with all dependencies in it when you run mvn package (this is one of the main purposes of Spring Boot). So remove the maven-shade-plugin, because this is not necessary (in fact, i think it is the real problem because it will interfere with Spring Boot).
what worked for me:
cd to THE_PROJECT_FOLDER via the cmd or git bash
mvn clean
maven install
maven package
go to the project using your IDE and go to the class containing the main method
Click on the #SpringBootApplication and see to the left an icon like a lamp
Click on it and select download with maven
Restart the server, everything is OK !!!!
Adding the following plugin in pom.xml solved the issue for me:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
Related
Goal
I want to use a private repository as a library in other spring boot projects by hosting it as a GitHub package.
Library project
https://github.com/sagarnayak/privatecentralrepo
Client Project
https://github.com/sagarnayak/repoclientproject
Steps To Reproduce
the library project has a library001 module. this is what I want to use as a library for other projects.
In the library module pom file, I have added the repackage execution goal.
......
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
......
I want to use the module as a library and host it as a private GitHub package.
When I do the mvnw deploy in the library001 module this should create an exec jar and push to GitHub to use this library in other projects.
Github has this exec jar.
To use the jar in the client project I have added this as a dependency in the client project.
<dependency>
<groupId>com.sagar</groupId>
<artifactId>libraray001</artifactId>
<version>0.0.3-SNAPSHOT</version>
<classifier>exec</classifier>
</dependency>
This gets the project into the external libraries part of the client project. and this has the class that I want to use in the library (TestModel001).
But when I try to import this into any classes that I want to use it can not resolve the import.
How do I use the library project in this project?
I solved the issue with this -
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
The issue was with the pom file.
I was using the configurations for an older version.
The client project as visible at sagarnayak/repoclientproject is not configured to consume the artifacts from the private Maven repository hosted on GitHub as described in the Working with the Apache Maven registry.
Specifically, following settings are missing:
<repositories> configuration in pom.xml
<servers> configuration in local settings.xml
Add following elements to the pom.xml:
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/sagarnayak/</url>
</repository>
</repositories>
Add following elements to the settings.xml
<servers>
<server>
<id>github</id>
<username>sagarnayak</username>
<password>YOUR_PERSONAL_ACCESS_TOKEN_HERE</password>
</server>
</servers>
Note: Keep settings.xml local to your machine - don't leak that Personal Access Token!
You are packaging the library via spring-boot-maven-plugin
It produces a JAR that has a self-running spring boot structure, and so you are unable to import it as a library correctly.
Try to remove spring-boot-maven-plugin from your libraray001 pom.xml, rebuild, republish and try to consume that artifact in your client project again, refreshing the dependencies and preferably bumping up the library version, to exclude caching possibility during the test.
I am trying to build eclipse plugin using tycho-compiler-plugin from maven.
I have resolved many bundled dependencies from p2 repo. I have some jar dependencies which are present in bundle-classpath in manifest.mf -
Bundle-ClassPath: .,
lib/test1.jar,
lib/test2.jar
These jars are present in lib folder which is present at root level i.e where pom is present.
POM file looks like -
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>com.test.plugin</artifactId>
<version>0.0.0</version>
<packaging>eclipse-plugin</packaging>
<repositories>
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>file:///E:/repo/eclipseRepo/</url>
</repository>
</repositories>
<build>
<directory>../../../../target</directory>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.25.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>0.25.0</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>0.25.0</version>
<configuration>
<buildDirectory>../../../../plugin</buildDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now ti builds eclipse plugin properly , but while packaging it also includes lib folder. Attached jar screenshot -
I want to exclude this lib folder from jar.I have tried configuration in tycho-packaging-jar plugin to exclude it. But not working. How to exclude it?
Using a <directory> or <buildDirectory> outside the current project’s base directory looks fairly non-standard. In fact, I have never had the need to explicit configure either of these – or <sourceDirectory>, for that matter. That’s what the build.properties file is for, which is the default way to configure these things in both Eclipse PDE and Tycho.
From the screenshot it looks like there is no build.properties file present. I would suggest you configure the various locations through its properties rather than through POM elements. Something along the lines of this example, with bin.includes and bin.excludes handling your JAR inclusions.
This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
SpringSource.org changed their site to http://spring.io
Does someone know how to get the latest build without Maven/github? from http://spring.io/projects
Please edit to keep this list of mirrors current
I found this maven repo where you could download from directly a zip file containing all the jars you need.
https://maven.springframework.org/release/org/springframework/spring/
https://repo.spring.io/release/org/springframework/spring/
Alternate solution: Maven
The solution I prefer is using Maven, it is easy and you don't have to download each jar alone. You can do it with the following steps:
Create an empty folder anywhere with any name you prefer, for example spring-source
Create a new file named pom.xml
Copy the xml below into this file
Open the spring-source folder in your console
Run mvn install
After download finished, you'll find spring jars in /spring-source/target/dependencies
<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>spring-source-download</groupId>
<artifactId>SpringDependencies</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>download-dependencies</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Also, if you need to download any other spring project, just copy the dependency configuration from its corresponding web page.
For example, if you want to download Spring Web Flow jars, go to its web page, and add its dependency configuration to the pom.xml dependencies, then run mvn install again.
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
There currently is a Continuous Integration framework running Selenium scripts with maven 3.0.4 which are invoked by Jenkins. I've created a project in SoapUI containing a number of tests within a test suite. I'd like to be have the SoapUI scripts to run as part of the existing Continuous Integration process but can't seem to get it going. I'v done extensive research and thus this is my last resort. Can somebody please provide step by step instructions on setting this up? I've done the following so far:
Created a folder in the Workspace directory for the REST tests.
Created an src folder within the above mentioned directory (Workspace). The src folder consists of the following structure: src/test/soapui/xml file with the name of the soapui project
Directly within the src folder I have a pom.xml file with the following:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Web Service Test Module</name>
<groupId>com.dstvo</groupId>
<artifactId>SOA-Tesing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<description>Web Service soapUI integration tests</description>
<pluginRepositories>
<pluginRepository>
<id>eviwarePluginRepository</id>
<url>http://www.soapui.org/repository/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>eviware</groupId>
<artifactId>maven-soapui-plugin</artifactId>
<version>4.0.0</version>
<configuration>
<projectFile>src/test/soapui/REST-Testing-soapui-project.xml</projectFile>
<host>local host and port</host>
<outputFolder>${project.build.directory}/surefire-reports</outputFolder>
<junitReport>true</junitReport>
<printReport>false</printReport>
</configuration>
<executions>
<execution>
<id>Soa_Tests</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I don't know if the pom.xml file is all that's needed in order to have the soapui tests run with maven or if there are some steps that I'm missing? Please help?
Here https://stackoverflow.com/a/17802822/2324993 I've already answer how to run soap ui tests via shell script.
So you just need to run this script with maven. You can do it for example with this maven plugin: http://mojo.codehaus.org/exec-maven-plugin/usage.html. You can use it to execute a shell script, or any other executable
I am using a local repository as described in Maven: add a dependency to a jar by relative path.
The repository-url is defined in the topmost pom.xml as
<url>file:${basedir}/../3rdParty/maven-repository</url>
Also, the topmost pom.xml defines 2 modules
<modules>
<module>sub1</module>
<module>sub2</module>
</modules>
The problem is, that if a module (say sub1) defines a dependency that should be downloaded from the repository, and maven is called from the topmost directory, the ${basedir} is not set to this directory, but to sub1, resulting in a wrong repository-URL.
So, say the project with the topmost pom.xml resides in
/Development/myproject/pom.xml
And the repository is in
/Development/3rdParty/maven-repository
Then the repository URL should be set to
/Development/myproject/../3rdParty/maven-repository
but it turns out it is set to
/Development/myproject/sub1/../3rdParty/maven-repository
which of course does not exist.
Any idea why that is the case?
Although it is annoying in your case, this is well-known and intentional. A maven project should know about its execution directory only, no matter in what context it is executed.
I asked almost the same question: Maven variable for reactor root earlier, and the only answer that made sense was to use ${user.dir}, although it's hacky and will not work if you build from a module directory.
(There is also this very verbose solution: Maven2 property that indicates the parent directory)
You can determine the root directory of a module with this nice plugin:
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
<version>0.3.1</version>
<executions>
<execution>
<id>directories</id>
<goals>
<goal>directory-of</goal>
</goals>
<phase>initialize</phase>
<configuration>
<property>maven-parent.basedir</property>
<project>
<groupId>my.group</groupId>
<artifactId>maven-parent</artifactId>
</project>
</configuration>
</execution>
</executions>
</plugin>
Use the directory like this: ${maven-parent.basedir}
How about having multiple repos?
<repositories>
<repository>
<id>ibm-jars-bundle-lv0</id>
<url>file://${basedir}/ibm-jars-bundle/repo</url>
</repository>
<repository>
<id>ibm-jars-bundle-lv1</id>
<url>file://${basedir}/../ibm-jars-bundle/repo</url>
</repository>
<repository>
<id>ibm-jars-bundle-lv2</id>
<url>file://${basedir}/../../ibm-jars-bundle/repo</url>
</repository>
</repositories>