I am in a project which uses hibernate, spring, and apace camel as third party tools. To launch the project I create a war file using maven and then run it using Jetty (jetty-distribution-8.1.14.v20131031).
Now I am supposed to add a new simple functionality on the project startup. It can be something as simple as adding a print line, but there is no main() function.
I have the output lines that the project printed to a file:
http://paste.kde.org/pnhee4u7s
I have read the file but all I see is calls by hibernate, apache and spring. All are third party tools. I have no idea how to do this, and I appreciate any possible help :s
If you're writing a Web application with a war, start with your web.xml; if you're using traditional configuration, that's where Jetty starts loading your app.
Since you're using Spring, I recommend writing an #Component that logs on startup, or adding such logging to an existing component or #Configuration.
Related
I need help here with the below issue. I am learning JMS and I am quite new to it. I came across a tutorial which I was following, however when I try to run this by selecting the project in eclipse I do not get an option to run on server. Is there a way we can run a simple java application on application servers?
Below is the link to the tutorial I am following
https://www.javatpoint.com/jms-tutorial
I have mostly worked with dynamic web projects for which the option is present to run on server.
I have not posted the code as it's the exact same as given in the tutorial.
For that you need to figure out which server(s) you want to deploy JMS. You can go with Weblogic or with ActiveMQ.
Below are the 2 reference links that would actually help you to resolve your query :
http://www.catgovind.com/java/test-weblogic-jms-java/
https://javainsider.wordpress.com/tag/jms-with-activemq-sample-example/
Yes, I would suggest you to go through spring-boot.
Here, you have an option to try a simple Hello World application
http://www.mastertheboss.com/jboss-frameworks/spring/your-first-jms-application-with-spring-boot
In the above example, you just have 2 java classes and one maven pom xml file to edit :)
Just try it out.
You can configure it to run from your eclipse too.
In/with spring-boot -
you don't have to do any web-server configuration on your own. Spring boot itself contains a web container.
It just creates a JAR file with which you can just run your application as "as your run a jar" which has your code + server.
And my last point is - you will get lots of support from different forums as spring boot is used widely.
I am a Spring Boot newbie. I'd like to initialise a project which consists of:
A console application that acts on command line arguments so the JAR files could be later used in scheduled tasks.
Consumes a RESTful service
Logging
Which package dependencies should I choose in Spring Initializer? Apart from the necessary packages, are there any libraries that are optional but make development easier?
Depends on how you want to consume the restful service, but you may not need any extra starters, the core spring-boot-starter that you get when you just hit "Generate Project" and is usually implied with all the common starters like -web, -security, .. has logging and dependency injection and is all you need to create a jar that can easily be started with java -jar
However, it does not come with RestTemplate which is a common way to build rest clients in spring. For that you'll need to manually add a dependency on org.springframework:spring-web like you can see examples for in https://spring.io/guides/gs/consuming-rest/
But you can as well use other rest client libraries if you like them better.
There is also Feign that can be used as rest client and it's available from the initializer, examples at https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html - have not tried it and I'm not sure how much extra cloud dependencies will be added when you add the starter.
I also like having Lombok in all projects but that's preference. The obvious sounding choice of DevTools doesn't give you much benefit in a console application but is great for live reloading of web servers.
[...] so the JAR files could be later used in scheduled tasks.
sounds like you're trying to create a library / module of a larger application. You don't need an application that works standalone for that though so maybe https://spring.io/guides/gs/multi-module/ is good to read for you. Difference for libraries is that you don't need the spring boot plugin for maven/gradle which can package a standalone jar, just the dependency management.
I am going to create Java Application that can load external jar files at runtime by FileChooser. I am using Spring Framework, and I want to load jar file and its applicationContext.xml file and inject its dependencies dynamically. I tried to achieve this by OSGi, but it seems very complicated so that I am searching another appropriate variants.
I want to make something like Intellij IDEA plugin installation from the disk.
How can I do this? (After the jar file chosen restarting an application also accepted)
I realy like your approach, unfortunately spring has lifecycles that are strict. As you might know, spring autowires "beans" only. Exactly one lifecycle registers the different bean candidates. After that lifecycle spring (by default) does not accept new classes.
You must use the spring-osgi.
If you only need the CDI part out of spring, you might like to use a different CDI like red hat's jboss server.
I am trying to create a java email batch program that sends an email with an attachment each day to a specific email address, and I have to use Spring as the framework for this program. It is not going to be a web application, but since I'm implementing Spring into this, how would I go about this? I am totally new to Spring (and Java for that matter), but am unsure of which direction I need to go. Which jar files do I need? Spring Batch or Spring Framework? Also, where can I download the jar files for Spring Framework? The spring.io site won't let me download those jar files.
I very strongly suggest you use a build tool that handles dependency management. Such tools are Ant+Ivy, Maven and Gradle. They will take care of downloading the appropriate jars based on your declaration of what dependencies you need and will take care of all the transitive dependencies.
One good way of getting started with Spring Batch is to follow this tutorial using either Maven or Gradle (the latter would probably be easier since you don't need to install it - the tutorial's code has a wrapper).
The tutorial uses Spring Boot which vastly simplifies Spring configuration (which is a serious benefit especially for someone who is new to Spring)
As others already told you, I personally would not start any spring based project (means: any project) without maven! You have so much benefits from it, not only depencency management.
To start a spring app outside an application context:
#Configuration
public class AppConfig {
//any bean configurations here
}
//your entry class
static void main(String args[]) {
//get a reference to the spring context. use this context throughout your app!
ApplicationContext ctx = new AnnotationConfigApplicationContext(CacheConfig.class).get();
//optain any beans from the context. inside these beans, you can use any spring feature you like, eg #Autowired
ctx.getBean(YourBean.class).executeMethod();
}
I'd recommend starting with Spring Boot which will handle all of that for you. As others have mentioned, pick a build tool (Maven or Gradle) and follow the guide we provide on building a batch application here: http://spring.io/guides/gs/batch-processing/.
I'm creating a web application that uses Apache Tomcat (Latest), Spring 3, Struts2 and Hibernate. I need to have a listener that observes a directory for any new XML files that appear. While the web application is deployed onto Tomcat and running it should keep doing this.
What method is recommended when doing something like this, using these frameworks?
Are there any examples that I can look at to assist with the beginning stages?
Try jdk7 WatchService. I have already done it a project which has a similar structure to the one you have. Otherwise you could try to use FileAlterationListner from org.apache.commons.io. I would rather go for jdk7 as it worked perfectly.
i have used JNotify in one of the project, it worked like charmed, if switching to JDK 7 is not possible.