when project deploys on jboss, i want to run some main() method separately with jboss - jboss

My question is the same as like below.
(Jboss version 5.0, in case it matters.)
I have a library in one of my web applications that needs to be configured with a machine-specific license before use. I don't want to put this library in shared/lib because at some point I may want to run multiple web applications with different versions of the library.
Right now the .jar files are stored in WEB-INF/lib. Thus, when I build the .war file and upload it to the server, the .jar file would still be the one bound to my PC. I would like to put a bash script somewhere in the webapp that Tomcat would automatically run when deploying the .war file - this script would then run the configuration script and bind the server's license file to the .jar. Is this possible? Is there a nicer way of doing what I want?
one thing is different. my jar should run with other process Id. that means it has to run as standalone separated by jboss. Even if this
String command = "cmd /C java -jar C:\\test\\WEB-INF\\lib\\teststart.jar";
oProcess = new ProcessBuilder(command).start();
works, I will be happy. that jar is runnable jar.
Do you have Any idea? Thanks..

What about something like ServletContextListener?
Create a class that implements this and in the contextInitialized method (contextInitialized will run during war deployment) create a ProcessBuilder to run your bash command.

Related

Is there a way to ensure that the correct JAR file is called by the Install4J service wrapper?

We are using Install4J v9 and our application needs to run as a Windows service. When we have installed the application as a Windows service, we have the original jar file myApp.jar and the service wrapper myApp.exe (which is running our jar file as a service) in the installation directory.
How can we ensure that our jar myApp.jar file is called by the service wrapper myApp.exe and not a substituted, fraudulent jar file?
I am wondering if jar signing would work, but how could install4j validate this signature?
install4j has no functionality to validate signatures of JAR files for inclusion in the classpath.
However, if an attacker can modify your JAR file, they can also modify your .exe file, so adding protection to the .exe against modification of the JAR file would not make anything safer.

Best method to export the Eclipse project as exe file

I have a selenium project in eclipse that i want to distribute to manual testers with no Eclipse or Java knowledge. Hence i am looking to distribute it to them as executable files so that they dont need to use eclipse to run them. Can any one suggest the best way to do this without having to install any 3rd party extensions?
P.S : My organisation doesnt allow me to install 3rd party extensions on Eclipse. It will require a lot of approvals. Hence i am wondering if there is any method available inside Eclipse itself?
I've done it some years ago, in my eclipse version:
file -> export -> java -> Runnable jar file
If you want an exe file you can use: Launch4J
Export your project as jar file and create a .bat file which will include all the necessary libraries in your classpath with your project and then make a call to the underlying script (in case if you are using testng then testng has option to make command line calls)
else use Maven
EDIT:
Something on below lines:
1. Create run.bat file
2. Content of the bat file:
JAVA_HOME={Path to your JDK}
CLASSPATH=%PATH%;{All the dependent jar files of your project as well as you project}
{Call to your Junit Script from command line} Something like this Run JUnit from command line
3. Run your batch file (run.bat)
I may not have provided the exact code but thats where you should be heading if you wish to run your JUnit tests from command line.
NOTE / FYI : Maven does not require any installation or approval..You just download the zip and unzip it and set environment variable and thats it.

WAS related files getting packaged in ear

I have got an ear file to deploy on WAS. In the ear file, I see the war file, the jar files and other static stuff. But I also see files like variales.xml,security.xml and deployment.xml although the ant build script did not generate these files.
Where did these extra files come from? What purpose do they serve?
These files are part of a feature known as Enhanced EARs. See the WebSphere Application Server V7: Packaging Applications for Deployment redbook for more information. In short, application-specific configuration can be included in the application to minimize the per-server configuration that an administrator must perform when installing an application.

How to run .ear file in JBoss 6?

I have created myProj.ear file and copied it into the deploy folder of the JBoss server.. How to run my project after starting the jBoss server?
I have been using war file and
deploying it in Tomcat till now to run
my project.... I am having a new
requirement to run the project in
JBoss. So, I converted my war file
into an ear file using the command Jar
-cvf myProj.ear ., Should I change anything in my project to run
the application in JBoss or just
copying my .ear file in to the jBoss
deploy folder is enough?
JBoss normally support hot deployment - meaning that if your application was deployed correctly (watch the console), it can be accessed via the browser (if you have a UI) or via web services, managed beans or any other interface you have provided.You can see the status of your application on the JBoss Admin Console. You can reach it by typing the URL of your JBoss installation. If you run your vanilla JBoss locally, you should be able to find the console under http://127.0.0.1:8080/admin-console
To reiterate: there is no explicit startup necessary, JBoss handles it for you.
Deploying an application in JBoss is pretty straightforward. You just have to copy the EAR file to the deploy directory in the 'server configuration' directory of your choice. Most people deploy it to the 'default' configuration, by copying the EAR file to the JBOSS_DIR/jboss-as/server/default/deploy directory.
Once copied, just run run.sh from bin, you can use the following params to bind it to an ip (-b) or binding it to anything other port (-Djboss.service.binding.set)
./run.sh -b 9.xxx.xxx.xxx -Djboss.service.binding.set=ports-01
Once you run it, Look at the console for error message. If everything goes fine you'd see "Started J2EE application" after couple of seconds.
If there are any errors or exceptions, make a note of the error message. Check that the EAR is complete and inspect the WAR file and the EJB jar files to make sure they contain all the necessary components (classes, descriptors,
jboss-deployment-structure.xml etc.).
You can safely redeploy the application if it is already deployed. To undeploy it you just have to remove the archive from the deploy directory. There’s no need to restart the server in either case. If everything seems to have gone OK, then point your browser at the application URL.
http://localhost:8080/xyz

Launch an Eclipse Run Configuration from ANT

I am using Orion server for my Java-based web application. I have a run configuration that launches Orion with the correct classpaths and all necessary configuration. I also have several ANT scripts for copying files to the build path. I want to create an ANT script that shuts down Orion, copies necessary files, and restarts Orion. I can shutdown and copy in ANT, but I can't figure out how to launch a run configuration. I prefer to reference the launch configuration as opposed to specifying all of the configurations in the ANT script as well. Is this possible?
With eclipse remote control you can launch eclipse run configurations in eclipse from a simple java client application.
Ant4Eclipse is an Eclipse plugin and looks like it can do what you are asking. I have never used it myself so can't guarantee but reading their documentation they say you can create an Executor task that works on your launch configuration artifact. You will then reference this task in your build file.