Does anyone know if Tomcat running inside of Eclipse truly uses the <tomcat>\bin\ directory when you've configured your server to use your local Tomcat install (Server view) inside Eclipse?
For example: I'm using a colleagues jar, which subsequently requires the X.properties file. I've been instructed to place that properties file in the <tomcat>\bin\ directory. This is sort of odd to me, but the line that fails is simply:
InputStream in = new FileInputStream("X.properties");
Anyhow, I'm pretty sure editing any of the Server config files will not help me, though I'm open to any suggestions. Or perhaps there's something in my launch configuration (below) that I can change?
No matter what, I get the following stack trace:
java.io.FileNotFoundException: X.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.mycompany.myteam.colleaguesproject.colleaguesservlet.init(colleaguesservlet.java:93)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3956)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4230)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Any help is greatly appreciated! :-)
Java designates the directory that you started it from as its 'working directory', and any relative paths are relative to that directory. In this case, that's Tomcat's bin directory, which contains Tomcat's startup script.
You should put the properties file in C:\apache-tomcat-5.5.25\bin to make this work, though this is not a good practice for java properties files. Reading them in off of Java's classpath is standard, and much more flexible.
I totally agree with mblinn !
Eclipse creates a local instance of tomcat server, for which eclipse.exe is the Main application.
Try placing your X.properties file in eclipse root folder.
Related
I am using IntelliJ to create a variant of the Java WorldWind application. When I build the JAR artifact in IntelliJ I can see my DLLs and SOs in the top-level directory of the JAR. However, when I try to execute it, it complains it can't see these libraries that are inside the JAR (tried both Windows and Linux, thus being why I include SOs and DLLs).
What do I need to do to get it to see these libraries?
This is my first time creating an executable JAR, so sorry for the vagueness, I'm not quite sure what information is important. Please ask me any questions necessary to better understand this problem, and I will answer them.
Edit:
Catched FileNotFoundException: D:\code\Animator\animator\out\artifacts\Animator_jar\Animator-natives-windows-i586.jar (The system cannot find the file specified),
while addNativeJarLibsImpl(
classFromJavaJar class com.jogamp.common.os.Platform,
classJarURI jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar!/com/jogamp/common/os/Platform.class,
nativeJarBaseName Animator-natives-windows-i586.jar):
[ file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar ->
file:/D:/code/Animator/animator/out/artifacts/Animator_jar/ ] +
Animator-natives-windows-i586.jar ->
slim: jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator-natives-windows-i586.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: D:\code\Animator\animator\out\artifacts\Animator_jar\gluegen-rt.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:551)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:96)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:414)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:388)
at com.jogamp.common.os.Platform$1.run(Platform.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:179)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at au.gov.ga.worldwind.animator.application.AnimatorConfiguration.<clinit>(AnimatorConfiguration.java:46)
at au.gov.ga.worldwind.animator.application.Animator.<clinit>(Animator.java:205)
As far as the structure of the JAR, I don't know how to show other than a screenshot of the JAR in 7-Zip:
In the image we can see that the name of the jar is: Animator.jar, but intelliJ is searching for: Animator-natives-windows-i586.jar. You must go to Module Settings - Artifacts and change the OutputDirectory to: D:\code\Animator\animator\out\artifacts\Animator_jar
Then check the name of the artifact to match the path and the name of the file.
The image added by me is an example.
I am debugging a Java application that runs Groovy program for a certain database transaction call. When the pointer passes the following line of the Groovy program
sql.eachRow("select.....from...where...",[value0, value1])
It prints the following exception
- Servlet.service() for servlet Groovy threw exception
java.lang.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:392)
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:258)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:795)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at groovy.sql.Sql$36.run(Sql.java:1192)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.sql.Sql.createConnection(Sql.java:1190)
at groovy.sql.Sql.eachRow(Sql.java:466)
at gjdk.groovy.sql.Sql_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
sce_expiry.groovy is the groovy file name.
The solutions other people got recommended are like making sure the common-collections.jar and groovy-all.jar are in the classpath. I have verified. Both jar files are located in the lib folder of the webapp's directory inside my Tomcat. And the class can be found inside common-collections.jar with the same package name.
I actually have almost 0 experience with Groovy. So I'm really not sure whether some additional configuration is needed.
Does anyone have any idea?
--------------------------Solution found and question might change--------------
Alright, so I found out two ways to make this work. And they are related.
First of all, I am using Tomcat 5 here. In the Tomcat folder, there is a common/lib directory for users to place jar files shared by applications.
There are already some Apache commons-xxx.jar files in place but not commons-collection.jar. If I put a copy of commons-collection.jar together with the existing jar file, it will work! Alternatively, remove one jar file (commons-dbcp.jar), it will work as well. Both commons-collection.jar and commons-dbcp.jar are available in the application's own lib folder.
Yet, I need to do more research on this, but I suspect that commons-dbcp.jar need to work together with commons-collection.jar for the function I call, and that common/lib folder takes a higher priority to be read in. Therefore, once commons-dbcp.jar is read in, Tomcat will ingore the same in the app's lib folder and will only work with the one in the common lib folder. While commons-collection was not available in the common lib folder, it complained when commons-dbcp.jar was looking for it.
Please correct me if I'm wrong. I don't know perfectly how Tomcat works..
So this question is no longer tagged with Groovy and Grails, but Java and Tomcat 5.
I'm fairly new to Java and I'm having trouble exporting my application into a runnable jar.
My application runs some transformations using Saxon and I want the stylesheets used to be inside the runnable jar.
Right now I simply have a subfolder in my project in eclipse and I'm accessing the stylesheets with that path.
However as soon as I export the project as runnable jar inside that jar all the stylesheets are on the same level as the used libraries (subfolder is nowhere to be found.)
Also the application searches for that subfolder in the cwd and of course can't find it there.
How do I pack the stylesheets and access them properly inside the jar ?
//Update:
I think I'm a little further.
I've created a subfolder under src and put all stylesheets in there. I'm accessing them like so:
xsltexps = comp.compile(new StreamSource(new File(this.getClass().getResource("/stylesheets/" + stylesheets).toURI())));
If i run it in eclipse everything works fine. When I export it as runnable jar and run it i get the following exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.(Unknown Source)
I have no idea what that even means.
Okay, so here's what actually worked:
xsltexps = comp.compile(new StreamSource(
getClass().getResourceAsStream("/stylesheets/" + stylesheets)));
Most importang change is the use of getResourceAsStream instead of getResource
I have project called test in Eclipse which I want to export into Runnable JAR file. During the process of exporting the project, when I choose as a location of JAR file the subfolder of test folder in file system, such as C:/.../test/App.jar, it will work. However, when I want to put it for example on my desktop, it will run but in a very limited look (some GUI components missing) and it throws a lot of exceptions saying something like that:
at java.awt.EventDispatchThread.run(Unknown Source) xception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class com.sun.opengl.impl.windows.WindowsGLDrawableFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java}
What can be the problem? I assume it is not good that I have to specify my JAR file concretely into one folder in file system, it would become unuseful for any other potentional user.
Looks like the jar needs other jars to execute. In this case you would have to set the classpath before you execute the jar
This might help you with your problem.
Hai
I have an application which is designed in netbeans6.0.1 where i need to display an image as an logo.My coding is as below
mLogo = new JLabel();
URL lUrlLogo = getclass().getResource("/com/images/image.gif");
Image lLogoimage = Toolkit.getDefaultToolkit().getImage(lUrlLogo);
ImageIcon licon = new ImageIcon(lLogoimage);
mLogo.setIcon(licon);
My code works fine when i execute it in netbeans but when I try to run my jar file which is created by netbeans in dist folder,it gives me an exception
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(Unknown Source)
at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
Whats the problem with my jar
Can some one help me to run my jar
Thanking u
Your jar file will need to include the image.
See this tutorial or this one for instructions for how to do that. Basically if you include the file in a source folder (with the appropriate path) it should be okay.
If you think you've already got the image there, run
jar tvf file.jar
to show the contents. Make sure everything's where you expect it to be in terms of directories.
EDIT: As per the comments, the problem turned out to be due to case sensitivity.
Finding resources in a jar file is always case-sensitive, whereas loading them from a file system is only case-sensitive if the file system is. So if your file is image.GIF but you're looking for image.gif then it'll work when you're loading from the file system in Windows, but not in the jar file.
And you have checked that the JAR file contains the path "/com/images/image.gif"?
Also, I'm not really sure about the leading slash, I always used relative paths to access resources (but I guess it should work anyways).
As an example from class it.lapo.example.Main I use getClass().getResource("resources/logo.png") and in the JAR files are this way:
it/lapo/example/Main.class
it/lapo/example/resources/logo.png
I know... not much different from your own example, but it does work... so I guess yours is quite close to being correct too.