Java bean server not running properly - java

I am currently using java beans to create an application with a remote interface, i have very simple methods like printDetail which returns "abcd", just a test method. I have a session bean like this:
#Stateless
public class MySession implements MySessionRemote {
#Override
public void businessMethod() {
System.out.println("aaaababa");
}
when i deploy the server, i get this error:
SEVERE: CORE10012: Application previously deployed is not at its
original location any more
I use Glassfish 3.1

I Found the solution, go to your browser type localhost:4848, select applications in left list, disable any other running apps that was deployed. e.g mine was saying something like
SEVERE: CORE10012: Application previously deployed is not at its original location any more "C:user/ .... / XYZ "
Then you should disable the app XYZ because apparently the server is still running this app even if you have created a new one.

Related

REST: run main method from a jar located inside "/web-inf/lib" of a web project

I'm using Jersey 1.x and Tomcat 8.0. I have a .jar file which is my main application that I've uploaded to "/web-inf/lib" of a Dynamic Web Project.
I can't seem to figure out how to run a class which contains a main method inside this jar, which is crucial for my web service because It creates a connection to the Derby DB and all my web service methods are using these connections.
It has to start running when Tomcat server starts.
That is most definitely not the way to do it. If you want to have something run when Tomcat starts, take a look at ServletContextListener. Basically you implement this interface:
import javax.servlet.ServletContextListener;
public class MyContextListener implements ServletContextListener {
#Override
public void contextInitialized(ServletContextEvent sce) {
// your init code goes here
}
}
However, I question that even this is what you want to do. If you're using a local or embedded Derby instance then you're probably ok but now you'll have to distribute the connection information some how. Traditionally in an application like you have you'll use something like DBCP (included with Tomcat - take a look at the Tomcat DataSource docs) and get the connection to the DB every time you need it. If you are just initializing the DB then ServletContextListener will allow that. But after that, don't use the ServletContextListener to also hand out database connections.

How to enable remote management operations in Wildfly

Trying to read some values from my standalone.xml in Wildfly, I have got the following error message:
{
"outcome" => "failed",
"failure-description" => "WFLYCTL0379: System boot is in process; execution of remote management operations is not currently available"
}
In JBoss 7.1.1 it works fine, please see my java coding inside Ejb Singleton:
#Startup
#Singleton
#ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class TestBean {
#PostConstruct
private void init() throws Exception {
final ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set("read-resource");
request.get("recursive").set(true);
request.get(ClientConstants.OP_ADDR).add("subsystem", "security");
final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("127.0.0.1"),
9029);
final ModelNode response = client.execute(new OperationBuilder(request).build());
}
}
This error comes at the moment when the client.execute() tries to get ModelNode.
I'd appreciate any help!
Don't know what El Lord Code was trying to accomplish, but in my project, for example, we are using the pattern of Startup Singleton to initialize the application. Now, during that thing, we need to do some programatic login - logout to Wildfly and the logout does some credential cache flushing which depends on acccessing the security domain. The problem is that this whole remote management is not accessible during startup and shutdown (it starts after and ends before the application is started / stopped).
I have posted a similar question here: https://developer.jboss.org/message/944842#944842
The Error is stating that Wildfly is still deploying some WAR/application
In this period the management is still not accessible.
Try to start the Wildfly without any applications in deployment folder and then try to read the standalone config for what ever needs.

Vaadin and JPARepository: transaction errors

I'm having troubles in integrating Vaadin and spring-data (JPARepositories in particular).
After following the guidance of Vaadin's team with their last webinar I managed to configure my application using Spring starter (spring boot), adding Vaadin, JPA and a Postgresql database. Using this method was really straightforward and loading entities to a table works out of the box by simply having this
#Autowired private ProjectDAO projects;
// other code here ...
grid.setContainerDataSource(new BeanItemContainer<Project>(Project.class, projects.findAll()));
My repository is just
#Repository
public class ProjectDAO implements JPARepository<Project, Long> {
}
And, as I said, this works flawlessly. The problem is when I try to save something: when trying to save a project via a button click, for example
btnSave.addClickListener(e -> saveCurrent());
private void saveCurrent() {
// ... here I do some filesystem operations, nothing that requires DB connection
setModified();
}
public void setModified() {
project.setLastAccess(new Date());
projects.saveAndFlush(project);
}
I get an exception:
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress.
I've tried many different things, such as marking the setModified method as #Transactional, or encapsulating the setModified into a service class, but everything always throws this exception.
I find it rather strange that this doesn't work "out of the box", and I'd rather not work with transactions myself, since there are already the instruments to do that.
Any help would be really appreciated
EDIT 12/05/2015
It seems that this problem only appears when using an external server, not the embedded one provided by spring-boot. For test purposes I can manage to use the built-in, but eventually I will have to deploy the application on an existing server, so what could the issue be? Tomcat's configuration?
If anyone needs the answer I'll leave here what I found out after a few days of breaking my head on it.
Before deploying the application I changed some configurations on the main class that was generated by Spring Initializr (The application one) and made it extend SpringBootServletInitializer because I was following the guide I found in the official spring blog. Turns out that this was in fact not necessary because I set up "WAR" in Spring Initializr from the beginning, thus the application already had a class extending that one, and as a result when deploying it on Tomcat, the web application started twice, so the application was configured twice and two persistence units were instantiated. This probably was the error, because after reverting the changes I made to the application everything worked fine.
TL;DR: if you use Spring Initializr to create a WAR application don't touch anything.

Load .properties file without restarting WebLogic server - ADF Application

Environment : ADF application running on WebLogic Server 11gR1 - JDeveloper 11.1.1.7
Can I update and load .properties file on application run-time without restarting my weblogic server? If so please suggest how I can proceed with this requirement.
I haven't tried this, but still here it goes:
Create a method in some backing bean, callable only from an administration page. This method would look like:
public void clearResourceBundleCache() {
ClassLoader cl = this.getClass().getClassLoader();
ResourceBundle.clearCache(cl);
}
Or even simpler:
public void clearResourceBundleCache() {
ResourceBundle.clearCache();
}
(See relevant docs)
To use this you would have to (1) replace the .properties files you want to change in the file system of the server and (2) call this method.
More sofisticated solutions would involve the ResourceBundle.Control (docs).

Pure java app port to glassfish

I have an application written in pure/basic Java without GUI. I have three classes with main methods, so each of them can run for themselves. Now I run them with ant in specific order.
In glassfish I deployed Web application only with RESTful service.
What I want to do now is to transfer the three classes into glassfish, so I will call them in exact same order as before from RESTful service.
I watched series of videos on youtube on Java EE 6 APIs, but I didn't find anything that would help transfer pure Java application to glassfish. Should I use EJB API for this?
There is nothing special to do. Just package the three classes into the .war file with your web service. When the web service method is called, create an instance of each class and call the appropriate method.
Of course you could also create EJBs for each class and inject an instance of each class into the web service class.
I would image that in the simplest form you can create servlet for each class that you normally call on the command line. Then, indeed you can pack them into a war file and deploy into glassfish. You do not have to use glassfish, by the way. You can use tomcat, jetty or any other servlet containers.
I assume you want the applications to run without user interaction like a human being clicking on a page. Create a singleton ejb which will be created as soon as the application is uploaded to the webserver, in the singleton create instances of your classes and call a method which should replicate the behaviour of the main method in each class.
`#Startup
#Singleton
public class StartupBean {
private MyClass obj;
private MyClass2 obj2;
#PostConstruct
initializeMyClasses(){
obj = new MyClass();
obj.start();//the start method contains code copy pasted from main
obj2 = new MyClass2();
obj2.start();`

Categories

Resources