As a intern, I'm currently developping a java webapp for the first time. I access a Oracle database with Hibernate framework, and use javascript and Jquery on client side.
Everything works smoothly as long as I stay in Eclipse. However, in order to deploy my application, I need to be able to launch it outside Eclipse.
Here's what I did until now : Right-clic on my projet -> Export -> Java/Runnable JAR File (with "Copy required librairies into a sub-folder net to the generated JAR", or it won't works)
I got a jar file (and a folder with a lot of jar libraries), and it runs lovely when executing it with java -jar -myJar.jar with Windows command prompt.
If I try to load a web page from my browser, the server answers (important to notice !) with a 404 error : it can't find the html page.
I can't figure out where I shoul put my webapp folder, which contains every html, css and js file.
Can you help me ? Thank you very much ;)
Related
I want to run a fat client delivered as a Java web start application without Java web start. I launched it via javaws and managed to get all the jar files mentioned in the JNLP file from the cache after they were downloaded.
I tried running the jar file that contains the main class according to the JNLP file, but I get the 'Could not find or load main class' error. Were I just trying to run a class I'd set the classpath accordingly, but since I'm running a jar file with java -jar, as far as I know the classpath settings will be ignored anyway. Now I'm not sure what to do, does anybody know how to tackle this?
I'll answer this myself now, turns out it is stupidly simple: Get all the jar files, unzip them to get the content, merge all the content (best done with rsync), create a new MANIFEST.MF file that contains the main class to be loaded and the merged hashes for all existing files from all MANIFEST.MF files, zip again to create a jar. That's it.
This may sounds like a dumb question to some, but I am not a Java developer, we have moved a Java app from Rackspace server to AWS linux server and upgraded MySql from 5.2.x to 5.7.x. Some SQL statements are causing issues so I am trying to fix those inside the .java files. However, when I save the file, and use .sftp library from VSCode to push the changes to the linux server, then refresh the site, it does not reflect the changes. Is there anything else I need to be doing every time I make a change?
I was able to update some string in a .jsp file and that worked when I refreshed, so I am not sure why when I change a .java file, it does not reflect change.
The entire directory is confusing to me, I believe it was done so that all files, configs, tomcat files, etc. would be under one git folder so that it can just be dropped anywhere. I find a lot of sources state that a .war file would be created and you would place that file in the tomcat apps directory.
Here is the basic layout of the directory of the app
-www/live/njun
-build.xml
+lib
+scripts
+sql
+src
-tomcat(has some config files, scripts, webapps folder)
-web
-content
-index.jsp
-trampoline
-includes folders with .java files
-tickets
-ticketsMgr.java (this is the file I modified but I could not see any differences in app)
-index.jsp (this is one I modified and did reflect in browser)
-WEB-INF
-classes/com/njun
-lots of folder that have .Class files(although when I open them it's all gibberish characters)
This is the basic structure of what I am looking at.
I tried going to the /opt/tomcat/bin and > sh startup.sh - to restart tomcat. That didn't work.
I also ran the > sh startup.sh version inside of the tomcat folder above,
/tomcat/bin/sh startup.sh - that shows me some info where the home, base tmpdir, jre_home, etc. But that didn't work neither.
I am not being asked to make major modifications on this app, I figure I can manage the SQL errors myself. If we get to the point where we need enhancements done to this app, we would hire a Java developer.
Please let me know if I am missing something and I can provide.
Thanks in advance,
That's because a .java file is just source code. You need to compile it and upload the corresponding .class file generated when you compile the .java sources. How to compile and run a Java program. Or well, since it runs on a Tomcat instance, you might have a JAR or WAR file. But the idea is still the same, since those are just basically zip files that hold your .class files (among other stuff that's less relevant for your issue).
I have created a Java application that uses a database, and I now want to build it into a jar file and make it so that the database works without NetBeans. I thought NetBeans would automatically include the database, but it doesn't.
The files that NetBeans include in the 'dist' folder when I build it look like this:
dist
lib
derby.jar (Executable Jar File)
derbyclient.jar (Executable Jar File)
README
WordFinder.jar (Executable Jar File)
Everything except the database-related code works when I launch the WordFinder.jar file after closing NetBeans.
I noticed that the database is using 'org.apache.derby.jdbc.ClientDriver', and I'm wondering, does that need to be 'org.apache.derby.jdbc.EmbeddedDriver' in order for it to include the database?
Are there any files that I need to include? I'm new to Java databases, so try to keep the instructions simple.
You need to start the database server in you computer, for doing that you need to go to your derby path (C:\Program Files\Java\jdk1.8.0_45\db\bin) and run the startNetworkServer.bat file
I may be a year late but seeing the comments, I'm assuming the issue hasn't been resolved yet. I had the same problem and would like to show how I worked around it. Note I'm not using an embedded derby database.
1) I changed my connection string. Instead of the usual "jdbc:derby://localhost:1527/myDB;create=true;...." , I put the exact location of the database which can be found usually under C:\Users\myPC\.netbeans-derby\myDB
2) Clean and build the project which should give you the "dist" folder which would include the jar file of the project together with the "lib" folder.
3) Start the StartNetworkServer.bat which is located in the bin folder under derby folder. A cmd would show that will say something "Apache Derby Network Server blah blah blah started and ready to accept connections on port 1527"
4) After doing those, run the jar file and it should run even with the netbeans IDE closed.
That's about it. That's how I got mine to work without opening Netbeans IDE. Hope it helps.
I have an extremely simple web app for experimenting in java. I have the following java class defined:
UtilDate.java http://www.philbair.org/samples/UtilDate_java.jpg
And a JSP file as follows:
UtilDate.java http://www.philbair.org/samples/getdate_jsp.jpg
The tomcat folders/files look like this (this is not official syntax, just an abstract representation of the folder structure):
UtilDate.java http://www.philbair.org/samples/tree.jpg
mywebapp/WEB-INF/classes/com/udate/UtilDate.class
The jsp file is under the root 'mywebapp' folder (name is inconsequential), and all these are under the webapps folder in tomcat.
After compiling this java class (UtilDate.java), I restart tomcat to make sure it's not hanging on to any old cache stuff.
I get the following...
javax.servlet.ServletException: java.lang.NoClassDefFoundError: UtilDate
when I try to put the jsp page in the browser.
If I replace the uDate() method in the print statement of the jsp file with
out.print("hello");
I get the word hello on the browser output.
This is crude code for testing a simple web app. I am not looking for advice on best practices (although that advice is excellent from what I've seen on this site), I just want to know why this doesn't work. It worked once, and after recompiling the class, it stopped working. I can run the class on my command line and it works just fine (outputs the date as in the main method).
I'm running Windows 7, and tomcat 7.0.34. I'm not using eclipse, or netbeans, etc. at the moment. I'm using a simple text editor, compiling the java class with the command line javac, creating the web folders manually, and placing all the files where they belong myself instead of having maven or ant or anything else build it for me. No war file at the moment. Just working with the files right in the tomcat folders under webapps. I know there are more sophisticated and recommended ways of doing this, but it's only a test for my own understanding with nothing to shield me from what's going on.
Again, this worked once.
Thanks in advance for any help.
you forgot to add the statement package com.udate; at the top of your java class. Add and compile , you should be through
I am doing a project in which one part is openid authentication. I am using Java.
I downloaded the code from the below site:
http://www.ibm.com/developerworks/java/library/j-openid/index.html, it said that he used wicket.
I tried to execute with tomcat server. I am able to compile the java files successfully.
But when I tried to run the openidregistration.html and put www.myopenid.com or (http)://pratap533.myopenid.com, it is not at all responding.
I am in big trouble as I have to complete the project to get my degree.
I included the openid4java.jar, joda-time.jar and wicket.jar file and the C:\Downloads\FileServe Manager\openid4java-sample-app\src all these files in classpath.
So I compiled them and was successful.
I created the wicket folder in webapps and in which I put web-inf. In web-inf I created classes folder and also copied the web.xml in web-inf folder.
In the classes I put all the 4 classes of wicket folder.
When I tried to run the openidregistration.html and put www.myopenid.com or (http)://pratap533.myopenid.com
it was not at all responding..
in web.xml file it is with servlet tags. those tags i did not include them.
Please any body help me..
I think I need to use eclipse, but I am not getting what is the problem.
I tried the following steps with the sample code you have mentioned and its working fine for me except i was getting connection failure error which might be due to the proxy network.
here are the steps for you
Create a dynamic web-application in eclipse IDE.
copy the jars from sample to the jar lib folder in your new project (created in step1).
replace the web.xml from the one from sample application.
copy the SRC folder from the sample application to the one created by you.
If you want to see what is happening inside the application copy the log4j.properties file from sample application to the src folder.
Follow the above 4 steps and you will get a running application what they have in there tutorial.
hope this will work for you.