Webpage can not access jar for applet - maven

I created two maven project: project-applet and project-webapp.
The java applet works fine: I can start it with the applet-viewer in a static html file with the necessary applet-tag.
Now I'm trying to move this static html file into a servlet (actually just it's content) index.jsp
<html>
<body>
<applet
code="project.applet.Applet.class"
codebase="/lib"
archive="project-applet-0.1.0.BUILD-SNAPSHOT.jar" width="900"
height="300"> Your browser is completely ignoring the applet tag! </applet>
</body>
</html>
I'm building everything with maven. The project-applet-0.1.0.BUILD-SNAPSHOT.jar is in the project-webapp-0.1.0.BUILD-SNAPSHOT.war file in this position WEB-INF/lib/.
I also tried to just copy it to project-webapp/src/main/webapp/ with codebase="/" but this didn't help even if the jar can be download from localhost:8080/project-webapp/project-applet-0.1.0.BUILD-SNAPSHOT.jar.
Can someone help me?
Thanks!

If the jar is lying at localhost:8080/project-webapp/project-applet-0.1.0.BUILD-SNAPSHOT.jar, the codebase is like this codebase="/project-webapp/"

Related

How to include a js file kept in static folder in thymeleaf html

I am using Spring Tool Suite to build spring boot application and using thymeleaf as template engine.
The folder structure is as follows:
src/main/resources/static
src/main/resources/templates
The HTML file is kept in src/main/resources/templates
and the javacript file is kept in src/main/resources/static
To include the javascript file in my html I have added the below line:
<script type="text/javascript" th:src="#{../static/js/policyCreations.js}"></script>
but I am getting bellow error in chrome console:
GET http://localhost:8082/static/js/policyCreations.js net::ERR_ABORTED 404
can anyone help me to resolve the issue
According to the official doc:
Spring Boot will automatically add static web resources located within any of the following directories:
/META-INF/resources/
/resources/
/static/
/public/
So all the files located in the static folder can be referenced directly without specifying the static folder name.
Like:
<script type="text/javascript" th:src="#{/js/policyCreations.js}"></script>

How to access a js file outside the public folder?

I was trying to register a vue component in the app.js file from a laravel project but I just can't seem to find the right path for the app.js, there are two files with app.js filenames. Here is my file structure:
public
css
js
app.js
resources
js
components
Articles.vue
ExampleComponent.Vue
app.js
bootstrap.js
Here is where I imported my app.js file to my blade file:
<body>
<div id="app">
<articles>
</articles>
</div>
<script type="text/javascript" src="{{ assets('js/app.js') }}"></script>
</body>
The problem is I want to access the second app.js file which is in the resources folder, but the above code keeps giving me the first app.js file which is in the public folder.
I tried giving it the absolute path to the file using this code URL::asset('resources/js/app.js')
This gives me a url like localhost:8000/resources/js/app.js which is the correct file location but somehow this link leads to a 404 page. So is there any other way to access the file?
Thanks
Firstly
localhost:8000/something always refer to something in the public directory. So, you cannot reference your resource/js/app.js in your blade file as js file.
Secondly
Actually you don't need to use the resource/js/app.js file in your blade. If you even do so, the code won't work. Because the codes in resources/js/app.js are un-compiled. You need to compile them and use them in blade files. So, where is the compiled file? It's actually the public/js/app.js file. This file is the compiled version of your resource/js/app.js.
The problem is every time you change a js file inside resource, you need to re-compile the js codes. All those codes will be merged together and will be copied in public/js/app.js.
How to compile?
Before compiling your js code you need to make sure you have installed your frontend dependencies correctly by running the npm install command.
Then if all dependencies are installed you can compile your code using the command
npm run dev for development level compile
npm run production for production level(minified and secured) compile.
If you don't want to run the npm run dev command every time you change a file, then you can run npm run watch command. This command will watch if any js file changed. If changed it will compile automatically.

MyBatis Generator stops working after i convert the project to Gradle (STS) or Maven

We are looking into using MyBatis Generator to create our base entities classes and create the CRUD operations
We have created the generatorConfig.xml file and run the MyBatis Generator
In our target folder all classes were created as expected
Now we convert the project to use Gradle (Gradle STS) since this is the convention for all our other projects
once we do that and we re-run the MyBatis Generator we get the following error
"Cannot find source folder for project "
What are we doing wrong?
This is the config file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="context1">
<jdbcConnection connectionURL="jdbc:sqlserver://<>.database.windows.net:1433;database=dbName;user=dbUser;password=password" driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver" password="...." userId="...." />
<javaModelGenerator targetPackage="javaModelGenerator" targetProject="myBatisArt\src" />
<sqlMapGenerator targetPackage="sqlMapGenerator" targetProject="myBatisArt\src" />
<javaClientGenerator targetPackage="javaClientGenerator" targetProject="myBatisArt\src" type="XMLMAPPER" />
<table catalog="myDB" tableName="Companies">
</table>
</context>
</generatorConfiguration>
I created the Java project "myBatisArt"
On first run , all files were created OK.
Then when hitting "Configure-->Convert to Gradle (STS) Project
(see image)
and running the generation process again i get the error
"Cannot find source folder for project"
Tried to alter the targetProject property to myBatisArt\src\main\java as suggested. but this did not help.
On the other hand the src folder was not defined as a "src" folder in eclipse.
When i went to Properties=>Java Build Path=>Source and added "src" folder it solved the problem
Now i can run "MyBatis Generator" and i get no error.
But, on the third hand, when i refresh the STS project , the src folder is no longer defined as a "src" folder again and i have to re-define it.
I guess that , as Lance said, since STS is legacy I have these problems.

bowerInstall task alternative for Java?

I'm working on a SpringMVC project and currently I'm organising the project structure for the "client" module. I'm using the webjars and wro4j projects with are great, to organise my JavaScript dependencies and concatenate and minimise my CSS/JS code.
What I miss is something exists in the "JavaScript" world that allows to use some HTML code depending on your environment. I'm talking about something like bowerInstall task.
What I would like is to have in my JSP code:
* the includes to my JS files one by one, when working in "development" profile
* a single file, as concatenation and minification, when working in "production" profile.
Next lines are from a HTML file in a Yeoman based project:
...
<!-- build:css styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="../bower_components/highlightjs/styles/monokai.css" />
<link rel="stylesheet" href="../bower_components/seiyria-bootstrap-slider/dist/css/bootstrap-slider.css" />
<!-- endbower -->
<!-- endbuild -->
...
When the grunt task runner is executed, if I'm working in dev mode it does not much but if we are in "prod" mode all the previous CSS are substituted by a line like:
<link rel="stylesheet" href="styles/vendor.css" />
Is this possible in Java??
Is this possible in Java?? No.
However, you may try a couple of options.
Google Pagespeed - Check filter-css-combine documentation. Quick and dirty option, if you have an old project running on production.
Grunt task - Search for grunt-concat-css.
If you are using Bower and Yeoman, you would most probably know Grunt. Just hook on the grunt task to maven ( Search allegro/grunt-maven-plugin) or Gradle (Search com.moowork.grunt) before your WAR task.
this is not a comprehensive answer. Just pointers in the right direction.

How to add JS/CSS files to Joomla modules?

I am starting out with Joomla and am writing a simple Joomla module. I am using some custom CSS and JS in my module. Now when I distribute this module I need my JS/CSS files to go with the ZIP. I have added my files in my module ZIP file.
This is what i need to know -
How do I refer to these CSS/JS files in my module so that even if I distribute the module as a zip i would not have to send the css/js files separately?
I tried looking at different solutions including
http://www.howtojoomla.net/how-tos/development/how-to-add-cssjavascript-to-your-joomla-extension But I was not able to figure out what the URL for the JS/CSS file should be?
I am using Joomla 1.7 hosted on a cloud hosting site.
Thanks
I'd say that the HowToJoomla Site's article pretty much sums up the process.
Here is the process with a few more steps added - hopefully this will help.
I am assuming you have got as far as packaging your extension and have been able to get your css and javascript files to install on the server. They may be in your module folder, or probably more correctly they should be within your modules sub-folder under the /media/ folder.
If after installing the module you can not locate your css and js files it is because you haven't referenced them correctly within your component's xml installation file. This page contains info about the xml installation / manifest file for 1.6/1.7 add-ons although it is for a component: http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!1.6_-_Part_01 they are very similar.
Either way - find your files within Joomla's folder structure and make a note of their relative path from the root of the website - ie the folder containing configuration.php
Now somewhere within your module's php - add the line that gets a reference to the JDocument object.
$document = JFactory::getDocument();
Now add the line that adds your javascript to the html head area:
$document->addScript('url/to/my/script.js');
obviously replace 'url/to/my/script.js' with the actual relative path to your javascript.
Now add the line that adds your css to the html head:
$document->addStyleSheet('url/to/my/stylesheet.css');
again adjust the path - it may for example be media/mod_mymodule/mymodule.css (if your module were called 'mymodule').
Only things to be aware of are that you need to add these lineswithin executable php tags NOT within a html area after exiting php mode.
You could add your js/css files to /media folder.
http://docs.joomla.org/Manifest_files#Media_files
Just add to your manifest file:
<files>
...
</files>
<media folder="media" destination="mod_your_module">
<folder>css</folder>
<folder>js</folder>
</media>
Inside your installable package, you should now have the /media folder.
Then add to view file:
$doc =& JFactory::getDocument();
$doc->addScript("/media/mod_your_module/js/script.js");
This article explains the benefits of this approach:
http://blog.joomlatools.com/2008/09/hidden-feature-joomlas-media-folder.html
You could use:
JHTML::script('modules/mod_your_module/js/script.js');
JHTML::stylesheet('modules/mod_your_module/css/stylesheet.css');
This example does not require JFactory::getDocument()
$document = JFactory::getDocument();
$modulePath = JURI::base() . 'modules/mod_your_module_name/';
//Adding JS Files
$document->addScript($modulePath.'js/myscript.js');
//Adding CSS Files
$document->addStyleSheet($modulePath.'css/style.css');
<script type="text/javascript" src="<?php echo JURI::BASE()?>modules/your_module_name/js/your_js_file"></script>
for Css:
<link href="<?php echo JURI::BASE()?>modules/your_module_name/css/your_css _file" type="text/css" media="all" rel="stylesheet">

Resources