jsp - Use my own classes in a servlet (Java/Tomcat/Linux) -


for last 3 days couldn't find single answer problem. need able use own classes in servlets.

i pretty sure files hierarchy correct:

|-web-inf/ |---classes/ |------com/ |---------myproject/ |------------user/ |---------------user.java |---------------location.java |---------------comment.java |------------servlet/ |---------------docomment.java 

since user.java, location.java , comment.java defined in 1 package com.myproject.user know should go main root of java project , compile them way:

/var/lib/tomcat6/webapps/root/web-inf/classes$ sudo javac com/myproject/user/location.java /var/lib/tomcat6/webapps/root/web-inf/classes$ sudo javac com/myproject/user/user.java /var/lib/tomcat6/webapps/root/web-inf/classes$ sudo javac com/myproject/user/comment.java 

however, javac cannot identify other objects (cannot find symbol error) when use classpath in compilation.

/var/lib/tomcat6/webapps/root/web-inf/classes$ sudo javac -cp /usr/share/tomcat6/lib/servlet-api.jar com/myproject/servlet/docomment.java 

please help!

you're putting java source in location compiled java classes expected. try compiling source , adding class files (.class vs .java) you're putting them currently.

for work, you'd have sure classes have no dependencies , package declaration of classes match folder hierarchy you're placing them under.

even so, isn't how web projects put together. better off packaging classes jar , placing jar in web-inf/lib folder.

for more information on creating jar, check out: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -