spring boot - no main artifact - spring

I have created a Spring Boot application, I have build the project and selected the main class and I have also added properties in my pom.xml:
<properties>
<java.version>1.8</java.version>
<start-class>com.mua.scraper.ScraperApplication</start-class>
</properties>
Now the problem is when I try to run the .jar file, it tell me that MainClassNotFound. Here is a snap:
Later project will be opend here
After changing the command, here is my output:
Error:
No main artifact

You are missing -jar to properly run the jar file. It should be:
java -jar scrapper.jar

Actually the problem was in my artifact, so here is what I have done:
Opened Project Structure(CTRL+ALT+SHIFT+S)
Navigate to Artifacts -> JAR -> From module with dependencies
Then Selected Main class, or the entry class
Copy the output directory and link via manifest(I made the mistake here)
Don't forget to select that directory as in the picture

Related

include jar of one module to another

I have maven projet with this architecture:
++parent-project
+module-a
+module-b
module-b is a web application. it will be run on Jboss AS 7.1.1. I'm using netbeans IDE.
Now module-b depend on module-a. this is a porm section of module-b:
<dependency>
<groupId>groupid</groupId>
<artifactId>module-a</artifactId>
<scope>compile</scope>
</dependency>
When i build the war file of module-b, module-a is not present to lib folder ( in war file. i open it with archive explorer ). therefore JBoss return ClassNotFoundException.
I'm tried differends scope ( compile , provided , runtime , test ). But nothing.
Please how can i solve this.
First of all, I think you should try to see how does it work in "pure" maven, without the IDE at all (NetBeans). So my answer will be based only on maven knowledge:
A couple of facts:
Module b has to have the following in pom: <packaging>war</packaging> This will instruct maven that you really want to get a war from this module.
When packaging WAR is specified in some pom, maven will take all the dependencies defined in this pom and will put them into the WEB-INF/lib folder of the war. Automatically. Of course, you can customize the output, but its more advanced stuff (see Maven WAR plugin if required)
All the dependencies have to be defined with group id, artifact id, and version at least. So make sure that you have the dependency on module a with version. There is no need to fiddle with scopes in this case. The default scope (if you don't specify a scope at all) is 'compile' which is fine.
Go to the directory of module b and from within the directory type: mvn dependency:tree. Once its done, please carefully observe the output, especially make sure that module a is listed (with a correct version) in a tree.
Sometime to make sure that no stale artifacts reside in the local m2 repository you might want to delete all the jars of your project from there and then execute the mvn package command again. The war has to be created in module b/target - and this is the WAR you should check out.
Note, all these steps are done without any interaction with NetBeans at all.

Maven ant task to add system path jar to WAR file

Running into a small problem. I have a spring-maven project. And there are some external jars I need to add into the POM which I did using .
Now to build the WAR file we are using an Ant Maven task i.e. artifact:mvn providing the argument war:war.
Here somehow my external jars are not getting added to the WAR file i.e. WEB-INF/lib
Can some one please let me know if I am missing something. Below is my pom entry
<dependency>
<groupId>{test}</groupId>
<artifactId>Test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/test.jar</systemPath>
</dependency>
Best solution is to start using a repository manager (a.k.a "Maven proxy server") and install the needed artifacts (test.jar) into the repository manager and use it as a usual dependency instead of using system scope via systemPath.
Calling mvn war:war via Ant does not make sense and shows you should learn how Maven works.
Change the packaging type in your pom file to war and you can simply call maven via:
mvn clean package
and everything should work. But this is only gues cause you didn't show your full pom file.
Install the test.jar locally using mvn install:install-file (docs). Now you can remove the system scope (and the systemPath) and everything will work out of the box.

How to avoid creating empty jar in non-Java Maven project?

I have a Maven project which uses a jdeb plugin to generate a deb (Ubuntu installer) package with some simple shell scripts that I would like to send to a customer to be able to deploy easily. This project has no Java whatsoever. I am not specifying in the pom.xml that it should package a jar. However, an empty jar does get packaged in the project's target directory anyway.
How can I avoid creating this empty jar file? I am not sure if it gets included in the deb package but if it does, it is just dead weight size-wise.
Got it figured. In the pom.xml the following needs to be added at the same hierarchy level where the <name>...</name> is for that project:
<packaging>pom</packaging>
Otherwise
<packaging>jar</packaging>
is assumed as a default.

Cant get Spring SAML2 working

I can't seem to get saml2 working. Here is what I have done.
I downloaded the sample application from here: https://github.com/spring-projects/spring-security-saml, this was a link from their documentation: http://docs.spring.io/spring-security-saml/docs/1.0.x/reference/html/chapter-quick-start.html
1) converted the sample application 'saml2-sample' into an eclispe project: mvn eclipse:eclipse
2) built the project: mvn package
3) added the 'Dynamic Web Module` facet to the project:
Right Click on project > Properties > Project Facets
4) Run the application on the STS Server:
Right Click on project > Run As > Run on Server
Server starts up and everything looks ok in the console except the url loads with HTTP Status 404 - /spring-security-saml2-sample/ at the URL http://localhost:8080/spring-security-saml2-sample/
Please, follow these steps:
Download the project from Github as archive.
Unzip the archive.
By STS/Eclipse: File > Import > Existing Maven Projects and select as root dir {your_download_folder}/spring-security-saml-master/sample folder.
Now, you may see these errors:
Fix the pom.xml as shown in this gist.
In the end, you may also fix the MetadataController class (note that some methods have changed between versions).
The easiest way is to remove that class, otherwise you should fix it manually.
Finally, run the project as webapp.
That's all!
Annotation-based configuration
If you would like to use an annotation-based configuration, you could see this one: spring-boot-security-saml-sample.
The try to change the Spring Framework dependency to latest version's like 3.2.13 or 4.0.9. I'm able to run the application successfully with both of these dependencies. Also when you're updating spring dependencies, please make sure to change xsd version to what you're using spring version "securityContext.xml" and "saml-servlet.xml".
Fyi - I've use following versions in a pom.xml file
<properties>
<junit.version>4.12</junit.version>
<jsp-api-version>2.0</jsp-api-version>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.security.version>3.2.5.RELEASE</spring.security.version>
<spring-security-saml2-core-version>1.0.0.RELEASE</spring-security-saml2-core-version>
<slf4j-log4j12-version>1.7.10</slf4j-log4j12-version>
<jstl.version>1.2</jstl.version>
</properties>

Java Maven Project appears in another project as directory not a jar

So, I created a Spring Maven Project, a Dao Project, which works great. All the code is in the correct place, all the unit tests run, and I can do a mvn clean install. I can see in the target directory that there is a build jar, and everything in it looks fine. I can also confirm that when I check my local .m2/repository, the latest jar I just built is in there.
Here is a small segment of that pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Project DAO</name>
Now, I am creating a new Spring Maven Web-Project for my UI, and this pom.xml starts out like:
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-ws</artifactId>
<name>My Web Project</name>
<packaging>war</packaging>
Also in this pom.xml file, one of the first dependencies I have is:
<!-- My DAO ProjectDependencies -->
<dependency>
<groupId>com.tom.myproject</groupId>
<artifactId>myproject-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
I can see in eclipse that when I try to access the classes from this dao jar, that seems to work fine. When I compile the code here, that all works fine. And when I do a "mvn clean install" to build this war, I can see the target directory, and all the needed classes and jars come in, obviously there are hibernate, logging, and spring classes that are there in the WEB-INF/lib directory.
Now this is he part where the question comes in ... Why does the myproject-dao show up under WEB-INF/lib as WEB-INF/lib/myproject-dao-0.0.1-SNAPSHOT.jar but appears as a directory, and not a jar?
Certainly when I pull in other jars, they are just .jar files and not directories.
I should add, when you look in the Eclipse project under maven dependencies, the icon for all the other jars show them as files. The icon for my myproject-dao.jar uses the icon for a folder/directory, so clearly a directory named "myproject-dao.jar" is being created and not a file with zipped up contents into a jar file.
When I build the war file, and deploy the war, the app says it cannot find any of the classes in the myproject-dao.jar directory. I have to delete the FOLDER "myproject-dao.jar" from the WEB-INF/lib directory and manually copy over the FILE "myproject-dao.jar". I can then clearly see the icon that means this really is a file.
This is probably a simple fix, so if you can help me out, that would be great.
ANSWER:
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
I wasn't using the maven-assembly-plugin. But, I did find out what the problem is.
Both my DAO project and the WEB project are in the same workspace, and the DAO project was open, as a result, the maven dependency shown in Eclipse was a folder icon, and not the jar icon. When I closed the DAO project and looked back at the maven dependencies on the WEB project pom.xml file ... NOW it shows the icon as a jar and not a folder.
So, all I have to do build my dao.jar file with maven, and when it is successful, it is done.
Then I have to CLOSE the project within Eclipse.
In my web project pom.xml file, the icon will now show this as a jar file, and when it builds, it will pull in the jars.
I imagine this is a benefit if one is working on several prior project, you really do have the chance to look at what is in the jar file while the war is running.
In my case, I know my dao.jar is working, so I can build it, and close the project, and then make use of that jar anywhere I need it.
Thanks for the help!

Resources