简体   繁体   中英

importing an eclipse project from file system, then running on server

I am trying to do the spring security tutorial at this link .

In the section entitled "Running the Tutorial application without Spring Security" , I took the following steps (adjusted for differences between the current version and the version that was in use when the tutorial was written):

1.) I downloaded the latest release of the Spring Security Distribution,   
2.) found and unzipped a war file in the dist directory called spring-security-samples-tutorial-3.1.2.RELEASE.war  
3.) Renamed the resulting folder spring-security-tutorial  
4.) Created a general project in eclipse called spring-security-tutorial  
5.) Imported all of the contents of the unzipped spring-security-samples-tutorial-3.1.2.RELEASE.war  
6.) Right clicked on the project in eclipse and selected configure...convert to maven project  
7.) Then right clicked on the project and clicked run as...  

But there was no "run on server" option. (I had chosen a general project instead of a Dynamic Web Project in hopes of preserving the file structure of the application to be imported)

I then started to repeat the process, but creating a Dynamic Web Project instead of a general project, and eclipse wants me to select the "src folders on build path". The file structure of the web application has 8 .class files in subfolders of WEB-INF, and I am not able to locate any .java files.

What steps can I take in order to download this and run it in eclipse on the server? With the ability to edit the classes?

I have read that I can select a .class file in eclipse and it will open the bytecode in the editor, so I imagine I can convert the class files to java files easily enough. But doing that within a general project triggers the error message that the class is not part of the classpath, so we need to get it in a working web project that can be run on the tomcat server from within eclipse first, I think.

A war file is a Web application ARchive (basically a zip). It is meant to contain a web application's compiled class files and resources (properties files, jsps, css, html, js, etc.). It a package that can be used by an application server (or servlet container) like Tomcat. Except through a Decompiler, you will not have access to the source code from the compiled .class files.

I doubt you can run this on Eclipse's Tomcat instances. Instead go to your Tomcat installation. Mine is at C:\\apache-tomcat-7.0.22 . Rename the war to something simple like security.war and place it inside the webapps folder, ie. C:\\apache-tomcat-7.0.22\\webapps\\security.war . Go to C:\\apache-tomcat-7.0.22\\bin and execute the startup.bat Windows batch file. This script sets up the classpath and launches a Java application containing all the applications in webapps . You can see the startup logs in C:\\apache-tomcat-7.0.22\\logs\\catalina.out (as you would normally in Eclipse console).

You can then go to localhost:8080/security to hit the application. Replace 8080 with whatever port you're configured on. security is the same name as the war file. When Tomcat starts (based on a config parameter) it will extract the war into a package directory under webapps with the same name.

You can play around with configuration settings. Some of the important ones are here .

You can shutdown Tomcat by running the C:\\apache-tomcat-7.0.22\\bin\\shutdown.bat Batch file script. You'll have to do this and restart if you change something in the application (ex. the web.xml or a properties file).

I think the tutorial you linked was meant more for trying security settings than actually changing the source code. I'm sure there are other samples online for Spring security, I just don't know them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM