Run Java with a main in a WebSphere project
Very new to WebSphere as well as packaging Java.
I need to take a Java project that we've been running from the command line as an executable Jar and make it run from WebSphere (since the admin user has been getting auto-logged out at midnight).
I've looked at creating a WAR file, but the ant examples I've looked at invoked a lot of WEB-INF dependencies ... but this project doesn't have that. It has a main entry point in the code.
EARs seem to require EJBs, which I don't think this project uses. Seeing as EJBs have been on their way out for a while I'm not as up to speed on them.
My questions are: What is the simplest way to put my executable JAR into WebSphere?
Bonus points: Do EAR files require EJBs in the project? If so, how do I know if this project invokes them?
websphere war executable-jar ear
|
show 4 more comments
Very new to WebSphere as well as packaging Java.
I need to take a Java project that we've been running from the command line as an executable Jar and make it run from WebSphere (since the admin user has been getting auto-logged out at midnight).
I've looked at creating a WAR file, but the ant examples I've looked at invoked a lot of WEB-INF dependencies ... but this project doesn't have that. It has a main entry point in the code.
EARs seem to require EJBs, which I don't think this project uses. Seeing as EJBs have been on their way out for a while I'm not as up to speed on them.
My questions are: What is the simplest way to put my executable JAR into WebSphere?
Bonus points: Do EAR files require EJBs in the project? If so, how do I know if this project invokes them?
websphere war executable-jar ear
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
1
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09
|
show 4 more comments
Very new to WebSphere as well as packaging Java.
I need to take a Java project that we've been running from the command line as an executable Jar and make it run from WebSphere (since the admin user has been getting auto-logged out at midnight).
I've looked at creating a WAR file, but the ant examples I've looked at invoked a lot of WEB-INF dependencies ... but this project doesn't have that. It has a main entry point in the code.
EARs seem to require EJBs, which I don't think this project uses. Seeing as EJBs have been on their way out for a while I'm not as up to speed on them.
My questions are: What is the simplest way to put my executable JAR into WebSphere?
Bonus points: Do EAR files require EJBs in the project? If so, how do I know if this project invokes them?
websphere war executable-jar ear
Very new to WebSphere as well as packaging Java.
I need to take a Java project that we've been running from the command line as an executable Jar and make it run from WebSphere (since the admin user has been getting auto-logged out at midnight).
I've looked at creating a WAR file, but the ant examples I've looked at invoked a lot of WEB-INF dependencies ... but this project doesn't have that. It has a main entry point in the code.
EARs seem to require EJBs, which I don't think this project uses. Seeing as EJBs have been on their way out for a while I'm not as up to speed on them.
My questions are: What is the simplest way to put my executable JAR into WebSphere?
Bonus points: Do EAR files require EJBs in the project? If so, how do I know if this project invokes them?
websphere war executable-jar ear
websphere war executable-jar ear
asked Nov 1 '18 at 19:50
micahhoover
1,27542442
1,27542442
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
1
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09
|
show 4 more comments
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
1
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
1
1
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09
|
show 4 more comments
1 Answer
1
active
oldest
votes
The simple answer is to create a war
application with a @WebListener:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println(toString() + " contextInitialized started");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " contextInitialized finished");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Replace MainClass.main(args);
with your application call (and add any JAR dependencies into WEB-INF/lib
).
The thing I don't like about the above is that it's not great to perform intense work during startup. This may make problem determination harder and certain capabilities (e.g. runtime diagnostic trace modification) are unavailable during startup.
You could create a WAS-specific solution by using AdminClient to subscribe to the Server MBean's Stateful notifications.
Otherwise, a standardized way would be to have an EJB @Startup bean which uses the TimerService to start work after some delay which is empirically determined to be an average application server startup time. For example:
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
@Singleton
@Startup
public class DeferredInitializer {
public static final int DELAY = Integer.getInteger("DeferredInitializer.DELAY", 60000);
@Resource
TimerService timerService;
@PostConstruct
private void init() throws Throwable {
System.out.println(toString() + " init entry");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createSingleActionTimer(DELAY, timerConfig);
Calendar c = new GregorianCalendar();
c.add(Calendar.MILLISECOND, DELAY);
System.out.println(toString() + " timer estimated to pop in (" + DELAY + "ms) ~@ " + c.getTime());
System.out.println(toString() + " init exit");
}
@Timeout
public void timeout(Timer timer) {
System.out.println(toString() + " timeout entry");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " timeout exit");
}
}
Specify the delay with the generic JVM argument -DDeferredInitializer.DELAY=X
(X in milliseconds).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53108414%2frun-java-with-a-main-in-a-websphere-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The simple answer is to create a war
application with a @WebListener:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println(toString() + " contextInitialized started");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " contextInitialized finished");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Replace MainClass.main(args);
with your application call (and add any JAR dependencies into WEB-INF/lib
).
The thing I don't like about the above is that it's not great to perform intense work during startup. This may make problem determination harder and certain capabilities (e.g. runtime diagnostic trace modification) are unavailable during startup.
You could create a WAS-specific solution by using AdminClient to subscribe to the Server MBean's Stateful notifications.
Otherwise, a standardized way would be to have an EJB @Startup bean which uses the TimerService to start work after some delay which is empirically determined to be an average application server startup time. For example:
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
@Singleton
@Startup
public class DeferredInitializer {
public static final int DELAY = Integer.getInteger("DeferredInitializer.DELAY", 60000);
@Resource
TimerService timerService;
@PostConstruct
private void init() throws Throwable {
System.out.println(toString() + " init entry");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createSingleActionTimer(DELAY, timerConfig);
Calendar c = new GregorianCalendar();
c.add(Calendar.MILLISECOND, DELAY);
System.out.println(toString() + " timer estimated to pop in (" + DELAY + "ms) ~@ " + c.getTime());
System.out.println(toString() + " init exit");
}
@Timeout
public void timeout(Timer timer) {
System.out.println(toString() + " timeout entry");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " timeout exit");
}
}
Specify the delay with the generic JVM argument -DDeferredInitializer.DELAY=X
(X in milliseconds).
add a comment |
The simple answer is to create a war
application with a @WebListener:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println(toString() + " contextInitialized started");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " contextInitialized finished");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Replace MainClass.main(args);
with your application call (and add any JAR dependencies into WEB-INF/lib
).
The thing I don't like about the above is that it's not great to perform intense work during startup. This may make problem determination harder and certain capabilities (e.g. runtime diagnostic trace modification) are unavailable during startup.
You could create a WAS-specific solution by using AdminClient to subscribe to the Server MBean's Stateful notifications.
Otherwise, a standardized way would be to have an EJB @Startup bean which uses the TimerService to start work after some delay which is empirically determined to be an average application server startup time. For example:
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
@Singleton
@Startup
public class DeferredInitializer {
public static final int DELAY = Integer.getInteger("DeferredInitializer.DELAY", 60000);
@Resource
TimerService timerService;
@PostConstruct
private void init() throws Throwable {
System.out.println(toString() + " init entry");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createSingleActionTimer(DELAY, timerConfig);
Calendar c = new GregorianCalendar();
c.add(Calendar.MILLISECOND, DELAY);
System.out.println(toString() + " timer estimated to pop in (" + DELAY + "ms) ~@ " + c.getTime());
System.out.println(toString() + " init exit");
}
@Timeout
public void timeout(Timer timer) {
System.out.println(toString() + " timeout entry");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " timeout exit");
}
}
Specify the delay with the generic JVM argument -DDeferredInitializer.DELAY=X
(X in milliseconds).
add a comment |
The simple answer is to create a war
application with a @WebListener:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println(toString() + " contextInitialized started");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " contextInitialized finished");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Replace MainClass.main(args);
with your application call (and add any JAR dependencies into WEB-INF/lib
).
The thing I don't like about the above is that it's not great to perform intense work during startup. This may make problem determination harder and certain capabilities (e.g. runtime diagnostic trace modification) are unavailable during startup.
You could create a WAS-specific solution by using AdminClient to subscribe to the Server MBean's Stateful notifications.
Otherwise, a standardized way would be to have an EJB @Startup bean which uses the TimerService to start work after some delay which is empirically determined to be an average application server startup time. For example:
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
@Singleton
@Startup
public class DeferredInitializer {
public static final int DELAY = Integer.getInteger("DeferredInitializer.DELAY", 60000);
@Resource
TimerService timerService;
@PostConstruct
private void init() throws Throwable {
System.out.println(toString() + " init entry");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createSingleActionTimer(DELAY, timerConfig);
Calendar c = new GregorianCalendar();
c.add(Calendar.MILLISECOND, DELAY);
System.out.println(toString() + " timer estimated to pop in (" + DELAY + "ms) ~@ " + c.getTime());
System.out.println(toString() + " init exit");
}
@Timeout
public void timeout(Timer timer) {
System.out.println(toString() + " timeout entry");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " timeout exit");
}
}
Specify the delay with the generic JVM argument -DDeferredInitializer.DELAY=X
(X in milliseconds).
The simple answer is to create a war
application with a @WebListener:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println(toString() + " contextInitialized started");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " contextInitialized finished");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Replace MainClass.main(args);
with your application call (and add any JAR dependencies into WEB-INF/lib
).
The thing I don't like about the above is that it's not great to perform intense work during startup. This may make problem determination harder and certain capabilities (e.g. runtime diagnostic trace modification) are unavailable during startup.
You could create a WAS-specific solution by using AdminClient to subscribe to the Server MBean's Stateful notifications.
Otherwise, a standardized way would be to have an EJB @Startup bean which uses the TimerService to start work after some delay which is empirically determined to be an average application server startup time. For example:
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
@Singleton
@Startup
public class DeferredInitializer {
public static final int DELAY = Integer.getInteger("DeferredInitializer.DELAY", 60000);
@Resource
TimerService timerService;
@PostConstruct
private void init() throws Throwable {
System.out.println(toString() + " init entry");
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
timerService.createSingleActionTimer(DELAY, timerConfig);
Calendar c = new GregorianCalendar();
c.add(Calendar.MILLISECOND, DELAY);
System.out.println(toString() + " timer estimated to pop in (" + DELAY + "ms) ~@ " + c.getTime());
System.out.println(toString() + " init exit");
}
@Timeout
public void timeout(Timer timer) {
System.out.println(toString() + " timeout entry");
String args = new String {};
MainClass.main(args);
System.out.println(toString() + " timeout exit");
}
}
Specify the delay with the generic JVM argument -DDeferredInitializer.DELAY=X
(X in milliseconds).
edited Nov 20 '18 at 22:58
answered Nov 20 '18 at 22:52
kgibm
420318
420318
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53108414%2frun-java-with-a-main-in-a-websphere-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you want to run the main method when WebSphere is started, or on some interval, or when someone hits some website?
– kgibm
Nov 2 '18 at 1:32
1
EAR doesnt require EJBs, but require either WAR module or EJB module. You can also deploy plain WAR. Is your application a Spring Boot? What your application does?
– Gas
Nov 2 '18 at 2:36
@kgibm: when WebSphere is started
– micahhoover
Nov 2 '18 at 13:19
@Gas: I can see why you would guess Spring Boot, but there's nothing that modern in our stack here. Basically it monitors a directory that gets files plopped into it from an sftp source. I want it to start watching that directory as soon as it comes up.
– micahhoover
Nov 2 '18 at 13:21
So whats the point of having that in WebSphere if it doesnt have UI nor is accessible remotely? Just add that to corn and it will be automatically started when the system boots up.
– Gas
Nov 2 '18 at 15:09